From fe46015b7875a49f2351e3fb058be5e9c8ae950a Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 27 Sep 2016 04:02:27 -0400 Subject: [PATCH] PY3 COME_FROM_LOOP bug There are still more in sre... --- test/Makefile | 4 ++-- test/bytecode_3.4/04_while1_while1.pyc | Bin 0 -> 200 bytes test/simple_source/looping/04_while1_while1.py | 9 +++++++++ uncompyle6/parser.py | 16 ++++------------ uncompyle6/parsers/parse2.py | 6 +++++- uncompyle6/parsers/parse3.py | 12 +++++++++--- uncompyle6/scanners/scanner3.py | 12 ++++-------- 7 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 test/bytecode_3.4/04_while1_while1.pyc create mode 100644 test/simple_source/looping/04_while1_while1.py diff --git a/test/Makefile b/test/Makefile index 073633ce..d033dc02 100644 --- a/test/Makefile +++ b/test/Makefile @@ -32,11 +32,11 @@ check-3.2: check-bytecode #: Run working tests from Python 3.3 check-3.3: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.3 --verify $(COMPILE) + $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify $(COMPILE) #: Run working tests from Python 3.4 check-3.4: check-bytecode check-3.4-ok check-2.7-ok - $(PYTHON) test_pythonlib.py --bytecode-3.4 --verify $(COMPILE) + $(PYTHON) test_pythonlib.py --bytecode-3.4 --weak-verify $(COMPILE) #: Run working tests from Python 3.5 check-3.5: check-bytecode diff --git a/test/bytecode_3.4/04_while1_while1.pyc b/test/bytecode_3.4/04_while1_while1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dcfbc4e6c2ed2d5dec8c142f43ea0e8e47fea95e GIT binary patch literal 200 zcmaFI!^_2K_$qt{0|UcjAcg}*Aj<)Wi}is-g$6?^14EG#Lxl{OA;u7p$H0)v$k4>d zP{_kj$P8mMGo&yu1Zy(-X)@j7h>uUp%t?)pzr_<&npcvUo9bFrlwY)xp@(^b literal 0 HcmV?d00001 diff --git a/test/simple_source/looping/04_while1_while1.py b/test/simple_source/looping/04_while1_while1.py new file mode 100644 index 00000000..849bf110 --- /dev/null +++ b/test/simple_source/looping/04_while1_while1.py @@ -0,0 +1,9 @@ +# From python 3.4 sre.pyc +while 1: + if __file__: + while 1: + if __file__: + break + raise RuntimeError + else: + raise RuntimeError diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 90e0118f..40bf49b8 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -311,20 +311,12 @@ class PythonParser(GenericASTBuilder): def p_whilestmt(self, args): """ - whilestmt ::= SETUP_LOOP - testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK _come_from + whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK + POP_BLOCK _come_from - whilestmt ::= SETUP_LOOP - testexpr - return_stmts - POP_BLOCK COME_FROM + whilestmt ::= SETUP_LOOP testexpr return_stmts + POP_BLOCK COME_FROM - while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM - while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM - - while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 0af84025..0e6970b7 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -42,7 +42,11 @@ class Python2Parser(PythonParser): def p_stmt2(self, args): """ - while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM + while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM + + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT exec_stmt ::= expr exprlist EXEC_STMT diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 7db37341..f752d775 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -306,15 +306,21 @@ class Python3Parser(PythonParser): whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK else_suite COME_FROM_LOOP + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK + else_suite COME_FROM_LOOP + whileelselaststmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK else_suitec COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM_LOOP # Python < 3.5 no POP BLOCK - whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP - whileTruestmt ::= SETUP_LOOP return_stmts COME_FROM_LOOP - while1stmt ::= SETUP_LOOP l_stmts _come_from JUMP_BACK COME_FROM_LOOP + whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK + COME_FROM_LOOP + whileTruestmt ::= SETUP_LOOP return_stmts + COME_FROM_LOOP + + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM_LOOP # FIXME: investigate - can code really produce a NOP? whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 1c379562..1fd7a04a 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -206,14 +206,10 @@ class Scanner3(Scanner): # "loop" tag last so the grammar rule matches that properly. for jump_offset in sorted(jump_targets[inst.offset], reverse=True): come_from_name = 'COME_FROM' - if (inst.offset in offset_action): - action = offset_action[inst.offset] - if (action.type == 'end' - and (self.opName(jump_offset)[len('SETUP_'):] - == action.name)): - come_from_name = '%s_%s' % ( - (come_from_name, action.name)) - pass + opname = self.opName(jump_offset) + if opname.startswith('SETUP_'): + come_from_type = opname[len('SETUP_'):] + come_from_name = 'COME_FROM_%s' % come_from_type pass tokens.append(Token(come_from_name, None, repr(jump_offset),