MatthieuDartiailh / bytecode

Python module to modify bytecode
https://bytecode.readthedocs.io/
MIT License
302 stars 38 forks source link

Why are extended line offsets -127 and 126, and not -128 and 127? #67

Closed RNavega closed 3 years ago

RNavega commented 4 years ago

Regarding this part here, emitting extended line offsets: https://github.com/vstinner/bytecode/blob/master/bytecode/concrete.py#L289-L295

But CPython uses -128 and 127 as the range, which is the (inclusive) range of a signed byte: https://github.com/python/cpython/blob/3.9/Python/compile.c#L5638-L5648

RNavega commented 4 years ago

The dis module too treats them as signed bytes:
https://github.com/python/cpython/blob/master/Lib/dis.py#L472-L474

MatthieuDartiailh commented 4 years ago

Thanks for your report. I do not think I ever touched this part of the codebase but it does sound like a bug. Would you mind putting together a PR ?