co_lnotab supports negative line number delta

Issue #26107: The format of the co_lnotab attribute of code objects changes to
support negative line number delta.

Changes:

* assemble_lnotab(): if line number delta is less than -128 or greater than
  127, emit multiple (offset_delta, lineno_delta) in co_lnotab
* update functions decoding co_lnotab to use signed 8-bit integers

  - dis.findlinestarts()
  - PyCode_Addr2Line()
  - _PyCode_CheckLineNumber()
  - frame_setlineno()

* update lnotab_notes.txt
* increase importlib MAGIC_NUMBER to 3361
* document the change in What's New in Python 3.6
* cleanup also PyCode_Optimize() to use better variable names
This commit is contained in:
Victor Stinner 2016-01-20 12:16:21 +01:00
parent 316fcc867b
commit f3914eb16d
11 changed files with 203 additions and 161 deletions

View file

@ -397,8 +397,8 @@ def findlinestarts(code):
Generate pairs (offset, lineno) as described in Python/compile.c.
"""
byte_increments = list(code.co_lnotab[0::2])
line_increments = list(code.co_lnotab[1::2])
byte_increments = code.co_lnotab[0::2]
line_increments = code.co_lnotab[1::2]
lastlineno = None
lineno = code.co_firstlineno
@ -409,6 +409,9 @@ def findlinestarts(code):
yield (addr, lineno)
lastlineno = lineno
addr += byte_incr
if line_incr >= 0x80:
# line_increments is an array of 8-bit signed integers
line_incr -= 0x100
lineno += line_incr
if lineno != lastlineno:
yield (addr, lineno)