From 90ac8a463dc2024b2e6b95dc60707d4b6dd9f42f Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 20 Mar 2018 11:33:10 -0400 Subject: [PATCH] Adjust 3.x while1else reduction check --- test/bytecode_3.4/05_while1_if_continue.pyc | Bin 607 -> 812 bytes .../bug34/05_while1_if_continue.py | 10 ++++++++++ uncompyle6/parsers/parse3.py | 4 ++-- uncompyle6/parsers/parse34.py | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/bytecode_3.4/05_while1_if_continue.pyc b/test/bytecode_3.4/05_while1_if_continue.pyc index 5e6785a4a1de1d9a3021ceeaefa6368f957f46a1..7698bb28313b49e08368e48deb89d4efa831affd 100644 GIT binary patch delta 300 zcmcc5vW89h9S<*;g4)KYZA=Udj~S2vkk8-%#KqAQmHh?T8B#bHS{N9jm>E)-7=kr9 zHu2tV|3Hj~S2vkk8-%#Kry-mHmOT!J6zFo98n!X);f~$0R-Z RACnRn8&H~uSAtQR2>?854cY(z diff --git a/test/simple_source/bug34/05_while1_if_continue.py b/test/simple_source/bug34/05_while1_if_continue.py index 9111a083..e514165a 100644 --- a/test/simple_source/bug34/05_while1_if_continue.py +++ b/test/simple_source/bug34/05_while1_if_continue.py @@ -25,3 +25,13 @@ def readline2(self): continue return line + self[0] + +# From 3.4.4 connection.py +def PipeClient(address): + while 1: + try: + address += 1 + except OSError as e: + raise e + else: + raise diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index a20e671e..67cb856b 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1090,7 +1090,7 @@ class Python3Parser(PythonParser): if tokens[last] in ('JUMP_BACK', 'CONTINUE'): # These indicate inside a loop, but token[last] # should not be in a loop. - # FIXME: Not quite righte: refine by using target + # FIXME: Not quite right: refine by using target return True # if SETUP_LOOP target spans the else part, then this is @@ -1100,7 +1100,7 @@ class Python3Parser(PythonParser): last += 1 if last == n: return False - return tokens[first].attr >= tokens[last].offset + return tokens[first].attr > tokens[last].offset elif lhs == 'while1stmt': # If there is a fall through to the COME_FROM_LOOP. then this is diff --git a/uncompyle6/parsers/parse34.py b/uncompyle6/parsers/parse34.py index eca7cff1..43d814c8 100644 --- a/uncompyle6/parsers/parse34.py +++ b/uncompyle6/parsers/parse34.py @@ -42,6 +42,9 @@ class Python34Parser(Python33Parser): whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK else_suitel COME_FROM + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK else_suitel + COME_FROM_LOOP + # Python 3.4+ optimizes the trailing two JUMPS away # Is this 3.4 only?