Author: Brian Kearns <[email protected]>
Branch: stdlib-2.7.6
Changeset: r69627:c212634712e1
Date: 2014-03-02 21:24 -0500
http://bitbucket.org/pypy/pypy/changeset/c212634712e1/
Log: fix pwd on 32bit?
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -372,7 +372,6 @@
return OpErrFmt, strings
class OpErrFmtNoArgs(OperationError):
-
def __init__(self, w_type, value):
self._value = value
self.setup(w_type)
diff --git a/pypy/module/pwd/interp_pwd.py b/pypy/module/pwd/interp_pwd.py
--- a/pypy/module/pwd/interp_pwd.py
+++ b/pypy/module/pwd/interp_pwd.py
@@ -3,7 +3,6 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec
-from rpython.rlib.rarithmetic import intmask, most_pos_value_of, widen
eci = ExternalCompilationInfo(includes=['pwd.h'])
@@ -51,8 +50,8 @@
w_tuple = space.newtuple([
space.wrap(rffi.charp2str(pw.c_pw_name)),
space.wrap(rffi.charp2str(pw.c_pw_passwd)),
- space.wrap(intmask(pw.c_pw_uid)),
- space.wrap(intmask(pw.c_pw_gid)),
+ space.wrap(pw.c_pw_uid),
+ space.wrap(pw.c_pw_gid),
space.wrap(rffi.charp2str(pw.c_pw_gecos)),
space.wrap(rffi.charp2str(pw.c_pw_dir)),
space.wrap(rffi.charp2str(pw.c_pw_shell)),
@@ -67,18 +66,22 @@
Return the password database entry for the given numeric user ID.
See pwd.__doc__ for more on password database entries.
"""
+ msg = "getpwuid(): uid not found"
try:
- uid = space.int_w(w_uid)
- if uid < -1 or uid > widen(most_pos_value_of(uid_t)):
+ val = space.int_w(w_uid)
+ uid = rffi.cast(uid_t, val)
+ if val == -1:
+ pass
+ elif val < 0 or uid != val:
raise OperationError(space.w_OverflowError, None)
except OperationError, e:
if e.match(space, space.w_OverflowError):
- raise oefmt(space.w_KeyError, "getpwuid(): uid not found")
+ raise oefmt(space.w_KeyError, msg)
raise
- uid = rffi.cast(uid_t, uid)
pw = c_getpwuid(uid)
if not pw:
- raise oefmt(space.w_KeyError, "getpwuid(): uid not found: %d",
widen(uid))
+ raise OperationError(space.w_KeyError, space.wrap(
+ "%s: %d" % (msg, uid)))
return make_struct_passwd(space, pw)
diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py
--- a/pypy/module/pwd/test/test_pwd.py
+++ b/pypy/module/pwd/test/test_pwd.py
@@ -28,9 +28,13 @@
# -1 is allowed, cast to uid_t
exc = raises(KeyError, pwd.getpwuid, -1)
m = re.match('getpwuid\(\): uid not found: ([0-9]+)', exc.value[0])
- assert m
+ assert m, exc.value[0]
maxval = int(m.group(1))
assert maxval >= 2**32 - 1
+ # shouldn't overflow
+ exc = raises(KeyError, pwd.getpwuid, maxval)
+ m = re.match('getpwuid\(\): uid not found: ([0-9]+)', exc.value[0])
+ assert m, exc.value[0]
# should be out of uid_t range
for v in [-2, maxval+1, 2**128, -2**128]:
exc = raises(KeyError, pwd.getpwuid, v)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit