def _do_call(self, funcsym, ll_args, RESULT): # XXX: check len(args)? ll_result = lltype.nullptr(rffi.VOIDP.TO) if self.restype != types.void: size = adjust_return_size(intmask(self.restype.c_size)) ll_result = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw') ffires = c_ffi_call(self.ll_cif, self.funcsym, rffi.cast(rffi.VOIDP, ll_result), rffi.cast(rffi.VOIDPP, ll_args)) if RESULT is not lltype.Void: TP = lltype.Ptr(rffi.CArray(RESULT)) if types.is_struct(self.restype): assert RESULT == rffi.SIGNED # for structs, we directly return the buffer and transfer the # ownership buf = rffi.cast(TP, ll_result) res = rffi.cast(RESULT, buf) else: if _BIG_ENDIAN and types.getkind(self.restype) in ('i','u'): ptr = ll_result n = rffi.sizeof(lltype.Signed) - self.restype.c_size ptr = rffi.ptradd(ptr, n) res = rffi.cast(TP, ptr)[0] else: res = rffi.cast(TP, ll_result)[0] else: res = None self._free_buffers(ll_result, ll_args) clibffi.check_fficall_result(ffires, self.flags) return res
def __init__(self, space, shape, length, address=r_uint(0)): memsize = shape.size * length # For W_ArrayInstances that are used as the result value of a # function call, ffi_call() writes 8 bytes into it even if the # function's result type asks for less. memsize = clibffi.adjust_return_size(memsize) W_DataInstance.__init__(self, space, memsize, address) self.length = length self.shape = shape
def _do_call(self, funcsym, ll_args, RESULT): # XXX: check len(args)? ll_result = lltype.nullptr(rffi.CCHARP.TO) if self.restype != types.void: size = adjust_return_size(intmask(self.restype.c_size)) ll_result = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw') ffires = c_ffi_call(self.ll_cif, self.funcsym, rffi.cast(rffi.VOIDP, ll_result), rffi.cast(rffi.VOIDPP, ll_args)) if RESULT is not lltype.Void: TP = lltype.Ptr(rffi.CArray(RESULT)) buf = rffi.cast(TP, ll_result) if types.is_struct(self.restype): assert RESULT == rffi.SIGNED # for structs, we directly return the buffer and transfer the # ownership res = rffi.cast(RESULT, buf) else: res = buf[0] else: res = None self._free_buffers(ll_result, ll_args) clibffi.check_fficall_result(ffires, self.flags) return res
def _do_call(self, funcsym, ll_args, RESULT): # XXX: check len(args)? ll_result = lltype.nullptr(rffi.CCHARP.TO) if self.restype != types.void: size = adjust_return_size(intmask(self.restype.c_size)) ll_result = lltype.malloc(rffi.CCHARP.TO, size, flavor="raw") ffires = c_ffi_call( self.ll_cif, self.funcsym, rffi.cast(rffi.VOIDP, ll_result), rffi.cast(rffi.VOIDPP, ll_args) ) if RESULT is not lltype.Void: TP = lltype.Ptr(rffi.CArray(RESULT)) buf = rffi.cast(TP, ll_result) if types.is_struct(self.restype): assert RESULT == rffi.SIGNED # for structs, we directly return the buffer and transfer the # ownership res = rffi.cast(RESULT, buf) else: res = buf[0] else: res = None self._free_buffers(ll_result, ll_args) clibffi.check_fficall_result(ffires, self.flags) return res