From a97d4003c7814ee66fc821e146a814c6ef270d85 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 13 Jan 2019 19:37:41 -0500 Subject: [PATCH] Python 3.7 changes chained comparison code fixes #206 --- test/Makefile | 2 ++ test/bytecode_3.7_run/01_chained_compare.pyc | Bin 0 -> 573 bytes .../simple_source/bug37/01_chained_compare.py | 19 ++++++++++++++++++ uncompyle6/parsers/parse37.py | 11 ++++++++++ uncompyle6/semantics/customize3.py | 10 +++++++++ 5 files changed, 42 insertions(+) create mode 100644 test/bytecode_3.7_run/01_chained_compare.pyc create mode 100644 test/simple_source/bug37/01_chained_compare.py 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 0000000000000000000000000000000000000000..b5aba77c7a269aae947838003d0c85b61cbc4f7c GIT binary patch literal 573 zcmZWmOH0E*5T4m=Yb+`VB3^_bD&*n=4+=gIMeyWB@r6**%%ZVr5;o025ftm6@xOQ% zdi9jQ;HA#Q2ci?^J^N+8-JQ|V2CxiX*DqcW;7yWmaXHv#&G*?55I(^5?n*eH@LMzW($|9va=aH35Kk%Ju*{W%!`3qO* c*b3a;=%iG{W~-t(#&uV_H5V0*;275N17J;ZI{*Lx literal 0 HcmV?d00001 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