mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
bpo-38115: Deal with invalid bytecode offsets in lnotab (GH-16079)
Document that lnotab can contain invalid bytecode offsets (because of terrible reasons that are difficult to fix). Make dis.findlinestarts() ignore invalid offsets in lnotab. All other uses of lnotab in CPython (various reimplementations of addr2line or line2addr in Python, C and gdb) already ignore this, because they take an address to look for, instead. Add tests for the result of dis.findlinestarts() on wacky constructs in test_peepholer.py, because it's the easiest place to add them.
This commit is contained in:
parent
7774d7831e
commit
c8165036f3
4 changed files with 77 additions and 2 deletions
|
@ -454,6 +454,7 @@ def findlinestarts(code):
|
|||
"""
|
||||
byte_increments = code.co_lnotab[0::2]
|
||||
line_increments = code.co_lnotab[1::2]
|
||||
bytecode_len = len(code.co_code)
|
||||
|
||||
lastlineno = None
|
||||
lineno = code.co_firstlineno
|
||||
|
@ -464,6 +465,10 @@ def findlinestarts(code):
|
|||
yield (addr, lineno)
|
||||
lastlineno = lineno
|
||||
addr += byte_incr
|
||||
if addr >= bytecode_len:
|
||||
# The rest of the lnotab byte offsets are past the end of
|
||||
# the bytecode, so the lines were optimized away.
|
||||
return
|
||||
if line_incr >= 0x80:
|
||||
# line_increments is an array of 8-bit signed integers
|
||||
line_incr -= 0x100
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue