Commits

Armin Rigo  committed 3725099 Merge

Merged in andrewsmedina/numpypy/stdlib-2.7.4-pwd-fix (pull request #175)

fixed support for pwd stdlib 2.7.4

  • Participants
  • Parent commits 248b5a2, 2102788
  • Branches stdlib-2.7.4

Comments (0)

Files changed (2)

File pypy/module/pwd/interp_pwd.py

 from rpython.rtyper.tool import rffi_platform
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import operationerrfmt
+from pypy.interpreter.error import OperationError, operationerrfmt
 from rpython.rlib.rarithmetic import intmask
 
+import sys
+
+
+if sys.maxint == 2147483647:
+    def check_uid_range(space, num):
+        pass
+else:
+    def check_uid_range(space, num):
+        if num < -(1<<31) or num >= (1<<32):
+            msg = "getpwuid(): uid not found"
+            raise OperationError(space.w_KeyError, space.wrap(msg))
+
+
 eci = ExternalCompilationInfo(
     includes=['pwd.h']
     )
         ])
     return space.call_function(w_passwd_struct, w_tuple)
 
-@unwrap_spec(uid=int)
-def getpwuid(space, uid):
+
+def getpwuid(space, w_uid):
     """
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
                       pw_gid,pw_gecos,pw_dir,pw_shell)
     Return the password database entry for the given numeric user ID.
     See pwd.__doc__ for more on password database entries.
     """
+    try:
+        uid = space.int_w(w_uid)
+    except OperationError, e:
+        if e.match(space, space.w_OverflowError):
+            msg = "getpwuid(): uid not found"
+            raise OperationError(space.w_KeyError, space.wrap(msg))
+        raise
+    check_uid_range(space, uid)
     pw = c_getpwuid(uid)
     if not pw:
         raise operationerrfmt(space.w_KeyError,
     finally:
         c_endpwent()
     return space.newlist(users_w)
-    

File pypy/module/pwd/test/test_pwd.py

         else:
             assert pw.pw_dir.startswith('/')
         assert pw.pw_shell.startswith('/')
-        #
         assert type(pw.pw_uid) is int
         assert type(pw.pw_gid) is int
+        # should be out of uid_t range
+        raises(KeyError, pwd.getpwuid, 2**128)
+        raises(KeyError, pwd.getpwuid, -2**128)
+        raises(KeyError, pwd.getpwuid, (1<<32))
+        raises(KeyError, pwd.getpwuid, -(1<<32))
 
     def test_getpwnam(self):
         import pwd