Skip to content

Commit e11a03d

Browse files
author
rocky
committed
magic load adjustments for Graal
1 parent b88cf98 commit e11a03d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

xdis/load.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,15 @@ def load_module_from_file_object(
311311
source_size = unpack("<I", fp.read(4))[0] # size mod 2**32
312312

313313
if get_code:
314-
if save_file_offsets and magic_int not in GRAAL3_MAGICS:
314+
is_graal = magic_int in GRAAL3_MAGICS
315+
# Graal uses the same magic int for separate major/minor releases!
316+
graal_weirdness_check = not is_graal or PYTHON_VERSION_TRIPLE == version
317+
if save_file_offsets and not is_graal:
315318
co, file_offsets = xdis.unmarshal.load_code_and_get_file_offsets(
316319
fp, magic_int, code_objects
317320
)
318321

319-
elif my_magic_int == magic_int:
322+
elif my_magic_int == magic_int and graal_weirdness_check:
320323
bytecode = fp.read()
321324
co = marshal.loads(bytecode)
322325
# Python 3.10 returns a tuple here?

xdis/magics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,12 @@ def __by_version(magic_versions: Dict[bytes, str]) -> dict:
702702
# Graal uses JVM bytecode, not Python bytecode
703703
add_magic_from_int(21150, "3.8.5Graal")
704704

705-
# Graal Java 21.0.2
705+
# Graal Java.
706+
# Note: Differnet major/minor releases can have the same magic!
707+
# Graal for 3.11 and 3.12 are like that.
706708
add_magic_from_int(21280, "3.10.8Graal")
707709
add_magic_from_int(21290, "3.11.7Graal")
710+
# add_magic_from_int(21290, "3.12.8Graal")
708711

709712

710713
# Jython uses JVM bytecode, not Python bytecode.

0 commit comments

Comments
 (0)