From a5f45f232decad2e74bfdf476255604273fd95fd Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 23 Jul 2016 10:37:41 -0400 Subject: [PATCH] 2.7: Detect "continue" inside except Fixes issue #38. This is a bit hacky. We need a more general "continue" detection. --- test/bytecode_2.7/05_for_try_except.pyc | Bin 0 -> 210 bytes test/simple_source/bug27+/05_for_try_except.py | 11 +++++++++++ uncompyle6/scanners/scanner2.py | 14 +++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/bytecode_2.7/05_for_try_except.pyc create mode 100644 test/simple_source/bug27+/05_for_try_except.py diff --git a/test/bytecode_2.7/05_for_try_except.pyc b/test/bytecode_2.7/05_for_try_except.pyc new file mode 100644 index 0000000000000000000000000000000000000000..decefe6724c23e3a8b6c82e5da7984d04edfeab0 GIT binary patch literal 210 zcmYL?O$x$L41_1vg%&Jc!CghMqKF$27p~p7s0i|?Z7f3n?0W^f6Fh=P^#Z0M7&2eT zz$DhYXWNgLAL3VSnH!Ow3+`hu5EHhi0gi;)0k^<}CxQH%4I&asA4Glx>|K)F&b5T5 zBTy;}QdY_|eqb6u;mnnRKlD&meNBsmmCma&Wba(Xv*pN}F4QG2l__h*_mB%SDeCXt TRhmat!s~96Y##N=f+P9>d8;Q? literal 0 HcmV?d00001 diff --git a/test/simple_source/bug27+/05_for_try_except.py b/test/simple_source/bug27+/05_for_try_except.py new file mode 100644 index 00000000..f96bd16f --- /dev/null +++ b/test/simple_source/bug27+/05_for_try_except.py @@ -0,0 +1,11 @@ +# Issue #38 in Python 2.7 +# Problem is distinguishing 'continue' from 'jump_back' +# in assembly instructions. + +# Here, we hack looking for two jump backs +# followed by the end of the except. This +# is a big hack. + +for a in [__name__]: + try:len(a) + except:continue diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index 6b49dba2..28ead94a 100755 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -32,7 +32,7 @@ from xdis.bytecode import findlinestarts import uncompyle6.scanner as scan class Scanner2(scan.Scanner): - def __init__(self, version, show_asm=None): + def __init__(self, version, show_asm=None, is_pypy=False): scan.Scanner.__init__(self, version, show_asm) self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT]) self.jump_forward = frozenset([self.opc.JUMP_ABSOLUTE, self.opc.JUMP_FORWARD]) @@ -164,6 +164,18 @@ class Scanner2(scan.Scanner): elif op in self.opc.hasjrel: pattr = repr(offset + 3 + oparg) elif op in self.opc.hasjabs: + if self.version == 2.7 and op == self.opc.JUMP_ABSOLUTE: + target = self.get_target(offset) + # 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') pattr = repr(oparg) elif op in self.opc.haslocal: pattr = varnames[oparg]