Пример #1
0
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
}
Пример #2
0
func constructClosure(fn *function) (err error) {
	var closure C.ffi_closure
	var fptr unsafe.Pointer
	var mptr unsafe.Pointer

	if mptr, err = C.ffi_closure_alloc(C.size_t(unsafe.Sizeof(closure)), &fptr); mptr == nil {
		return
	}

	if status := Status(C.ffi_prep_closure_loc((*C.ffi_closure)(mptr), &fn.Interface.ffi_cif, C.closure(C.GoClosureCallback), unsafe.Pointer(fn), fptr)); status != OK {
		C.ffi_closure_free(mptr)
		err = status
		return
	}

	fn.fptr = fptr
	fn.mptr = mptr
	return nil
}