From 535df1592e2de27b9bcae9dc5e101f9f704b4aaf Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 31 Mar 2018 19:28:35 -0400 Subject: [PATCH] Another 3.6 control-flow bug... and add source to some previous bytecode tests --- test/bytecode_3.6/05-for-ifelse.pyc | Bin 0 -> 325 bytes .../simple_source/bug25/04_try_except_else.py | 18 ++++++++++++++++++ test/simple_source/bug35/06_try_return.py | 12 ++++++++++++ test/simple_source/bug36/05-for-ifelse.py | 13 +++++++++++++ .../exception/04_assert_continue.py | 16 ++++++++++++++++ uncompyle6/parsers/parse36.py | 3 +++ 6 files changed, 62 insertions(+) create mode 100644 test/bytecode_3.6/05-for-ifelse.pyc create mode 100644 test/simple_source/bug25/04_try_except_else.py create mode 100644 test/simple_source/bug35/06_try_return.py create mode 100644 test/simple_source/bug36/05-for-ifelse.py create mode 100644 test/simple_source/exception/04_assert_continue.py diff --git a/test/bytecode_3.6/05-for-ifelse.pyc b/test/bytecode_3.6/05-for-ifelse.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a6372a706bd28c2aa112c6a54c3605dc71a9edaf GIT binary patch literal 325 zcmYjLJxc>Y5S`ikNH~p%l|R7diWnhyl?1`mX)FQ(InL~^9B#aGmy;7VmHrujfo*=r zwpRWHD`!_kXLxTOGw|L_N2Bchc(*DM-~;{@BYjCQ`$QZ#zQPJPyM{bkC$#c4AVh>K zf|(QbGmCS$DYi*}WErV!n_7GUgvY}r*hm)^2`R_>m}VR<>F-=p4*9dirw@38eBfdu zlypqC4l9>DRjLyXrHfVlAY9sNA?sfIR|9>Wn0nJHQJSXHYcaX)?xw}$?0hU6J+7rt uMx3_KE-AIBxX&;LM1Wc7AyPBFN1H{CVg6bFsElrIc(G}Cr^GBcc!O`G#Y1TT literal 0 HcmV?d00001 diff --git a/test/simple_source/bug25/04_try_except_else.py b/test/simple_source/bug25/04_try_except_else.py new file mode 100644 index 00000000..f4fedffb --- /dev/null +++ b/test/simple_source/bug25/04_try_except_else.py @@ -0,0 +1,18 @@ +# Bug found in 2.4 test_math.py +# Bug was turning last try/except/else into try/else +import math +def test_exceptions(): + try: + x = math.exp(-1000000000) + except: + raise RuntimeError + + x = 1 + try: + x = math.sqrt(-1.0) + except ValueError: + return x + else: + raise RuntimeError + +test_exceptions() diff --git a/test/simple_source/bug35/06_try_return.py b/test/simple_source/bug35/06_try_return.py new file mode 100644 index 00000000..984e225b --- /dev/null +++ b/test/simple_source/bug35/06_try_return.py @@ -0,0 +1,12 @@ +# From 3.6.4 pdb.py +# Bug was not having a semantic action for "except_return" tree +def do_commands(self, arg): + if not arg: + bnum = 1 + else: + try: + bnum = int(arg) + except: + self.error("Usage:") + return + self.commands_bnum = bnum diff --git a/test/simple_source/bug36/05-for-ifelse.py b/test/simple_source/bug36/05-for-ifelse.py new file mode 100644 index 00000000..b8d7894c --- /dev/null +++ b/test/simple_source/bug36/05-for-ifelse.py @@ -0,0 +1,13 @@ +# From 3.6.4 configparser.py +# Bug in 3.6 was handling "else" with compound +# if. there is no POP_BLOCK and +# there are several COME_FROMs before the else +def _read(self, fp, a, value, f): + for line in fp: + for prefix in a: + fp() + if (value and fp and + prefix > 5): + f() + else: + f() diff --git a/test/simple_source/exception/04_assert_continue.py b/test/simple_source/exception/04_assert_continue.py new file mode 100644 index 00000000..d75f2afc --- /dev/null +++ b/test/simple_source/exception/04_assert_continue.py @@ -0,0 +1,16 @@ +# Adapted from Python 3.3 idlelib/PyParse.py +# Bug is continue flowing back to while messing up the determination +# that it is inside an "if". + +# RUNNABLE! +def _study1(i, n, ch): + while i == 3: + i = 4 + if ch: + i = 10 + assert i < 5 + continue + if n: + return n + +assert _study1(3, 4, False) == 4 diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index dde2b0aa..254fd929 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -61,6 +61,9 @@ class Python36Parser(Python35Parser): except_suite ::= c_stmts_opt COME_FROM POP_EXCEPT jump_except COME_FROM + jb_cfs ::= JUMP_BACK come_froms + ifelsestmtl ::= testexpr c_stmts_opt jb_cfs else_suitel + # In 3.6+, A sequence of statements ending in a RETURN can cause # JUMP_FORWARD END_FINALLY to be omitted from try middle