[pypy-svn] r78172 - in pypy/trunk/pypy/rlib: . test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Oct 21 14:26:50 CEST 2010
Author: antocuni
Date: Thu Oct 21 14:26:48 2010
New Revision: 78172
Modified:
pypy/trunk/pypy/rlib/libffi.py
pypy/trunk/pypy/rlib/test/test_libffi.py
Log:
make rlib.libffi more robust when calling a function that it's declared to return a smaller unsigned, but then called expecting a ULONG. This fixes test_unsigned_short_args in module/_ffi
Modified: pypy/trunk/pypy/rlib/libffi.py
==============================================================================
--- pypy/trunk/pypy/rlib/libffi.py (original)
+++ pypy/trunk/pypy/rlib/libffi.py Thu Oct 21 14:26:48 2010
@@ -188,6 +188,9 @@
#
if _fits_into_long(RESULT):
res = self._do_call_int(self.funcsym, ll_args)
+ if self.restype.c_size < types.slong.c_size:
+ # mask res to keep only the bits we are interested in
+ res &= ~(-1 << self.restype.c_size*8)
elif RESULT is rffi.DOUBLE:
return self._do_call_float(self.funcsym, ll_args)
elif RESULT is lltype.Void:
Modified: pypy/trunk/pypy/rlib/test/test_libffi.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_libffi.py (original)
+++ pypy/trunk/pypy/rlib/test/test_libffi.py Thu Oct 21 14:26:48 2010
@@ -182,7 +182,9 @@
"""
libfoo = self.get_libfoo()
func = (libfoo, 'sum_xy_us', [types.ushort, types.ushort], types.ushort)
- res = self.call(func, [32000, 8000], rffi.USHORT)
+ # the ULONG in the next line is not a typo: we really want to test
+ # that we get the correct value even if we cast it to a larger type
+ res = self.call(func, [32000, 8000], rffi.ULONG)
assert res == 40000
More information about the Pypy-commit
mailing list