mirror of
https://github.com/syssec-utd/pylingual.git
synced 2026-05-10 18:39:03 -07:00
Merge pull request #112 from XinlongCS/python-3.14-cflow
Python 3.14 LOAD_FAST_BORROW and ast fixes
This commit is contained in:
@@ -35,8 +35,8 @@ def normalize_source(
|
||||
tree = ast.parse(source, feature_version=version)
|
||||
if replace_docstrings:
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Expr) and isinstance(node.value, ast.Str):
|
||||
node.value.s = "pass"
|
||||
if isinstance(node, ast.Expr) and isinstance(node.value, ast.Constant) and isinstance(node.value.value, str):
|
||||
node.value.value = "pass"
|
||||
return ast.unparse(tree)
|
||||
|
||||
|
||||
|
||||
@@ -4,3 +4,4 @@ from .remove_docstrings import remove_docstrings
|
||||
from .remove_nop import remove_nop
|
||||
from .fix_indirect_jump import fix_indirect_jump
|
||||
from .replace_firstlno import replace_firstlno
|
||||
from .replace_borrow import replace_borrow
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from ..EditableBytecode import EditableBytecode
|
||||
|
||||
def replace_borrow(bytecode: EditableBytecode):
|
||||
if bytecode.version < (3,14):
|
||||
return
|
||||
load_fast_borrows = [inst for inst in bytecode.instructions if inst.opname == "LOAD_FAST_BORROW"]
|
||||
for borrow in load_fast_borrows:
|
||||
borrow.opname = "LOAD_FAST"
|
||||
borrow.opcode = bytecode.opcode.LOAD_FAST
|
||||
|
||||
double_load_fast_borrows = [inst for inst in bytecode.instructions if inst.opname == "LOAD_FAST_BORROW_LOAD_FAST_BORROW"]
|
||||
for double_borrow in double_load_fast_borrows:
|
||||
double_borrow.opname = "LOAD_FAST_LOAD_FAST"
|
||||
double_borrow.opcode = bytecode.opcode.LOAD_FAST_LOAD_FAST
|
||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
import networkx as nx
|
||||
from pylingual.control_flow_reconstruction.cfg import CFG
|
||||
from pylingual.editable_bytecode import EditableBytecode, Inst, PYCFile
|
||||
from pylingual.editable_bytecode.bytecode_patches import fix_indirect_jump, fix_unreachable, remove_extended_arg, remove_nop, replace_firstlno
|
||||
from pylingual.editable_bytecode.bytecode_patches import fix_indirect_jump, fix_unreachable, remove_extended_arg, remove_nop, replace_firstlno, replace_borrow
|
||||
from pylingual.editable_bytecode.control_flow_graph import bytecode_to_control_flow_graph
|
||||
|
||||
|
||||
@@ -191,8 +191,8 @@ def compare_pyc(pyc_a: PYCFile | Path, pyc_b: PYCFile | Path) -> list[TestResult
|
||||
pyc_a = pyc_a.copy() if isinstance(pyc_a, PYCFile) else PYCFile(pyc_a)
|
||||
pyc_b = pyc_b.copy() if isinstance(pyc_b, PYCFile) else PYCFile(pyc_b)
|
||||
|
||||
pyc_a.apply_patches([remove_extended_arg, remove_nop, fix_indirect_jump, fix_unreachable, remove_extended_arg, replace_firstlno])
|
||||
pyc_b.apply_patches([remove_extended_arg, remove_nop, fix_indirect_jump, fix_unreachable, remove_extended_arg, replace_firstlno])
|
||||
pyc_a.apply_patches([remove_extended_arg, remove_nop, fix_indirect_jump, fix_unreachable, remove_extended_arg, replace_firstlno, replace_borrow])
|
||||
pyc_b.apply_patches([remove_extended_arg, remove_nop, fix_indirect_jump, fix_unreachable, remove_extended_arg, replace_firstlno, replace_borrow])
|
||||
|
||||
results = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user