示例#1
0
 def __init__(self, space, name):
     self.space = space
     self.w_ffitype = W_FFIType('struct %s' % name, clibffi.FFI_TYPE_NULL,
                                w_structdescr=self)
     self.fields_w = None
     self.name2w_field = {}
     self._ffistruct_owner = None
示例#2
0
    def setup_class(cls):
        BaseAppTestFFI.setup_class.im_func(cls)

        @unwrap_spec(addr=int, typename=str, length=int)
        def read_raw_mem(space, addr, typename, length):
            import ctypes
            addr = ctypes.cast(addr, ctypes.c_void_p)
            c_type = getattr(ctypes, typename)
            array_type = ctypes.POINTER(c_type * length)
            ptr_array = ctypes.cast(addr, array_type)
            array = ptr_array[0]
            lst = [array[i] for i in range(length)]
            return space.wrap(lst)

        if cls.runappdirect:
            cls.w_read_raw_mem = lambda self, *args: read_raw_mem(
                cls.space, *args)
        else:
            cls.w_read_raw_mem = cls.space.wrap(interp2app(read_raw_mem))
        #
        from rpython.rlib import clibffi
        from rpython.rlib.rarithmetic import r_uint
        from rpython.rtyper.lltypesystem import lltype, rffi
        dummy_type = lltype.malloc(clibffi.FFI_TYPE_P.TO, flavor='raw')
        dummy_type.c_size = r_uint(123)
        dummy_type.c_alignment = rffi.cast(rffi.USHORT, 0)
        dummy_type.c_type = rffi.cast(rffi.USHORT, 0)
        cls.w_dummy_type = W_FFIType('dummy', dummy_type)
        cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
示例#3
0
 def descr_get_ffi_type(self, space):
     # XXX: this assumes that you have the _ffi module enabled. In the long
     # term, probably we will move the code for build structures and arrays
     # from _rawffi to _ffi
     from pypy.module._ffi.interp_ffitype import W_FFIType
     return W_FFIType('<unknown>', self.get_basic_ffi_type(), self)