Author: Dario Bertini <berda...@gmail.com> Branch: win64 test Changeset: r45266:9476f6f9941f Date: 2011-07-02 15:19 +0200 http://bitbucket.org/pypy/pypy/changeset/9476f6f9941f/
Log: Fixed ovfcheck, intmask and the objspace wrap Also: lessened other checks to allow for long types in place of ints diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -1,5 +1,6 @@ import __builtin__ import types +import sys from pypy.interpreter import pyframe, function, special from pypy.interpreter.baseobjspace import ObjSpace, Wrappable from pypy.interpreter.error import OperationError, operationerrfmt @@ -161,7 +162,7 @@ if isinstance(x, OperationError): raise TypeError, ("attempt to wrap already wrapped exception: %s"% (x,)) - if isinstance(x, int): + if isinstance(x, (int, long)) and -sys.maxint -1 <= x <= sys.maxint: if isinstance(x, bool): return self.newbool(x) else: diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py --- a/pypy/rlib/debug.py +++ b/pypy/rlib/debug.py @@ -302,7 +302,7 @@ """Give a translation-time error if 'x' is not a plain int (e.g. if it's a r_longlong or an r_uint). """ - assert type(x) is int + assert type(x) in (int, long) return x class Entry(ExtRegistryEntry): diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py --- a/pypy/rlib/rarithmetic.py +++ b/pypy/rlib/rarithmetic.py @@ -63,11 +63,11 @@ """ def intmask(n): - if isinstance(n, int): - return int(n) # possibly bool->int if isinstance(n, objectmodel.Symbolic): return n # assume Symbolics don't overflow assert not isinstance(n, float) + if -sys.maxint -1 < n < sys.maxint: + return int(n) n = long(n) n &= LONG_MASK if n >= LONG_TEST: @@ -111,8 +111,8 @@ # raise OverflowError if the operation did overflow assert not isinstance(r, r_uint), "unexpected ovf check on unsigned" assert not isinstance(r, r_longlong), "ovfcheck not supported on r_longlong" - assert not isinstance(r,r_ulonglong),"ovfcheck not supported on r_ulonglong" - if abs(r) > sys.maxint: + assert not isinstance(r, r_ulonglong), "ovfcheck not supported on r_ulonglong" + if r > sys.maxint or r < -sys.maxint - 1: raise OverflowError, "signed integer expression did overflow" return r diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py --- a/pypy/rlib/rbigint.py +++ b/pypy/rlib/rbigint.py @@ -51,14 +51,14 @@ def _widen_digit(x): if not we_are_translated(): - assert type(x) is int, "widen_digit() takes an int, got a %r" % type(x) + assert type(x) in (int, long), "widen_digit() takes an int, got a %r" % type(x) if SHIFT <= 15: return int(x) return r_longlong(x) def _store_digit(x): if not we_are_translated(): - assert type(x) is int, "store_digit() takes an int, got a %r" % type(x) + assert type(x) in (int, long), "store_digit() takes an int, got a %r" % type(x) if SHIFT <= 15: return rffi.cast(rffi.SHORT, x) elif SHIFT <= 31: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit