Author: Christian Tismer <[email protected]>
Branch: win64-stage1
Changeset: r49766:7c4368db5b47
Date: 2011-11-25 00:30 +0100
http://bitbucket.org/pypy/pypy/changeset/7c4368db5b47/
Log: unification of int/long. Extended is_valid_int by parameter
'force_type=True'. This function should be used in all cases where I
changed a check for int to (int, long)
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
@@ -160,7 +160,7 @@
if isinstance(x, OperationError):
raise TypeError, ("attempt to wrap already wrapped exception: %s"%
(x,))
- if isinstance(x, (int, long)) and is_valid_int(x):
+ if is_valid_int(x, force_type=False):
if isinstance(x, bool):
return self.newbool(x)
else:
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -136,7 +136,12 @@
# the replacement for sys.maxint
maxint = int(LONG_TEST - 1)
-def is_valid_int(r):
+def is_valid_int(r, force_type=True):
+ if force_type_type:
+ assert isinstance(r, (int, long))
+ else:
+ if not isinstance(r, (int, long)):
+ return True
return -maxint - 1 <= r <= maxint
def ovfcheck(r):
@@ -146,8 +151,8 @@
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 type(r) is long and not is_valid_int(r):
- # the type check is needed to make ovfcheck skip symbolics.
+ if not is_valid_int(r, force_type=False):
+ # checks only if applicable to r's type.
# this happens in the garbage collector.
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
@@ -49,14 +49,14 @@
def _widen_digit(x):
if not we_are_translated():
- assert isinstance(x, (int, long)) and is_valid_int(x), "widen_digit()
takes an int, got a %r" % type(x)
+ assert is_valid_int(x), "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 isinstance(x, (int, long)) and is_valid_int(x), "store_digit()
takes an int, got a %r" % type(x)
+ assert is_valid_int(x), "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
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit