[pypy-svn] r72765 - in pypy/branch/fix-64/pypy: interpreter interpreter/test module/posix

arigo at codespeak.net arigo at codespeak.net
Wed Mar 24 22:42:11 CET 2010


Author: arigo
Date: Wed Mar 24 22:42:09 2010
New Revision: 72765

Modified:
   pypy/branch/fix-64/pypy/interpreter/baseobjspace.py
   pypy/branch/fix-64/pypy/interpreter/gateway.py
   pypy/branch/fix-64/pypy/interpreter/test/test_gateway.py
   pypy/branch/fix-64/pypy/module/posix/interp_posix.py
Log:
Partially undo a change: getting unsigned integers in RPython here
looks a bit like too big a change, and there is really no reason
to allow a value larger than 2**31 as far as I can tell.  So for
now, we just allow values between 0 and 2**31 as a regular int.


Modified: pypy/branch/fix-64/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/fix-64/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/fix-64/pypy/interpreter/baseobjspace.py	Wed Mar 24 22:42:09 2010
@@ -1116,6 +1116,19 @@
                               self.wrap("expected an unsigned 32-bit integer"))
         return value
 
+    def c_nonnegint_w(self, w_obj):
+        # Like space.int_w(), but raises an app-level ValueError if
+        # the integer is negative or does not fit in 32 bits.  Mostly here
+        # for gateway.py.
+        value = self.int_w(w_obj)
+        if value < 0:
+            raise OperationError(self.w_ValueError,
+                                 self.wrap("expected a non-negative integer"))
+        if value > 2147483647:
+            raise OperationError(self.w_OverflowError,
+                                 self.wrap("expected a 32-bit integer"))
+        return value
+
     def warn(self, msg, w_warningcls):
         self.appexec([self.wrap(msg), w_warningcls], """(msg, warningcls):
             import warnings

Modified: pypy/branch/fix-64/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/fix-64/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/fix-64/pypy/interpreter/gateway.py	Wed Mar 24 22:42:09 2010
@@ -132,6 +132,9 @@
     def visit_c_uint(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
+    def visit_c_nonnegint(self, el, app_sig):
+        self.checked_space_method(el, app_sig)
+
     def visit__Wrappable(self, el, app_sig):
         name = el.__name__
         argname = self.orig_arg()
@@ -242,6 +245,9 @@
     def visit_c_uint(self, typ):
         self.run_args.append("space.c_uint_w(%s)" % (self.scopenext(),))
 
+    def visit_c_nonnegint(self, typ):
+        self.run_args.append("space.c_nonnegint_w(%s)" % (self.scopenext(),))
+
     def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
         try:
             key = tuple(unwrap_spec)
@@ -366,6 +372,9 @@
     def visit_c_uint(self, typ):
         self.unwrap.append("space.c_uint_w(%s)" % (self.nextarg(),))
 
+    def visit_c_nonnegint(self, typ):
+        self.unwrap.append("space.c_nonnegint_w(%s)" % (self.nextarg(),))
+
     def make_fastfunc(unwrap_spec, func):
         unwrap_info = UnwrapSpec_FastFunc_Unwrap()
         unwrap_info.apply_over(unwrap_spec)

Modified: pypy/branch/fix-64/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/fix-64/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/branch/fix-64/pypy/interpreter/test/test_gateway.py	Wed Mar 24 22:42:09 2010
@@ -207,9 +207,12 @@
                                                    'c_int'])
         app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
                                                    'c_uint'])
+        app_ng = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+                                                   'c_nonnegint'])
         assert app_ug is not app_g
         w_app_g = space.wrap(app_g)
         w_app_ug = space.wrap(app_ug)
+        w_app_ng = space.wrap(app_ng)
         #
         assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)),
                                space.wrap(13))
@@ -230,6 +233,14 @@
         space.raises_w(space.w_OverflowError,
                        space.call_function, w_app_ug,
                        space.wrap(r_longlong(0x100000000)))
+        #
+        assert self.space.eq_w(space.call_function(w_app_ng, space.wrap(7)),
+                               space.wrap(13))
+        space.raises_w(space.w_OverflowError,
+                       space.call_function, w_app_ng,
+                       space.wrap(r_longlong(0x80000000)))
+        space.raises_w(space.w_ValueError,
+                       space.call_function, w_app_ng, space.wrap(-1))
 
     def test_interp2app_unwrap_spec_args_w(self):
         space = self.space

Modified: pypy/branch/fix-64/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/fix-64/pypy/module/posix/interp_posix.py	(original)
+++ pypy/branch/fix-64/pypy/module/posix/interp_posix.py	Wed Mar 24 22:42:09 2010
@@ -649,7 +649,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None
-setuid.unwrap_spec = [ObjSpace, "c_uint"]
+setuid.unwrap_spec = [ObjSpace, "c_nonnegint"]
 
 def seteuid(space, arg):
     """ seteuid(uid)
@@ -661,7 +661,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None
-seteuid.unwrap_spec = [ObjSpace, "c_uint"]
+seteuid.unwrap_spec = [ObjSpace, "c_nonnegint"]
 
 def setgid(space, arg):
     """ setgid(gid)
@@ -673,7 +673,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None
-setgid.unwrap_spec = [ObjSpace, "c_uint"]
+setgid.unwrap_spec = [ObjSpace, "c_nonnegint"]
 
 def setegid(space, arg):
     """ setegid(gid)
@@ -685,7 +685,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None
-setegid.unwrap_spec = [ObjSpace, "c_uint"]
+setegid.unwrap_spec = [ObjSpace, "c_nonnegint"]
 
 def chroot(space, path):
     """ chroot(path)
@@ -785,7 +785,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None                
-setreuid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
+setreuid.unwrap_spec = [ObjSpace, "c_nonnegint", "c_nonnegint"]
 
 def setregid(space, rgid, egid):
     """ setregid(rgid, egid)
@@ -797,7 +797,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None                
-setregid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
+setregid.unwrap_spec = [ObjSpace, "c_nonnegint", "c_nonnegint"]
 
 def getsid(space, pid):
     """ getsid(pid) -> sid
@@ -866,7 +866,7 @@
     except OSError, e:
         raise wrap_oserror(space, e)
     return space.w_None
-chown.unwrap_spec = [ObjSpace, str, "c_uint", "c_uint"]
+chown.unwrap_spec = [ObjSpace, str, "c_nonnegint", "c_nonnegint"]
 
 if _WIN:
     from pypy.rlib import rwin32



More information about the Pypy-commit mailing list