Skip to content

Commit 03c93dd

Browse files
author
rocky
committed
Merge branch 'graal-disassembly-save' into graal-disassembly
2 parents f929cc4 + d48d528 commit 03c93dd

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

xdis/disasm.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,25 @@
5151
# FIXME we may also need to distinguish by magic_int2magic
5252
# (for 3.8.5 Graal for example.)
5353
def get_opcode(version_tuple: tuple, python_implementation, alternate_opmap=None, magic_int: int=-1):
54-
5554
# Set up disassembler with the right opcodes
5655
lookup = ".".join((str(i) for i in version_tuple))
5756
if python_implementation == PythonImplementation.PyPy:
5857
lookup += "PyPy"
58+
elif python_implementation == PythonImplementation.Graal:
59+
if magic_int == 21290:
60+
if version_tuple == (3, 11, 7):
61+
lookup = "3.11.7Graal"
62+
else:
63+
lookup = "3.12.7Graal"
64+
else:
65+
lookup += "Graal"
5966
if lookup in op_imports.keys():
6067
if alternate_opmap is not None:
6168
# TODO: change bytecode version number comment line to indicate altered
6269
return remap_opcodes(op_imports[lookup], alternate_opmap)
6370
return op_imports[lookup]
64-
if python_implementation != PythonImplementation.CPyton:
65-
pypy_str = f" for {python_implementation}"
71+
if python_implementation != PythonImplementation.CPython:
72+
implementation_str = f" for {python_implementation}"
6673
else:
6774
implementation_str = ""
6875
raise TypeError(
@@ -156,8 +163,8 @@ def disco(
156163
sip_hash,
157164
header=True,
158165
show_filename=False,
159-
python_implementation=python_implementation)
160-
166+
python_implementation=python_implementation,
167+
)
161168

162169
# Store final output stream when there is an error.
163170
real_out = out or sys.stdout

xdis/load.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ def load_module_from_file_object(
358358
if is_pypy(magic_int, filename):
359359
python_implementation = PythonImplementation.PyPy
360360

361+
# Below we need to return co.version_triple instead of version_triple,
362+
# because Graal uses the *same* magic number but different bytecode
363+
# for Python 3.11 and Python 3.12. What a zoo we have here.
364+
if hasattr(co, "version_triple") and co.version_triple != (0, 0, 0):
365+
version_triple = co.version_triple
366+
361367
return (
362368
version_triple,
363369
timestamp,

0 commit comments

Comments
 (0)