Author: Antonio Cuni <[email protected]>
Branch: ffistruct
Changeset: r49117:4fee7e624e7e
Date: 2011-11-09 22:45 +0100
http://bitbucket.org/pypy/pypy/changeset/4fee7e624e7e/
Log: app level support for pointer fields
diff --git a/pypy/module/_ffi/interp_struct.py
b/pypy/module/_ffi/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_ffi/interp_struct.py
@@ -139,11 +139,11 @@
return space.wrap(r_ulonglong(value))
return space.wrap(value)
#
- if w_ffitype.is_signed() or w_ffitype.is_unsigned():
+ if w_ffitype.is_signed() or w_ffitype.is_unsigned() or
w_ffitype.is_pointer():
value = libffi.struct_getfield_int(w_ffitype.ffitype, self.rawmem,
offset)
- if w_ffitype.is_unsigned():
- return space.wrap(r_uint(value))
- return space.wrap(value)
+ if w_ffitype.is_signed():
+ return space.wrap(value)
+ return space.wrap(r_uint(value))
#
if w_ffitype.is_char():
value = libffi.struct_getfield_int(w_ffitype.ffitype, self.rawmem,
offset)
@@ -171,7 +171,7 @@
libffi.struct_setfield_longlong(w_ffitype.ffitype, self.rawmem,
offset, value)
return
#
- if w_ffitype.is_signed() or w_ffitype.is_unsigned():
+ if w_ffitype.is_signed() or w_ffitype.is_unsigned() or
w_ffitype.is_pointer():
value = space.truncatedint_w(w_value)
libffi.struct_setfield_int(w_ffitype.ffitype, self.rawmem, offset,
value)
return
diff --git a/pypy/module/_ffi/test/test_struct.py
b/pypy/module/_ffi/test/test_struct.py
--- a/pypy/module/_ffi/test/test_struct.py
+++ b/pypy/module/_ffi/test/test_struct.py
@@ -139,6 +139,7 @@
Field('ulong', types.ulong),
Field('char', types.char),
Field('unichar', types.unichar),
+ Field('ptr', types.void_p),
]
descr = _StructDescr('foo', fields)
struct = descr.allocate()
@@ -156,8 +157,9 @@
assert struct.getfield('char') == 'a'
struct.setfield('unichar', u'\u1234')
assert struct.getfield('unichar') == u'\u1234'
-
-
+ struct.setfield('ptr', -1)
+ assert struct.getfield('ptr') == sys.maxint*2 + 1
+
def test_getfield_setfield_longlong(self):
import sys
from _ffi import _StructDescr, Field, types
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit