Fix 2.6 IF/THEN misclassification..

with an exception condition
This commit is contained in:
rocky
2018-01-13 00:58:16 -05:00
parent 70ddd71c0e
commit 185ec4e306
3 changed files with 25 additions and 8 deletions

View File

@@ -12,3 +12,14 @@ def test_specific_values(self):
self = 2 self = 2
self = 3 self = 3
# From 2.6 test_decorators.
# Bug was thinking an "except" was some sort of if/then
def call(*args):
try:
return 5
except KeyError:
return 2
except TypeError:
# Unhashable argument
return 3

View File

@@ -894,7 +894,6 @@ class Scanner2(Scanner):
self.structs.append({'type': 'if-then', self.structs.append({'type': 'if-then',
'start': start-3, 'start': start-3,
'end': pre_rtarget}) 'end': pre_rtarget})
self.thens[start] = end self.thens[start] = end
elif jump_op == 'JUMP_ABSOLUTE': elif jump_op == 'JUMP_ABSOLUTE':
if_then_maybe = {'type': 'if-then', if_then_maybe = {'type': 'if-then',
@@ -937,13 +936,20 @@ class Scanner2(Scanner):
'end': end}) 'end': end})
elif code_pre_rtarget == self.opc.RETURN_VALUE: elif code_pre_rtarget == self.opc.RETURN_VALUE:
if self.version == 2.7 or pre_rtarget not in self.ignore_if: if self.version == 2.7 or pre_rtarget not in self.ignore_if:
self.structs.append({'type': 'if-then', # 10 is exception-match. If there is an exception match in the
'start': start, # compare, then this is an exception clause not an if-then clause
'end': rtarget}) if (self.code[self.prev[offset]] != self.opc.COMPARE_OP or
self.thens[start] = rtarget self.code[self.prev[offset]+1] != 10):
if self.version == 2.7 or code[pre_rtarget+1] != self.opc.JUMP_FORWARD: self.structs.append({'type': 'if-then',
self.fixed_jumps[offset] = rtarget 'start': start,
self.return_end_ifs.add(pre_rtarget) 'end': rtarget})
self.thens[start] = rtarget
if self.version == 2.7 or code[pre_rtarget+1] != self.opc.JUMP_FORWARD:
self.fixed_jumps[offset] = rtarget
self.return_end_ifs.add(pre_rtarget)
pass
pass
pass
elif op in self.pop_jump_if_or_pop: elif op in self.pop_jump_if_or_pop:
target = self.get_target(offset, op) target = self.get_target(offset, op)