From c6e20e44449c632b437db46fd636f3ec198ca6d6 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 11 Jan 2018 21:52:33 -0500 Subject: [PATCH 1/4] Fix whileelse bug --- test/bytecode_2.6/03_whileelse_bug.pyc | Bin 0 -> 350 bytes test/bytecode_2.7/03_whileelse_bug.pyc | Bin 0 -> 340 bytes test/bytecode_3.3/03_whileelse_bug.pyc | Bin 0 -> 374 bytes test/bytecode_3.4/03_whileelse_bug.pyc | Bin 0 -> 289 bytes test/simple_source/looping/03_whileelse_bug.py | 9 +++++++++ uncompyle6/parsers/parse26.py | 4 ++-- uncompyle6/parsers/parse27.py | 4 ++-- uncompyle6/parsers/parse3.py | 4 ++-- uncompyle6/parsers/parse34.py | 4 ++-- 9 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 test/bytecode_2.6/03_whileelse_bug.pyc create mode 100644 test/bytecode_2.7/03_whileelse_bug.pyc create mode 100644 test/bytecode_3.3/03_whileelse_bug.pyc create mode 100644 test/bytecode_3.4/03_whileelse_bug.pyc create mode 100644 test/simple_source/looping/03_whileelse_bug.py diff --git a/test/bytecode_2.6/03_whileelse_bug.pyc b/test/bytecode_2.6/03_whileelse_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3e455931a4504562099aee98a96328876b26b59a GIT binary patch literal 350 zcmb79OA5j;6r8k+ic&8jLUrMHC5Q;_UFf3VreGU15KT2LD(KD&dJ@4C_+AuT8<@#t z-e<_;6;_+ic$MON1l?1D4T&<~4y;HBEF+Jcl!?K8GlCrvod>uArVVj!I8}w9ksELb zA!4qv<2lENI1pl5zKndDo+~0K-WaiRK?OgR_C>2r{+6G8Y09BN)5<`L&C_(#7Kr~Ztp(1!8OWTlo9 Imql;90c7|;IRF3v literal 0 HcmV?d00001 diff --git a/test/bytecode_2.7/03_whileelse_bug.pyc b/test/bytecode_2.7/03_whileelse_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c11ec887b3a39dba82598d56c55440bd5d2bdcc9 GIT binary patch literal 340 zcmb79y9&ZE6g_RgN3mbv;3QNKAGnGL?hbY+bSc;d4MbZ_ixqV9e;xb*?~Q`93HRjO z*EvMIe6RnE;uPQG(7U8CK0yXNfS8DbFmS1oGH~$Rio(nY>LG5xd4#%WNtYMyz^Q|X z8v>bYbAgjUM6zKZXm70upjazlW-UrimBr(y$}KZsP=`Xx#N^dEm1CXfg*xuWlUZ`v zD=noqGTBzUQE@GsG@Y2T%C1v3G9Ce(HeJtcIO~8tHvEsDgJpl(v`Aro$g@hzh4rBv EZ(IC6WB>pF literal 0 HcmV?d00001 diff --git a/test/bytecode_3.3/03_whileelse_bug.pyc b/test/bytecode_3.3/03_whileelse_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ff461caf7e9357ce1f4e2ba01767725a2a88c968 GIT binary patch literal 374 zcmb78%L>9U5Zt!lqbPXy;7O<;R_Rql@b1M!!Arq5)Ie;jF<3!weusbJH~9!yNROdH9?XyiX{}{oDCA)X2T3r4OaSqjK`0z(G|)J|mq48iFF^*a zWYA=~#h7`EF%PH|te%14mu7KhZb43Jd~tqhQF5w&PJVttW?s6!fpL6!MrKZGYEE%# zd{Sw;UP0w8_W0tG(v(U=kmh18Ai==M34~lsY>Y+hK%So_ghrSSVX*<_ZgJS;=BJeA Lq}qXXgERvGBAqp- literal 0 HcmV?d00001 diff --git a/test/simple_source/looping/03_whileelse_bug.py b/test/simple_source/looping/03_whileelse_bug.py new file mode 100644 index 00000000..ce741792 --- /dev/null +++ b/test/simple_source/looping/03_whileelse_bug.py @@ -0,0 +1,9 @@ +# From idlelib/PyParse.py +# Bug is "if" inside a nested while/else. +def _study1(i, n): + while i: + while i: + i = 0 + else: + if i: + i = 1 diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index ec204646..47bc42b1 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -142,8 +142,8 @@ class Python26Parser(Python2Parser): whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK - else_suite COME_FROM - while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM + else_suitel COME_FROM + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suitel COME_FROM return ::= ret_expr RETURN_END_IF POP_TOP return ::= ret_expr RETURN_VALUE POP_TOP diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index adbc2195..8393432f 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -120,9 +120,9 @@ class Python27Parser(Python2Parser): while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK _come_froms while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK - else_suite COME_FROM + else_suitel COME_FROM whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK - else_suite COME_FROM + else_suitel COME_FROM ifstmt ::= testexpr return_if_stmts COME_FROM ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite COME_FROM diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 14cd7360..a32d09f5 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -347,10 +347,10 @@ class Python3Parser(PythonParser): COME_FROM_LOOP while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK - else_suite + else_suitel whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK - else_suite COME_FROM_LOOP + else_suitel COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM_LOOP diff --git a/uncompyle6/parsers/parse34.py b/uncompyle6/parsers/parse34.py index 4e98721c..e1259a9a 100644 --- a/uncompyle6/parsers/parse34.py +++ b/uncompyle6/parsers/parse34.py @@ -19,9 +19,9 @@ class Python34Parser(Python33Parser): # FIXME the below masks a bug in not detecting COME_FROM_LOOP - # grammar rules with COME_FROM -> COME_FROM_LOOP alreadly exist + # grammar rules with COME_FROM -> COME_FROM_LOOP already exist whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK - else_suite COME_FROM + else_suitel COME_FROM # Python 3.4+ optimizes the trailing two JUMPS away From c4f12e9b22612899acf48f733b22f50e2ff929d7 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 11 Jan 2018 22:00:12 -0500 Subject: [PATCH 2/4] 2.4 whileelse test --- test/bytecode_2.4/03_whileelse_bug.pyc | Bin 0 -> 312 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/bytecode_2.4/03_whileelse_bug.pyc diff --git a/test/bytecode_2.4/03_whileelse_bug.pyc b/test/bytecode_2.4/03_whileelse_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..41534234f18a0f7290559b505f86c499f4358080 GIT binary patch literal 312 zcmYk1zYc;h5XQg4K!U-Sa6t$EPEMM*GvI(>ArTsFf`S&JCc60)KBiCL-RWSH@7J$) z*Sq%c4*XYdljis>Mf;Lu1402jfs~BGI&>(KGgw@=BH20NI>jBR22j_YI3J3xJb+UG zm2i$DjznCj6DgtQ>(Hg!ks-iv$B@x5jEsxPeb2{`t)S_Xv*u8jI`ke4X?3=3cfNfn<9I5Pu`y@=9GA(wnExw}T1W#< Fd;s}?ED`_! literal 0 HcmV?d00001 From a0d10c2d4c7803db1333a6e409e153e43e5a6e05 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 12 Jan 2018 09:47:32 -0500 Subject: [PATCH 3/4] Improve test framework... test_pyenvlib.py: get list of python versions from xdis main.py: bump okay_files appropriately when --verify is off --- test/test_pyenvlib.py | 21 ++++++++++++--------- uncompyle6/main.py | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test_pyenvlib.py b/test/test_pyenvlib.py index 2c0284c9..206141aa 100755 --- a/test/test_pyenvlib.py +++ b/test/test_pyenvlib.py @@ -21,22 +21,25 @@ Step 2: Run the test: from __future__ import print_function -from uncompyle6 import main, PYTHON3 -import os, time, shutil, sys +import os, time, re, shutil, sys from fnmatch import fnmatch +from uncompyle6 import main, PYTHON3 +import xdis.magics as magics + #----- configure this for your needs +python_versions = [v for v in magics.python_versions if + re.match('^[0-9.]+$', v)] + +# FIXME: we should remove Python versions that we don't support. +# These include Jython, and Python bytecode changes pre release. + TEST_VERSIONS=( 'pypy-2.4.0', 'pypy-2.6.1', 'pypy-5.0.1', 'pypy-5.3.1', 'pypy3.5-5.7.1-beta', - # FIXME: get this from xdis magics. - '2.3.7', '2.4.6', '2.5.6', '2.6.9', - '2.7.10', '2.7.11', '2.7.12', '2.7.13', '2.7.14', - '3.0.1', '3.1.5', '3.2.6', - '3.3.5', '3.3.6', '3.3.7', - '3.4.2', '3.5.3', '3.6.0', '3.6.3', '3.6.4', - 'native') + 'native') + tuple(python_versions) + target_base = '/tmp/py-dis/' lib_prefix = os.path.join(os.environ['HOME'], '.pyenv/versions') diff --git a/uncompyle6/main.py b/uncompyle6/main.py index 141eefce..2695ae21 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -196,6 +196,9 @@ def main(in_base, out_base, files, codes, outfile=None, raise pass pass + pass + else: + okay_files += 1 pass elif do_verify: sys.stderr.write("\n### uncompile successful, but no file to compare against\n") From a60104517d21df25e5650fb22b498ef61d28bde8 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 12 Jan 2018 10:00:26 -0500 Subject: [PATCH 4/4] Fix ok status on --weak-verify --- uncompyle6/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uncompyle6/main.py b/uncompyle6/main.py index 2695ae21..a624d0f4 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -185,6 +185,10 @@ def main(in_base, out_base, files, codes, outfile=None, okay_files += 1 else: print('\n# %s\n\t%s', infile, msg) + pass + else: + okay_files += 1 + pass except verify.VerifyCmpError as e: print(e) verify_failed_files += 1