You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Use get_inst and self.insts more..
needed more in 3.6 to handle EXTENDED_ARGS before JUMP_xxx
This commit is contained in:
BIN
test/bytecode_3.6/09_ext_arg_jump.pyc
Normal file
BIN
test/bytecode_3.6/09_ext_arg_jump.pyc
Normal file
Binary file not shown.
37
test/simple_source/bug36/09_ext_arg_jump.py
Normal file
37
test/simple_source/bug36/09_ext_arg_jump.py
Normal 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
|
@@ -102,12 +102,15 @@ class Scanner(object):
|
|||||||
That is, it is ether "JUMP_FORWARD" or an absolute jump that
|
That is, it is ether "JUMP_FORWARD" or an absolute jump that
|
||||||
goes forward.
|
goes forward.
|
||||||
"""
|
"""
|
||||||
if self.code[offset] == self.opc.JUMP_FORWARD:
|
opname = self.get_inst(offset).opname
|
||||||
|
if opname == 'JUMP_FORWARD':
|
||||||
return True
|
return True
|
||||||
if self.code[offset] != self.opc.JUMP_ABSOLUTE:
|
if opname != 'JUMP_ABSOLUTE':
|
||||||
return False
|
return False
|
||||||
# FIXME 0 isn't always correct
|
return offset < self.get_target(offset)
|
||||||
return offset < self.get_target(offset, 0)
|
|
||||||
|
def prev_offset(self, offset):
|
||||||
|
return self.insts[self.offset2inst_index[offset]-1].offset
|
||||||
|
|
||||||
def get_inst(self, offset):
|
def get_inst(self, offset):
|
||||||
# Instructions can get moved as a result of EXTENDED_ARGS removal.
|
# Instructions can get moved as a result of EXTENDED_ARGS removal.
|
||||||
|
Reference in New Issue
Block a user