Permalink
Browse files

fix handling of uint values on 32bit

  • Loading branch information...
antocuni committed May 22, 2012
1 parent d3c095f commit ea009b397c5cae0e484fa9fa49aa50d4b828fdcf
Showing with 45 additions and 1 deletion.
  1. +42 −0 pypy/module/_ffi/test/test_type_converter.py
  2. +3 −1 pypy/module/_ffi/type_converter.py
@@ -126,3 +126,45 @@ def test_strings(self):
# then, try to pass explicit pointers
self.check(app_types.char_p, self.space.wrap(42), 42)
self.check(app_types.unichar_p, self.space.wrap(42), 42)
+
+
+
+class DummyToAppLevelConverter(ToAppLevelConverter):
+
+ def get_all(self, w_ffitype):
+ return self.val
+
+ get_signed = get_all
+ get_unsigned = get_all
+ get_pointer = get_all
+ get_char = get_all
+ get_unichar = get_all
+ get_longlong = get_all
+ get_char_p = get_all
+ get_unichar_p = get_all
+ get_float = get_all
+ get_singlefloat = get_all
+
+ def convert(self, w_ffitype, val):
+ self.val = val
+ return self.do_and_wrap(w_ffitype)
+
+
+class TestFromAppLevel(object):
+
+ def setup_class(cls):
+ cls.space = gettestobjspace(usemodules=('_ffi',))
+ converter = DummyToAppLevelConverter(cls.space)
+ cls.from_app_level = staticmethod(converter.convert)
+
+ def check(self, w_ffitype, val, w_expected):
+ w_v = self.from_app_level(w_ffitype, val)
+ assert self.space.eq_w(w_v, w_expected)
+
+ def test_int(self):
+ self.check(app_types.sint, 42, self.space.wrap(42))
+ self.check(app_types.sint, -sys.maxint-1, self.space.wrap(-sys.maxint-1))
+
+ def test_uint(self):
+ self.check(app_types.uint, 42, self.space.wrap(42))
+ self.check(app_types.uint, r_uint(sys.maxint+1), self.space.wrap(sys.maxint+1))
@@ -205,7 +205,9 @@ def do_and_wrap(self, w_ffitype):
elif w_ffitype.is_signed():
intval = self.get_signed(w_ffitype)
return space.wrap(intval)
- elif w_ffitype is app_types.ulong or w_ffitype is app_types.ulonglong:
+ elif (w_ffitype is app_types.ulonglong or
+ w_ffitype is app_types.ulong or (libffi.IS_32_BIT and
+ w_ffitype is app_types.uint)):
# Note that we the second check (for ulonglong) is meaningful only
# on 64 bit, because on 32 bit the ulonglong case would have been
# handled by the is_longlong() branch above. On 64 bit, ulonglong

0 comments on commit ea009b3

Please sign in to comment.