From ca9888ace48c0c232f3c26b193e5d64e46d51feb Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 23 Jul 2016 17:29:05 -0400 Subject: [PATCH] Another 2.7 'continue' detection bug --- test/bytecode_2.7/05_for_try_except.pyc | Bin 210 -> 283 bytes .../simple_source/bug27+/05_for_try_except.py | 7 +++++++ uncompyle6/scanners/scanner2.py | 18 ++++++----------- uncompyle6/scanners/scanner27.py | 19 ++++++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/test/bytecode_2.7/05_for_try_except.pyc b/test/bytecode_2.7/05_for_try_except.pyc index decefe6724c23e3a8b6c82e5da7984d04edfeab0..c2e729f9f4c8220a18d19c7256371396403b2243 100644 GIT binary patch delta 141 zcmcb_IGahD`7a>G6Wcz8Tf#hn}rw3VrK*Z7w{EK delta 67 zcmbQubcs=#`7j1+K4BGfgxCf5y 2 and - tokens[-1].type == 'JUMP_BACK' and - self.code[offset+3] == self.opc.END_FINALLY): - tokens[-1].type = intern('CONTINUE') + # use instead: hasattr(self, 'patch_continue'): ? + if self.version == 2.7: + self.patch_continue(tokens, offset, op) pattr = repr(oparg) elif op in self.opc.haslocal: pattr = varnames[oparg] diff --git a/uncompyle6/scanners/scanner27.py b/uncompyle6/scanners/scanner27.py index 1f1d943e..af1320b4 100755 --- a/uncompyle6/scanners/scanner27.py +++ b/uncompyle6/scanners/scanner27.py @@ -12,6 +12,11 @@ from __future__ import print_function from uncompyle6.scanners.scanner2 import Scanner2 +from uncompyle6 import PYTHON3 +if PYTHON3: + import sys + intern = sys.intern + # bytecode verification, verify(), uses JUMP_OPs from here from xdis.opcodes import opcode_27 JUMP_OPs = opcode_27.JUMP_OPs @@ -76,6 +81,20 @@ class Scanner27(Scanner2): self.opc.JUMP_IF_TRUE_OR_POP]) return + + def patch_continue(self, tokens, offset, op): + if op in (self.opc.JUMP_FORWARD, self.opc.JUMP_ABSOLUTE): + # FIXME: this is a hack to catch stuff like: + # for ... + # try: ... + # except: continue + # the "continue" is not on a new line. + n = len(tokens) + if (n > 2 and + tokens[-1].type == 'JUMP_BACK' and + self.code[offset+3] == self.opc.END_FINALLY): + tokens[-1].type = intern('CONTINUE') + pass if __name__ == "__main__":