[pypy-commit] pypy release-5.x: Issue #2388: the problem is obscure interaction with a different call (I

mattip pypy.commits at gmail.com
Sun Sep 4 11:00:27 EDT 2016


Author: Matti Picus <matti.picus at gmail.com>
Branch: release-5.x
Changeset: r86863:145c1bd68950
Date: 2016-09-04 17:55 +0300
http://bitbucket.org/pypy/pypy/changeset/145c1bd68950/

Log:	Issue #2388: the problem is obscure interaction with a different
	call (I don't know which one) with the signature (string, float),
	which was considered as more general than the signature (string,
	int) of os.access(). (grafted from
	7d6c66b1477085a45a3a64056a010adf3e018924)

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -17,7 +17,7 @@
 from rpython.flowspace.model import Variable, Constant, const
 from rpython.flowspace.operation import op
 from rpython.rlib import rarithmetic
-from rpython.annotator.model import AnnotatorError
+from rpython.annotator.model import AnnotatorError, TLS
 
 BINARY_OPERATIONS = set([oper.opname for oper in op.__dict__.values()
                         if oper.dispatch == 2])
@@ -436,6 +436,11 @@
 class __extend__(pairtype(SomeFloat, SomeFloat)):
 
     def union((flt1, flt2)):
+        if not TLS.allow_int_to_float:
+            # in this mode, if one of the two is actually the
+            # subclass SomeInteger, complain
+            if isinstance(flt1, SomeInteger) or isinstance(flt2, SomeInteger):
+                raise UnionError(flt1, flt2)
         return SomeFloat()
 
     add = sub = mul = union
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -44,6 +44,7 @@
     # A global attribute :-(  Patch it with 'True' to enable checking of
     # the no_nul attribute...
     check_str_without_nul = False
+    allow_int_to_float = True
 TLS = State()
 
 class SomeObject(object):
diff --git a/rpython/rlib/rmarshal.py b/rpython/rlib/rmarshal.py
--- a/rpython/rlib/rmarshal.py
+++ b/rpython/rlib/rmarshal.py
@@ -346,11 +346,15 @@
     # on s_bigger.  It relies on the fact that s_bigger was created with
     # an expression like 'annotation([s_item])' which returns a ListDef with
     # no bookkeeper, on which side-effects are not allowed.
+    saved = annmodel.TLS.allow_int_to_float
     try:
+        annmodel.TLS.allow_int_to_float = False
         s_union = annmodel.unionof(s_bigger, s_smaller)
         return s_bigger.contains(s_union)
     except (annmodel.UnionError, TooLateForChange):
         return False
+    finally:
+        annmodel.TLS.allow_int_to_float = saved
 
 
 class __extend__(pairtype(MTag, annmodel.SomeObject)):
diff --git a/rpython/rlib/test/test_rmarshal.py b/rpython/rlib/test/test_rmarshal.py
--- a/rpython/rlib/test/test_rmarshal.py
+++ b/rpython/rlib/test/test_rmarshal.py
@@ -128,10 +128,12 @@
 
 def test_llinterp_marshal():
     from rpython.rtyper.test.test_llinterp import interpret
-    marshaller = get_marshaller([(int, str, float)])
+    marshaller1 = get_marshaller([(int, str, float)])
+    marshaller2 = get_marshaller([(int, str, int)])
     def f():
         buf = []
-        marshaller(buf, [(5, "hello", -0.5), (7, "world", 1E100)])
+        marshaller1(buf, [(5, "hello", -0.5), (7, "world", 1E100)])
+        marshaller2(buf, [(5, "hello", 1)])
         return ''.join(buf)
     res = interpret(f, [])
     res = ''.join(res.chars)
@@ -139,14 +141,20 @@
         assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
                        's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
                        'i\x07\x00\x00\x00s\x05\x00\x00\x00world'
-                       'f\x061e+100')
+                       'f\x061e+100'
+                       '[\x01\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
+                       's\x05\x00\x00\x00helloi\x01\x00\x00\x00')
     else:
         assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00'
                        'I\x05\x00\x00\x00\x00\x00\x00\x00'
                        's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
                        'I\x07\x00\x00\x00\x00\x00\x00\x00'
                        's\x05\x00\x00\x00world'
-                       'f\x061e+100')
+                       'f\x061e+100'
+                       '[\x01\x00\x00\x00(\x03\x00\x00\x00'
+                       'I\x05\x00\x00\x00\x00\x00\x00\x00'
+                       's\x05\x00\x00\x00hello'
+                       'I\x01\x00\x00\x00\x00\x00\x00\x00')
 
 def test_llinterp_unmarshal():
     from rpython.rtyper.test.test_llinterp import interpret


More information about the pypy-commit mailing list