Skip to content

Commit 8165db4

Browse files
author
rocky
committed
bug fixes...
* decode_linotab() -> decode_lineno_tab_old to make it clear that this routine works for version before 3.10 * last instruction can be RERAISE or RASE_VARARGS in addition to RETURN_VALUE * Avoid using asm.code.to_native() for now, since there are bugs
1 parent 99cb83a commit 8165db4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

xasm/assemble.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,11 @@ def warn(mess: str):
451451
print("Warning: ", mess)
452452

453453

454-
def decode_lineno_tab(lnotab, first_lineno):
454+
def decode_lineno_tab_old(lnotab, first_lineno: int) -> dict:
455+
"""
456+
Uncompresses line number table for Python versions before
457+
3.10
458+
"""
455459
line_number, line_number_diff = first_lineno, 0
456460
offset, offset_diff = 0, 0
457461
uncompressed_lnotab = {}
@@ -477,15 +481,15 @@ def decode_lineno_tab(lnotab, first_lineno):
477481

478482
def is_code_ok(asm: Assembler) -> bool:
479483
"""
480-
Performs some sanity checks on code
484+
Performs some sanity checks on code.
481485
"""
482486

483487
is_valid: bool = True
484488

485489
code = asm.code
486490
last_instruction = code.instructions[-1]
487491
last_offset = last_instruction.offset
488-
if last_instruction.opname != "RETURN_VALUE":
492+
if last_instruction.opname not in ("RETURN_VALUE", "RERAISE", "RAISE_VARARGS"):
489493
warn(
490494
f"Last instruction of at offset {last_offset} of {code.co_name}"
491495
f' should be "RETURN_VALUE", is "{last_instruction.opname}"'
@@ -684,10 +688,10 @@ def create_code(asm: Assembler, label, backpatch):
684688
is_code_ok(asm)
685689

686690
# Stamp might be added here
687-
if asm.python_version[:2] == PYTHON_VERSION_TRIPLE[:2]:
688-
code = asm.code.to_native()
689-
else:
690-
code = asm.code.freeze()
691+
# if asm.python_version[:2] == PYTHON_VERSION_TRIPLE[:2]:
692+
# code = asm.code.to_native()
693+
# else:
694+
code = asm.code.freeze()
691695

692696
# asm.print_instructions()
693697

xasm/pyc_convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from xdis.opcodes import opcode_27, opcode_33
1515

1616
from xasm.assemble import (Assembler, Instruction, asm_file, create_code,
17-
decode_lineno_tab)
17+
decode_lineno_tab_old)
1818
from xasm.version import __version__
1919
from xasm.write_pyc import write_pycfile
2020

@@ -159,7 +159,7 @@ def transform_asm(asm, conversion_type, src_version, dest_version):
159159
new_asm.backpatch.append(copy(asm.backpatch[j]))
160160
new_asm.label.append(copy(asm.label[j]))
161161
new_asm.codes.append(copy(code))
162-
new_asm.code.co_lnotab = decode_lineno_tab(code.co_lnotab, code.co_firstlineno)
162+
new_asm.code.co_lnotab = decode_lineno_tab_old(code.co_lnotab, code.co_firstlineno)
163163
instructions = asm.codes[j].instructions
164164
new_asm.code.instructions = []
165165
i, offset, n = 0, 0, len(instructions)

0 commit comments

Comments
 (0)