Author: Antonio Cuni <[email protected]>
Branch: 
Changeset: r55158:4a38b43757e3
Date: 2012-05-22 14:03 +0000
http://bitbucket.org/pypy/pypy/changeset/4a38b43757e3/

Log:    fix handling of uint values on 32bit

diff --git a/pypy/module/_ffi/test/test_type_converter.py 
b/pypy/module/_ffi/test/test_type_converter.py
--- a/pypy/module/_ffi/test/test_type_converter.py
+++ b/pypy/module/_ffi/test/test_type_converter.py
@@ -126,3 +126,45 @@
         # 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))
diff --git a/pypy/module/_ffi/type_converter.py 
b/pypy/module/_ffi/type_converter.py
--- a/pypy/module/_ffi/type_converter.py
+++ b/pypy/module/_ffi/type_converter.py
@@ -205,7 +205,9 @@
         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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to