diff -r 456c58fc64b0 -r d0d6e4ad31bd DebugClients/Python/coverage/bytecode.py --- a/DebugClients/Python/coverage/bytecode.py Sun Oct 04 13:35:09 2015 +0200 +++ b/DebugClients/Python/coverage/bytecode.py Sun Oct 04 22:37:56 2015 +0200 @@ -1,8 +1,13 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + """Bytecode manipulation for coverage.py""" -import opcode, types +import opcode +import types -from .backward import byte_to_int +from coverage.backward import byte_to_int + class ByteCode(object): """A single bytecode.""" @@ -26,10 +31,12 @@ class ByteCodes(object): """Iterator over byte codes in `code`. + This handles the logic of EXTENDED_ARG byte codes internally. Those byte + codes are not returned by this iterator. + Returns `ByteCode` objects. """ - # pylint: disable=R0924 def __init__(self, code): self.code = code @@ -38,6 +45,7 @@ def __iter__(self): offset = 0 + ext_arg = 0 while offset < len(self.code): bc = ByteCode() bc.op = self[offset] @@ -45,7 +53,7 @@ next_offset = offset+1 if bc.op >= opcode.HAVE_ARGUMENT: - bc.arg = self[offset+1] + 256*self[offset+2] + bc.arg = ext_arg + self[offset+1] + 256*self[offset+2] next_offset += 2 label = -1 @@ -56,7 +64,11 @@ bc.jump_to = label bc.next_offset = offset = next_offset - yield bc + if bc.op == opcode.EXTENDED_ARG: + ext_arg = bc.arg * 256*256 + else: + ext_arg = 0 + yield bc class CodeObjects(object): @@ -73,6 +85,3 @@ if isinstance(c, types.CodeType): self.stack.append(c) yield code - -# -# eflag: FileType = Python2