コード例 #1
0
ファイル: test_libffi.py プロジェクト: njues/Sypy
 def test_struct_fields(self):
     longsize = 4 if IS_32_BIT else 8
     POINT = lltype.Struct(
         'POINT',
         ('x', rffi.LONG),
         ('y', rffi.SHORT),
         ('z', rffi.VOIDP),
     )
     y_ofs = longsize
     z_ofs = longsize * 2
     p = lltype.malloc(POINT, flavor='raw')
     p.x = 42
     p.y = rffi.cast(rffi.SHORT, -1)
     p.z = rffi.cast(rffi.VOIDP, 0x1234)
     addr = rffi.cast(rffi.VOIDP, p)
     assert struct_getfield_int(types.slong, addr, 0) == 42
     assert struct_getfield_int(types.sshort, addr, y_ofs) == -1
     assert struct_getfield_int(types.pointer, addr, z_ofs) == 0x1234
     #
     struct_setfield_int(types.slong, addr, 0, 43)
     struct_setfield_int(types.sshort, addr, y_ofs,
                         0x1234FFFE)  # 0x1234 is masked out
     struct_setfield_int(types.pointer, addr, z_ofs, 0x4321)
     assert p.x == 43
     assert p.y == -2
     assert rffi.cast(rffi.LONG, p.z) == 0x4321
     #
     lltype.free(p, flavor='raw')
コード例 #2
0
ファイル: test_libffi.py プロジェクト: Debug-Orz/Sypy
 def test_struct_fields(self):
     longsize = 4 if IS_32_BIT else 8
     POINT = lltype.Struct('POINT',
                           ('x', rffi.LONG),
                           ('y', rffi.SHORT),
                           ('z', rffi.VOIDP),
                           )
     y_ofs = longsize
     z_ofs = longsize*2
     p = lltype.malloc(POINT, flavor='raw')
     p.x = 42
     p.y = rffi.cast(rffi.SHORT, -1)
     p.z = rffi.cast(rffi.VOIDP, 0x1234)
     addr = rffi.cast(rffi.VOIDP, p)
     assert struct_getfield_int(types.slong, addr, 0) == 42
     assert struct_getfield_int(types.sshort, addr, y_ofs) == -1
     assert struct_getfield_int(types.pointer, addr, z_ofs) == 0x1234
     #
     struct_setfield_int(types.slong, addr, 0, 43)
     struct_setfield_int(types.sshort, addr, y_ofs, 0x1234FFFE) # 0x1234 is masked out
     struct_setfield_int(types.pointer, addr, z_ofs, 0x4321)
     assert p.x == 43
     assert p.y == -2
     assert rffi.cast(rffi.LONG, p.z) == 0x4321
     #
     lltype.free(p, flavor='raw')
コード例 #3
0
ファイル: test_fficall.py プロジェクト: nipengadmaster/pypy
 def f(n):
     i = 0
     addr = lltype.malloc(rffi.VOIDP.TO, 10, flavor='raw')
     while i < n:
         myjitdriver.jit_merge_point(n=n, i=i, addr=addr)
         struct_setfield_int(types.slong, addr, 0, 1)
         i += struct_getfield_int(types.slong, addr, 0)
     lltype.free(addr, flavor='raw')
     return i
コード例 #4
0
ファイル: test_fficall.py プロジェクト: Debug-Orz/Sypy
 def f(n):
     i = 0
     addr = lltype.malloc(rffi.VOIDP.TO, 10, flavor='raw')
     while i < n:
         myjitdriver.jit_merge_point(n=n, i=i, addr=addr)
         struct_setfield_int(types.slong, addr, 0, 1)
         i += struct_getfield_int(types.slong, addr, 0)
     lltype.free(addr, flavor='raw')
     return i
コード例 #5
0
ファイル: interp_struct.py プロジェクト: MichaelBlume/pypy
 def get_unichar(self, w_ffitype):
     intval = libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                         self.rawmem, self.offset)
     return rffi.cast(rffi.WCHAR_T, intval)
コード例 #6
0
ファイル: interp_struct.py プロジェクト: MichaelBlume/pypy
 def get_unsigned(self, w_ffitype):
     value = libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                        self.rawmem, self.offset)
     return r_uint(value)
コード例 #7
0
ファイル: interp_struct.py プロジェクト: MichaelBlume/pypy
 def get_signed(self, w_ffitype):
     return libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                       self.rawmem, self.offset)
コード例 #8
0
ファイル: interp_struct.py プロジェクト: nipengadmaster/pypy
 def get_unichar(self, w_ffitype):
     intval = libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                         self.rawmem, self.offset)
     return rffi.cast(rffi.WCHAR_T, intval)
コード例 #9
0
ファイル: interp_struct.py プロジェクト: nipengadmaster/pypy
 def get_unsigned(self, w_ffitype):
     value = libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                        self.rawmem, self.offset)
     return r_uint(value)
コード例 #10
0
ファイル: interp_struct.py プロジェクト: nipengadmaster/pypy
 def get_signed(self, w_ffitype):
     return libffi.struct_getfield_int(w_ffitype.get_ffitype(),
                                       self.rawmem, self.offset)