Ejemplo n.º 1
0
def jit_ffi_call_impl_any(cif_description, func_addr, exchange_buffer):
    """
    This is the function which actually calls libffi. All the rest is just
    infrastructure to convince the JIT to pass a typed result box to
    jit_ffi_save_result
    """
    buffer_array = rffi.cast(rffi.VOIDPP, exchange_buffer)
    for i in range(cif_description.nargs):
        data = rffi.ptradd(exchange_buffer, cif_description.exchange_args[i])
        buffer_array[i] = data
    resultdata = rffi.ptradd(exchange_buffer, cif_description.exchange_result)
    clibffi.c_ffi_call(cif_description.cif, func_addr,
                       rffi.cast(rffi.VOIDP, resultdata), buffer_array)
Ejemplo n.º 2
0
def jit_ffi_call_impl_any(cif_description, func_addr, exchange_buffer):
    """
    This is the function which actually calls libffi. All the rest if just
    infrastructure to convince the JIT to pass a typed result box to
    jit_ffi_save_result
    """
    buffer_array = rffi.cast(rffi.VOIDPP, exchange_buffer)
    for i in range(cif_description.nargs):
        data = rffi.ptradd(exchange_buffer, cif_description.exchange_args[i])
        buffer_array[i] = data
    resultdata = rffi.ptradd(exchange_buffer,
                             cif_description.exchange_result)
    clibffi.c_ffi_call(cif_description.cif, func_addr,
                       rffi.cast(rffi.VOIDP, resultdata),
                       buffer_array)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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