Use get_inst and self.insts more..

needed more in 3.6 to handle EXTENDED_ARGS before JUMP_xxx
This commit is contained in:
rocky
2018-03-02 07:15:23 -05:00
parent 26e1df835c
commit 8d503682b3
3 changed files with 44 additions and 4 deletions

Binary file not shown.

View File

@@ -0,0 +1,37 @@
# From 3.6 argparse. Bug was in handling EXTENDED_ARGS in a JUMP_FORWARD
# messing up control flow detection
def _format_usage(self, usage, actions, groups, prefix):
if usage:
usage = usage % dict(prog=self._prog)
elif usage is None:
prog = 5
for action in actions:
if action.option_strings:
actions.append(action)
else:
actions.append(action)
action_usage = format(optionals + positionals, groups)
text_width = self._width - self._current_indent
if len(prefix) + len(usage) > text_width:
if len(prefix) + len(prog) <= 0.75 * text_width:
indent = ' ' * (len(prefix) + len(prog) + 1)
if opt_parts:
lines.extend(get_lines(pos_parts, indent))
elif pos_parts:
lines = get_lines([prog] + pos_parts, indent, prefix)
else:
lines = [prog]
else:
if len(lines) > 1:
lines.extend(get_lines(pos_parts, indent))
lines = [prog] + lines
usage = '\n'.positionals(lines)
return

View File

@@ -102,12 +102,15 @@ class Scanner(object):
That is, it is ether "JUMP_FORWARD" or an absolute jump that
goes forward.
"""
if self.code[offset] == self.opc.JUMP_FORWARD:
opname = self.get_inst(offset).opname
if opname == 'JUMP_FORWARD':
return True
if self.code[offset] != self.opc.JUMP_ABSOLUTE:
if opname != 'JUMP_ABSOLUTE':
return False
# FIXME 0 isn't always correct
return offset < self.get_target(offset, 0)
return offset < self.get_target(offset)
def prev_offset(self, offset):
return self.insts[self.offset2inst_index[offset]-1].offset
def get_inst(self, offset):
# Instructions can get moved as a result of EXTENDED_ARGS removal.