[pypy-svn] r72562 - in pypy/branch/fix-64/pypy: interpreter interpreter/test module/posix module/posix/test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 22 15:59:32 CET 2010
Author: arigo
Date: Mon Mar 22 15:59:30 2010
New Revision: 72562
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
pypy/branch/fix-64/pypy/module/posix/test/test_posix2.py
Log:
Tweaks. Add to unwrap_spec the entry 'c_int' and 'c_uint', meaning
a C-sized int or unsigned int. You still get an RPython integer,
but if you are on a 64-bit platform and the integer would not fix
a C-level 'int', then you get an OverflowError.
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 Mon Mar 22 15:59:30 2010
@@ -9,11 +9,14 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.debug import make_sure_not_resized
from pypy.rlib.timer import DummyTimer, Timer
+from pypy.rlib.rarithmetic import r_uint
from pypy.rlib import jit
import os, sys
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
+UINT_MAX_32_BITS = r_uint(4294967295)
+
class W_Root(object):
"""This is the abstract root class of all wrapped objects that live
@@ -1095,6 +1098,24 @@
self.wrap("expected a non-negative integer"))
return value
+ def c_int_w(self, w_obj):
+ # Like space.int_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.int_w(w_obj)
+ if value < -2147483647-1 or value > 2147483647:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected a 32-bit integer"))
+ return value
+
+ def c_uint_w(self, w_obj):
+ # Like space.uint_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.uint_w(w_obj)
+ if value > UINT_MAX_32_BITS:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected an unsigned 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 Mon Mar 22 15:59:30 2010
@@ -126,6 +126,12 @@
def visit_nonnegint(self, el, app_sig):
self.checked_space_method(el, app_sig)
+ def visit_c_int(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
+ def visit_c_uint(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()
@@ -230,6 +236,12 @@
def visit_nonnegint(self, typ):
self.run_args.append("space.nonnegint_w(%s)" % (self.scopenext(),))
+ def visit_c_int(self, typ):
+ self.run_args.append("space.c_int_w(%s)" % (self.scopenext(),))
+
+ def visit_c_uint(self, typ):
+ self.run_args.append("space.c_uint_w(%s)" % (self.scopenext(),))
+
def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
try:
key = tuple(unwrap_spec)
@@ -348,6 +360,12 @@
def visit_nonnegint(self, typ):
self.unwrap.append("space.nonnegint_w(%s)" % (self.nextarg(),))
+ def visit_c_int(self, typ):
+ self.unwrap.append("space.c_int_w(%s)" % (self.nextarg(),))
+
+ def visit_c_uint(self, typ):
+ self.unwrap.append("space.c_uint_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 Mon Mar 22 15:59:30 2010
@@ -197,6 +197,40 @@
space.raises_w(space.w_ValueError,
space.call_function, w_app_g, space.wrap(-1))
+ def test_interp2app_unwrap_spec_c_int(self):
+ from pypy.rlib.rarithmetic import r_longlong
+ space = self.space
+ w = space.wrap
+ def g(space, x):
+ return space.wrap(x + 6)
+ app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_int'])
+ app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_uint'])
+ assert app_ug is not app_g
+ w_app_g = space.wrap(app_g)
+ w_app_ug = space.wrap(app_ug)
+ #
+ assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)),
+ space.wrap(13))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(0x80000000)))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(-0x80000001)))
+ #
+ assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)),
+ space.wrap(13))
+ assert self.space.eq_w(space.call_function(w_app_ug,
+ space.wrap(0x7FFFFFFF)),
+ space.wrap(r_longlong(0x7FFFFFFF+6)))
+ space.raises_w(space.w_ValueError,
+ space.call_function, w_app_ug, space.wrap(-1))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_ug,
+ space.wrap(r_longlong(0x100000000)))
+
def test_interp2app_unwrap_spec_args_w(self):
space = self.space
w = space.wrap
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 Mon Mar 22 15:59:30 2010
@@ -20,7 +20,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(fd)
-open.unwrap_spec = [ObjSpace, str, int, int]
+open.unwrap_spec = [ObjSpace, str, "c_int", "c_int"]
def lseek(space, fd, pos, how):
"""Set the current position of a file descriptor. Return the new position.
@@ -32,7 +32,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(pos)
-lseek.unwrap_spec = [ObjSpace, int, r_longlong, int]
+lseek.unwrap_spec = [ObjSpace, "c_int", r_longlong, "c_int"]
def isatty(space, fd):
"""Return True if 'fd' is an open file descriptor connected to the
@@ -43,7 +43,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-isatty.unwrap_spec = [ObjSpace, int]
+isatty.unwrap_spec = [ObjSpace, "c_int"]
def read(space, fd, buffersize):
"""Read data from a file descriptor."""
@@ -53,7 +53,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(s)
-read.unwrap_spec = [ObjSpace, int, int]
+read.unwrap_spec = [ObjSpace, "c_int", int]
def write(space, fd, data):
"""Write a string to a file descriptor. Return the number of bytes
@@ -64,7 +64,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-write.unwrap_spec = [ObjSpace, int, 'bufferstr']
+write.unwrap_spec = [ObjSpace, "c_int", 'bufferstr']
def close(space, fd):
"""Close a file descriptor (for low level IO)."""
@@ -72,12 +72,12 @@
os.close(fd)
except OSError, e:
raise wrap_oserror(space, e)
-close.unwrap_spec = [ObjSpace, int]
+close.unwrap_spec = [ObjSpace, "c_int"]
def closerange(fd_low, fd_high):
"""Closes all file descriptors in [fd_low, fd_high), ignoring errors."""
rposix.closerange(fd_low, fd_high)
-closerange.unwrap_spec = [int, int]
+closerange.unwrap_spec = ["c_int", "c_int"]
def ftruncate(space, fd, length):
"""Truncate a file to a specified length."""
@@ -85,21 +85,21 @@
os.ftruncate(fd, length)
except OSError, e:
raise wrap_oserror(space, e)
-ftruncate.unwrap_spec = [ObjSpace, int, r_longlong]
+ftruncate.unwrap_spec = [ObjSpace, "c_int", r_longlong]
def fsync(space, fd):
try:
os.fsync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fsync.unwrap_spec = [ObjSpace, int]
+fsync.unwrap_spec = [ObjSpace, "c_int"]
def fdatasync(space, fd):
try:
os.fdatasync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fdatasync.unwrap_spec = [ObjSpace, int]
+fdatasync.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -157,7 +157,7 @@
raise wrap_oserror(space, e)
else:
return build_stat_result(space, st)
-fstat.unwrap_spec = [ObjSpace, int]
+fstat.unwrap_spec = [ObjSpace, "c_int"]
def stat(space, path):
"""Perform a stat system call on the given path. Return an object
@@ -221,7 +221,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(newfd)
-dup.unwrap_spec = [ObjSpace, int]
+dup.unwrap_spec = [ObjSpace, "c_int"]
def dup2(space, old_fd, new_fd):
"""Duplicate a file descriptor."""
@@ -229,7 +229,7 @@
os.dup2(old_fd, new_fd)
except OSError, e:
raise wrap_oserror(space, e)
-dup2.unwrap_spec = [ObjSpace, int, int]
+dup2.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def access(space, path, mode):
"""
@@ -247,7 +247,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(ok)
-access.unwrap_spec = [ObjSpace, str, int]
+access.unwrap_spec = [ObjSpace, str, "c_int"]
def times(space):
@@ -335,7 +335,7 @@
os.mkdir(path, mode)
except OSError, e:
raise wrap_oserror(space, e)
-mkdir.unwrap_spec = [ObjSpace, str, int]
+mkdir.unwrap_spec = [ObjSpace, str, "c_int"]
def rmdir(space, path):
"""Remove a directory."""
@@ -353,7 +353,7 @@
raise OperationError(space.w_ValueError,
space.wrap("strerror() argument out of range"))
return space.wrap(text)
-strerror.unwrap_spec = [ObjSpace, int]
+strerror.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -440,7 +440,7 @@
os.chmod(path, mode)
except OSError, e:
raise wrap_oserror(space, e)
-chmod.unwrap_spec = [ObjSpace, str, int]
+chmod.unwrap_spec = [ObjSpace, str, "c_int"]
def rename(space, old, new):
"Rename a file or directory."
@@ -454,7 +454,7 @@
"Set the current numeric umask and return the previous umask."
prevmask = os.umask(mask)
return space.wrap(prevmask)
-umask.unwrap_spec = [ObjSpace, int]
+umask.unwrap_spec = [ObjSpace, "c_int"]
def getpid(space):
"Return the current process id."
@@ -471,7 +471,7 @@
os.kill(pid, sig)
except OSError, e:
raise wrap_oserror(space, e)
-kill.unwrap_spec = [ObjSpace, int, int]
+kill.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def abort(space):
"""Abort the interpreter immediately. This 'dumps core' or otherwise fails
@@ -531,11 +531,11 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.newtuple([space.wrap(pid), space.wrap(status)])
-waitpid.unwrap_spec = [ObjSpace, int, int]
+waitpid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def _exit(space, status):
os._exit(status)
-_exit.unwrap_spec = [ObjSpace, int]
+_exit.unwrap_spec = [ObjSpace, "c_int"]
def execv(space, command, w_args):
""" execv(path, args)
@@ -649,7 +649,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setuid.unwrap_spec = [ObjSpace, int]
+setuid.unwrap_spec = [ObjSpace, "c_uint"]
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, int]
+seteuid.unwrap_spec = [ObjSpace, "c_uint"]
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, int]
+setgid.unwrap_spec = [ObjSpace, "c_uint"]
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, int]
+setegid.unwrap_spec = [ObjSpace, "c_uint"]
def chroot(space, path):
""" chroot(path)
@@ -761,7 +761,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(pgid)
-getpgid.unwrap_spec = [ObjSpace, int]
+getpgid.unwrap_spec = [ObjSpace, "c_int"]
def setpgid(space, pid, pgrp):
""" setpgid(pid, pgrp)
@@ -773,7 +773,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setpgid.unwrap_spec = [ObjSpace, int, int]
+setpgid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def setreuid(space, ruid, euid):
""" setreuid(ruid, euid)
@@ -785,7 +785,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setreuid.unwrap_spec = [ObjSpace, int, int]
+setreuid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
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, int, int]
+setregid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
def getsid(space, pid):
""" getsid(pid) -> sid
@@ -809,7 +809,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(sid)
-getsid.unwrap_spec = [ObjSpace, int]
+getsid.unwrap_spec = [ObjSpace, "c_int"]
def setsid(space):
""" setsid()
@@ -831,7 +831,7 @@
def WSTAR(space, status):
return space.newbool(getattr(os, name)(status))
WSTAR.__doc__ = getattr(os, name).__doc__
- WSTAR.unwrap_spec = [ObjSpace, int]
+ WSTAR.unwrap_spec = [ObjSpace, "c_int"]
WSTAR.func_name = name
return WSTAR
@@ -845,7 +845,7 @@
return space.wrap(os.ttyname(fd))
except OSError, e:
raise wrap_oserror(space, e)
-ttyname.unwrap_spec = [ObjSpace, int]
+ttyname.unwrap_spec = [ObjSpace, "c_int"]
def sysconf(space, w_num_or_name):
# XXX slightly non-nice, reuses the sysconf of the underlying os module
@@ -866,7 +866,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-chown.unwrap_spec = [ObjSpace, str, int, int]
+chown.unwrap_spec = [ObjSpace, str, "c_uint", "c_uint"]
if _WIN:
from pypy.rlib import rwin32
Modified: pypy/branch/fix-64/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/fix-64/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/branch/fix-64/pypy/module/posix/test/test_posix2.py Mon Mar 22 15:59:30 2010
@@ -380,7 +380,7 @@
if hasattr(os, 'setuid'):
def test_os_setuid_error(self):
os = self.posix
- raises(OSError, os.setuid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setuid, -100000)
if hasattr(os, 'getgid'):
def test_os_getgid(self):
@@ -396,13 +396,13 @@
if hasattr(os, 'setgid'):
def test_os_setgid_error(self):
os = self.posix
- raises(OSError, os.setgid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setgid, -100000)
if hasattr(os, 'getsid'):
def test_os_getsid(self):
os = self.posix
assert os.getsid(0) == self.getsid0
- raises(OSError, os.getsid, -100000)
+ raises((OSError, ValueError, OverflowError), os.getsid, -100000)
if hasattr(os, 'sysconf'):
def test_os_sysconf(self):
More information about the Pypy-commit
mailing list