Commits

Maciej Fijalkowski committed a3eaf1b Merge

merge from upstream

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))
             b.append(cp[i])
             i += 1
         return assert_str0(b.build())
+    charp2strn._annenforceargs_ = [None, annmodel.SomeInteger(nonneg=True)]
 
     # char* and size -> str (which can contain null bytes)
     def charpsize2str(cp, size):
         b = builder_class(size)
         b.append_charpsize(cp, size)
         return b.build()
-    charpsize2str._annenforceargs_ = [None, int]
+    charpsize2str._annenforceargs_ = [None, annmodel.SomeInteger(nonneg=True)]
 
     return (str2charp, free_charp, charp2str,
             get_nonmovingbuffer, free_nonmovingbuffer,