Commits

Armin Rigo committed 9112e81

Test and fix: uintptr_t is actually unsigned.

Comments (0)

Files changed (2)

pypy/objspace/std/test/test_stdobjspace.py

         space = gettestobjspace(withstrbuf=True)
         cls = space._get_interplevel_cls(space.w_str)
         assert cls is W_AbstractStringObject
+
+    def test_wrap_various_unsigned_types(self):
+        import sys
+        from pypy.rpython.lltypesystem import lltype, rffi
+        space = self.space
+        value = sys.maxint * 2
+        x = rffi.cast(lltype.Unsigned, value)
+        assert space.eq_w(space.wrap(value), space.wrap(x))
+        x = rffi.cast(rffi.UINTPTR_T, value)
+        assert x > 0
+        assert space.eq_w(space.wrap(value), space.wrap(x))
+        value = 60000
+        x = rffi.cast(rffi.USHORT, value)
+        assert space.eq_w(space.wrap(value), space.wrap(x))
+        value = 200
+        x = rffi.cast(rffi.UCHAR, value)
+        assert space.eq_w(space.wrap(value), space.wrap(x))

pypy/rpython/lltypesystem/rffi.py

           'long long', 'unsigned long long',
           'size_t', 'time_t', 'wchar_t',
           'uintptr_t', 'intptr_t']
+_TYPES_ARE_UNSIGNED = set(['size_t', 'uintptr_t'])   # plus "unsigned *"
 if os.name != 'nt':
     TYPES.append('mode_t')
     TYPES.append('pid_t')
             name = 'u' + name[9:]
             signed = False
         else:
-            signed = (name != 'size_t')
+            signed = (name not in _TYPES_ARE_UNSIGNED)
         name = name.replace(' ', '')
         names.append(name)
         populatelist.append((name.upper(), c_name, signed))