[pypy-commit] pypy ffistruct: make sure that we properly convert a sbyte >= 128 into a negative value when we set it. This requires to change the TYPE_MAP_INT in clibffi.py, which was wrong before (rffi.CHAR is unsigned, not signed)
antocuni
noreply at buildbot.pypy.org
Wed Nov 9 13:51:12 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r49001:aa53c87e4cdf
Date: 2011-11-09 10:00 +0100
http://bitbucket.org/pypy/pypy/changeset/aa53c87e4cdf/
Log: make sure that we properly convert a sbyte >= 128 into a negative
value when we set it. This requires to change the TYPE_MAP_INT in
clibffi.py, which was wrong before (rffi.CHAR is unsigned, not
signed)
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
@@ -130,10 +130,10 @@
]
descr = _StructDescr('foo', fields)
struct = descr.allocate()
- struct.setfield('sbyte', 42)
+ struct.setfield('sbyte', 128)
struct.setfield('sint', 43)
struct.setfield('slong', 44)
- assert struct.getfield('sbyte') == 42
+ assert struct.getfield('sbyte') == -128
assert struct.getfield('sint') == 43
assert struct.getfield('slong') == 44
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -212,7 +212,7 @@
__int_type_map = [
(rffi.UCHAR, ffi_type_uchar),
- (rffi.CHAR, ffi_type_schar),
+ (rffi.SIGNEDCHAR, ffi_type_schar),
(rffi.SHORT, ffi_type_sshort),
(rffi.USHORT, ffi_type_ushort),
(rffi.UINT, ffi_type_uint),
More information about the pypy-commit
mailing list