[pypy-commit] pypy win64-stage1: blaming myself about bad ideas. is_valid_int should never raise an exception, basta!

ctismer noreply at buildbot.pypy.org
Mon Nov 28 19:11:40 CET 2011


Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r49929:d9abe6cd48d4
Date: 2011-11-28 18:31 +0100
http://bitbucket.org/pypy/pypy/changeset/d9abe6cd48d4/

Log:	blaming myself about bad ideas. is_valid_int should never raise an
	exception, basta!

diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -269,7 +269,7 @@
 
     def __init__(self, value):
         if not we_are_translated():
-            if is_valid_int(value, force_type=False):
+            if is_valid_int(value):
                 value = int(value)    # bool -> int
             else:
                 assert isinstance(value, Symbolic)
diff --git a/pypy/objspace/flow/model.py b/pypy/objspace/flow/model.py
--- a/pypy/objspace/flow/model.py
+++ b/pypy/objspace/flow/model.py
@@ -548,7 +548,7 @@
                     cases = [link.exitcase for link in block.exits]
                     has_default = cases[-1] == 'default'
                     for n in cases[:len(cases)-has_default]:
-                        if is_valid_int(n, force_type=False):
+                        if is_valid_int(n):
                             continue
                         if isinstance(n, (str, unicode)) and len(n) == 1:
                             continue
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 is_valid_int(x, force_type=False):
+        if is_valid_int(x):
             if isinstance(x, bool):
                 return self.newbool(x)
             else:
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -202,7 +202,7 @@
                 self.space.raises_w(self.space.w_IndexError,
                                     self.space.setitem, w_list, w(key), w(42))
             else:
-                if is_valid_int(value, force_type=False):   # non-slicing
+                if is_valid_int(value):   # non-slicing
                     if random.random() < 0.25:   # deleting
                         self.space.delitem(w_list, w(key))
                         del expected[key]
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -136,13 +136,9 @@
 # the replacement for sys.maxint
 maxint = int(LONG_TEST - 1)
 
-def is_valid_int(r, force_type=True):
-    if force_type:
-        assert isinstance(r, (int, long))
-    else:
-        if not isinstance(r, (int, long)):
-            return False
-    return -maxint - 1 <= r <= maxint
+def is_valid_int(r):
+    return isinstance(r, (int, long)) and (
+        -maxint - 1 <= r <= maxint)
 
 def ovfcheck(r):
     "NOT_RPYTHON"
@@ -151,7 +147,7 @@
     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 not is_valid_int(r, force_type=False):
+    if not is_valid_int(r):
         # checks only if applicable to r's type.
         # this happens in the garbage collector.
         raise OverflowError, "signed integer expression did overflow"
diff --git a/pypy/rpython/lltypesystem/llarena.py b/pypy/rpython/lltypesystem/llarena.py
--- a/pypy/rpython/lltypesystem/llarena.py
+++ b/pypy/rpython/lltypesystem/llarena.py
@@ -166,7 +166,7 @@
         return '<arenaaddr %s + %d>' % (self.arena, self.offset)
 
     def __add__(self, other):
-        if is_valid_int(other, force_type=False):
+        if is_valid_int(other):
             position = self.offset + other
         elif isinstance(other, llmemory.AddressOffset):
             # this is really some Do What I Mean logic.  There are two
@@ -186,7 +186,7 @@
     def __sub__(self, other):
         if isinstance(other, llmemory.AddressOffset):
             other = llmemory.raw_malloc_usage(other)
-        if is_valid_int(other, force_type=False):
+        if is_valid_int(other):
             return self.arena.getaddr(self.offset - other)
         if isinstance(other, fakearenaaddress):
             if self.arena is not other.arena:
diff --git a/pypy/rpython/lltypesystem/llmemory.py b/pypy/rpython/lltypesystem/llmemory.py
--- a/pypy/rpython/lltypesystem/llmemory.py
+++ b/pypy/rpython/lltypesystem/llmemory.py
@@ -30,7 +30,7 @@
     def __ge__(self, other):
         if self is other:
             return True
-        elif (is_valid_int(other, force_type=False) and other == 0 and
+        elif (is_valid_int(other) and other == 0 and
             self.known_nonneg()):
             return True
         else:
diff --git a/pypy/rpython/lltypesystem/opimpl.py b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -191,7 +191,7 @@
     return intmask(x + y)
 
 def op_int_sub(x, y):
-    if not is_valid_int(x, force_type=False):
+    if not is_valid_int(x):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
     assert is_valid_int(y)
@@ -217,14 +217,14 @@
     return a <= b < c
 
 def op_int_and(x, y):
-    if not is_valid_int(x, force_type=False):
+    if not is_valid_int(x):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
     assert is_valid_int(y)
     return x & y
 
 def op_int_or(x, y):
-    if not is_valid_int(x, force_type=False):
+    if not is_valid_int(x):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
     assert is_valid_int(y)
@@ -244,7 +244,7 @@
     return intmask(x * y)
 
 def op_int_rshift(x, y):
-    if not is_valid_int(x, force_type=False):
+    if not is_valid_int(x):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
     assert is_valid_int(y)


More information about the pypy-commit mailing list