1
0
mirror of https://github.com/golang/go synced 2024-11-24 02:10:11 -07:00

syscall: improve NewCallback documentation and panic message

This commit is contained in:
Jeet Parekh 2018-07-27 21:21:26 +05:30
parent 51cc964fb7
commit 64ceaea9f1
2 changed files with 5 additions and 5 deletions

View File

@ -42,15 +42,15 @@ func callbackasmAddr(i int) uintptr {
//go:linkname compileCallback syscall.compileCallback
func compileCallback(fn eface, cleanstack bool) (code uintptr) {
if fn._type == nil || (fn._type.kind&kindMask) != kindFunc {
panic("compileCallback: expected a function with signature - func(args) uintptr { ... }")
panic("compileCallback: expected function with one uintptr-sized result")
}
ft := (*functype)(unsafe.Pointer(fn._type))
if len(ft.out()) != 1 {
panic("compileCallback: function must have one result of type uintptr")
panic("compileCallback: expected function with one uintptr-sized result")
}
uintptrSize := unsafe.Sizeof(uintptr(0))
if ft.out()[0].size != uintptrSize {
panic("compileCallback: result is not of type uintptr")
panic("compileCallback: expected function with one uintptr-sized result")
}
argsize := uintptr(0)
for _, t := range ft.in() {

View File

@ -122,14 +122,14 @@ func compileCallback(fn interface{}, cleanstack bool) uintptr
// NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention.
// This is useful when interoperating with Windows code requiring callbacks.
// The argument is expected to be a function with signature - func(args) uintptr { ... }. The size of arguments must not be more than the size of uintptr.
// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr.
func NewCallback(fn interface{}) uintptr {
return compileCallback(fn, true)
}
// NewCallbackCDecl converts a Go function to a function pointer conforming to the cdecl calling convention.
// This is useful when interoperating with Windows code requiring callbacks.
// The argument is expected to be a function with signature - func(args) uintptr { ... }. The size of arguments must not be more than the size of uintptr.
// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr.
func NewCallbackCDecl(fn interface{}) uintptr {
return compileCallback(fn, false)
}