From 75c718bc5c313a514662107a7c02a593d06b8df2 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 3 Sep 2016 09:56:41 -0400 Subject: [PATCH] Python 2.2..2.6 bug in a == b == c == d Fix was to remove some come froms. Feels a little hacky though. --- test/bytecode_2.6/08_triple_equals.pyc | Bin 0 -> 249 bytes test/simple_source/bug26/08_triple_equals.py | 7 +++++++ uncompyle6/scanners/scanner2.py | 18 +++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 test/bytecode_2.6/08_triple_equals.pyc create mode 100644 test/simple_source/bug26/08_triple_equals.py diff --git a/test/bytecode_2.6/08_triple_equals.pyc b/test/bytecode_2.6/08_triple_equals.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b4276d2d8f6604d2848291ef3d1a295cef88cae9 GIT binary patch literal 249 zcmcckiI+?9+Ntnl1}I<#(hfjeYzHJ#frycTg*l6fAzzGvF_j6*=3-z>VPF7?<}ooa zG3JA~j0{oC40-H8788h-!psn?!2&cQ6NnkoK?De-&zcDWAMO3Xk|nG_vDAu!{Jau2 zAS)v?H!-gS%*@FLGZ}%RX&OL+0YMb21G&YSxdl0?@x}S2Mail9Nu}vVX8Hye@g+r> kAmP-)(!`u%y@JXT4xn0_-29Z%oK!oIbBaNP79$rE05g6u3;+NC literal 0 HcmV?d00001 diff --git a/test/simple_source/bug26/08_triple_equals.py b/test/simple_source/bug26/08_triple_equals.py new file mode 100644 index 00000000..b269ce30 --- /dev/null +++ b/test/simple_source/bug26/08_triple_equals.py @@ -0,0 +1,7 @@ +# From Python 2.6 aifc.py +# Bug was handling triple == +# Fixed by removing some COME_FROMs inside +if expon == himant == lomant == 0: + f = 0.0 +else: + f = 1.1 diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index f1496d6c..3c2a8521 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -642,16 +642,17 @@ class Scanner2(scan.Scanner): self.fixed_jumps[i] = i+1 elif op in self.pop_jump_if: - start = pos+3 target = self.get_target(pos, op) rtarget = self.restrict_to_parent(target, parent) - pre = self.prev # Do not let jump to go out of parent struct bounds if target != rtarget and parent['type'] == 'and/or': self.fixed_jumps[pos] = rtarget return + start = pos+3 + pre = self.prev + # Does this jump to right after another conditional jump that is # not myself? If so, it's part of a larger conditional. # rocky: if we have a conditional jump to the next instruction, then @@ -673,13 +674,11 @@ class Scanner2(scan.Scanner): # Is it an "and" inside an "if" or "while" block if op == self.opc.PJIF: + # Search for other POP_JUMP_IF_FALSE targetting the same op, # in current statement, starting from current offset, and filter # everything inside inner 'or' jumps and midline ifs match = self.rem_or(start, self.next_stmt[pos], self.opc.PJIF, target) - ## We can't remove mid-line ifs because line structures have changed - ## from restructBytecode(). - ## match = self.remove_mid_line_ifs(match) # If we still have any offsets in set, start working on it if match: @@ -714,9 +713,12 @@ class Scanner2(scan.Scanner): self.fixed_jumps[pos] = fix or match[-1] return else: - self.fixed_jumps[pos] = match[-1] + if self.version < 2.7 and parent['type'] == 'root': + self.fixed_jumps[pos] = rtarget + else: + self.fixed_jumps[pos] = match[-1] return - else: # op == self.opc.PJIT + else: # op != self.opc.PJIT if self.version < 2.7 and code[pos+3] == self.opc.POP_TOP: assert_pos = pos + 4 else: @@ -835,6 +837,8 @@ class Scanner2(scan.Scanner): self.opc.JUMP_IF_TRUE_OR_POP): if (oparg > offset): label = oparg + pass + pass if label is not None and label != -1: # In Python <= 2.6, the POP_TOP in: