diff --git a/test/Makefile b/test/Makefile index 00662c6c..2f08b526 100644 --- a/test/Makefile +++ b/test/Makefile @@ -64,10 +64,12 @@ check-3.5: check-bytecode #: Run working tests from Python 3.6 check-3.6: check-bytecode $(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify $(COMPILE) + $(PYTHON) test_pythonlib.py --bytecode-3.6-run --verify-run #: Run working tests from Python 3.7 check-3.7: check-bytecode $(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(COMPILE) + $(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run # FIXME #: this is called when running under pypy3.5-5.8.0 or pypy2-5.6.0 diff --git a/test/bytecode_3.7_run/01_chained_compare.pyc b/test/bytecode_3.7_run/01_chained_compare.pyc new file mode 100644 index 00000000..b5aba77c Binary files /dev/null and b/test/bytecode_3.7_run/01_chained_compare.pyc differ diff --git a/test/simple_source/bug37/01_chained_compare.py b/test/simple_source/bug37/01_chained_compare.py new file mode 100644 index 00000000..f79f299d --- /dev/null +++ b/test/simple_source/bug37/01_chained_compare.py @@ -0,0 +1,19 @@ +# From Python 3.7 pickle.py +# Bug was different code generation for chained comparisons than prior Python versions + + +def chained_compare_a(protocol): + if not 0 <= protocol <= 7: + raise ValueError("pickle protocol must be <= %d" % 7) + +def chained_compare_b(a, obj): + if a: + if -0x80000000 <= obj <= 0x7fffffff: + return 5 + +chained_compare_a(3) +try: + chained_compare_a(8) +except ValueError: + pass +chained_compare_b(True, 0x0) diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index de5d880a..64b2c4d7 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -67,6 +67,17 @@ class Python37Parser(Python36Parser): # FIXME: generalize and specialize call ::= expr CALL_METHOD_0 + + testtrue ::= compare_chained37 + + compare_chained37 ::= expr compare_chained1a_37 + compare_chained37 ::= expr compare_chained1b_37 + compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD + compare_chained2b_37 ::= expr COMPARE_OP POP_JUMP_IF_FALSE JUMP_FORWARD + compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE + compare_chained2a_37 ELSE POP_TOP COME_FROM + compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE + compare_chained2b_37 ELSE POP_TOP JUMP_FORWARD COME_FROM """ def customize_grammar_rules(self, tokens, customize): diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index 9a4d2aa5..5dce03f7 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -917,6 +917,16 @@ def customize_for_version3(self, version): 'async_for_stmt': ( '%|async for %c in %c:\n%+%c%-%-\n\n', 7, 1, 17), + 'compare_chained1a_37': ( ' %[3]{pattr.replace("-", " ")} %p %p', + (0, 19), + (-4, 19)), + 'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p', + (0, 19), + (-5, 19)), + 'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)), + + 'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)), + }) pass pass # version >= 3.6