Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r86812:7d6c66b14770 Date: 2016-09-01 10:26 +0200 http://bitbucket.org/pypy/pypy/changeset/7d6c66b14770/
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(). 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit