func constructClosure(fn *function) (err error) { var ptr unsafe.Pointer var rc C.int if rc, err = C.ffi_closure_alloc__(&ptr); rc != 0 { return } if status := Status(C.ffi_prep_closure((*C.ffi_closure)(ptr), &fn.Interface.ffi_cif, C.closure(C.GoClosureCallback), unsafe.Pointer(fn))); status != OK { C.ffi_closure_free__(ptr) err = status return } if rc, err = C.ffi_closure_make_executable__(ptr); rc != 0 { C.ffi_closure_free__(ptr) return } fn.fptr = ptr fn.mptr = ptr return nil }
func destroyClosure(fn *function) { C.ffi_closure_free__(fn.mptr) }