Example #1
0
func NewCIF(abi ABI, rtype Type, atypes ...Type) (CIF, error) {
	var cif C.ffi_cif
	atypes_ptr := (**C.ffi_type)(unsafe.Pointer(&atypes[0]))
	status := C.ffi_prep_cif(&cif, C.ffi_abi(abi), C.uint(len(atypes)), rtype, atypes_ptr)
	if status == C.FFI_OK {
		return CIF(cif), nil
	}
	return CIF{}, ffi_error(status)
}
Example #2
0
File: ffi.go Project: sbinet/go-ffi
// NewCif creates a new ffi call interface object
func NewCif(abi Abi, rtype Type, args []Type) (*Cif, error) {
	cif := &Cif{}
	c_nargs := C.uint(len(args))
	var c_args **C.ffi_type = nil
	if len(args) > 0 {
		var cargs = make([]*C.ffi_type, len(args))
		for i, _ := range args {
			cargs[i] = args[i].cptr()
		}
		c_args = &cargs[0]
	}
	sc := C.ffi_prep_cif(&cif.c, C.ffi_abi(abi), c_nargs, rtype.cptr(), c_args)
	if sc != C.FFI_OK {
		return nil, fmt.Errorf("error while preparing cif (%s)",
			Status(sc))
	}
	cif.rtype = rtype
	cif.args = args
	return cif, nil
}