[pypy-commit] pypy py3k: avoid OverflowErrors in specialised int tuples now that our w_int is long

pjenvey noreply at buildbot.pypy.org
Wed Oct 17 21:56:47 CEST 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r58188:fae3f8237b0e
Date: 2012-10-17 12:56 -0700
http://bitbucket.org/pypy/pypy/changeset/fae3f8237b0e/

Log:	avoid OverflowErrors in specialised int tuples now that our w_int is
	long

diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -188,15 +188,26 @@
 Cls_ff = make_specialised_class((float, float))
 #Cls_ooo = make_specialised_class((object, object, object))
 
+def is_int_w(space, w_obj):
+    """Determine if obj can be safely casted to an int_w"""
+    try:
+        space.int_w(w_obj)
+    except OperationError, e:
+        if not (e.match(space, space.w_OverflowError) or
+                e.match(space, space.w_TypeError)):
+            raise
+        return False
+    return True
+
 def makespecialisedtuple(space, list_w):
     if len(list_w) == 2:
         w_arg1, w_arg2 = list_w
         w_type1 = space.type(w_arg1)
         #w_type2 = space.type(w_arg2)
         #
-        if w_type1 is space.w_int:
+        if w_type1 is space.w_int and is_int_w(space, w_arg1):
             w_type2 = space.type(w_arg2)
-            if w_type2 is space.w_int:
+            if w_type2 is space.w_int and is_int_w(space, w_arg2):
                 return Cls_ii(space, w_arg1, w_arg2)
             #elif w_type2 is space.w_str:
             #    return Cls_is(space, w_arg1, w_arg2)
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -243,6 +243,10 @@
         assert a == (1, 2.2,) + b
         assert not a != (1, 2.2) + b
 
+    def test_ovfl_bug(self):
+        # previously failed
+        a = (0xffffffffffffffff, 0)
+
 
 class AppTestAll(test_tupleobject.AppTestW_TupleObject):
     pass


More information about the pypy-commit mailing list