Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 def _do_call(self, funcsym, ll_args, RESULT):
     # XXX: check len(args)?
     ll_result = lltype.nullptr(rffi.CCHARP.TO)
     if self.restype != types.void:
         ll_result = lltype.malloc(rffi.CCHARP.TO,
                                   intmask(self.restype.c_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