Skip to content

Commit 5f94403

Browse files
author
rocky
committed
Handle more graal unmarshaling...
Graal 3.10 added, Code for graal-specific unmarshal routines have been added.
1 parent 5b192c4 commit 5f94403

File tree

6 files changed

+221
-64
lines changed

6 files changed

+221
-64
lines changed

xdis/codetype/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,24 @@ def portableCodeType(version_triple=PYTHON_VERSION_TRIPLE):
226226
# Note: default values of `None` indicate a required parameter.
227227
# default values of -1, (None,) or "" indicate an unsupplied parameter.
228228
def to_portable(
229-
co_argcount,
229+
co_argcount: int,
230230
co_posonlyargcount: Optional[int] = -1, # 3.8 .. 3.10
231231
co_kwonlyargcount: Optional[int] = -1, # 3.0+
232-
co_nlocals=None,
232+
co_nlocals: int=0,
233233
co_stacksize: Optional[int] = -1, # 1.5+
234-
co_flags=None,
235-
co_code=None, # 3.0+ this type changes from <str> to <bytes>
236-
co_consts=None,
237-
co_names=None,
238-
co_varnames=None,
239-
co_filename=None,
240-
co_name=None,
241-
co_qualname=None,
234+
co_flags: int=0,
235+
co_code: Union[str, bytes]="", # 3.0+ this type changes from <str> to <bytes>
236+
co_consts: tuple[str, ...]=tuple(),
237+
co_names: tuple[str, ...]=tuple(),
238+
co_varnames: tuple[str, ...]=tuple(),
239+
co_filename: str="??",
240+
co_name: str="??",
241+
co_qualname: str="??",
242242
co_firstlineno: int=-1,
243243
co_lnotab: str="", # 1.5+; 3.0+ this type changes from <str> to <bytes>
244244
# In 3.11 it is different
245-
co_freevars: tuple[None]=(None,), # 2.0+
246-
co_cellvars: tuple[None]=(None,), # 2.0+
245+
co_freevars: tuple[str, ...]=tuple(), # 2.0+
246+
co_cellvars: tuple[str, ...]=tuple(), # 2.0+
247247
co_exceptiontable=None, # 3.11+
248248
version_triple=PYTHON_VERSION_TRIPLE,
249249
collection_order: Dict[Union[set, frozenset, dict], Tuple[Any]] = {},

xdis/codetype/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1616

1717
import inspect
18+
from typing import Union
1819

1920

2021
def iscode(obj):
@@ -39,10 +40,17 @@ def code_has_star_star_arg(code):
3940

4041
class CodeBase:
4142
# These mimic some of the attributes in a Python code type
42-
co_code: bytes
43-
co_name: str
43+
co_argcount: int
44+
co_code: Union[bytes, str]
45+
co_consts: tuple
4446
co_filename: str
4547
co_firstlineno: int
48+
co_kwposonlyargcount: int
49+
co_name: str
50+
co_nlocals: int
51+
co_posonlyargcount: int
52+
co_stacksize: int
53+
co_varnames: tuple
4654

4755
# Mimic Python 3 code access functions
4856
def __len__(self) -> int:

xdis/disasm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def disco_loop(
243243
real_out.write("\n# Instruction disassembly not supported here.\n")
244244
else:
245245
real_out.write(f"\n# Instruction disassembly for {co.co_name} not supported here.\n")
246+
real_out.write(f"instruction bytecode:\n{co.co_code.hex(':')}\n")
247+
246248
else:
247249
bytecode = Bytecode(co, opc, dup_lines=dup_lines)
248250
real_out.write(
@@ -397,9 +399,6 @@ def disassemble_file(
397399

398400
is_graal = magic_int in GRAAL3_MAGICS
399401

400-
if is_graal and save_file_offsets:
401-
outstream.write("\n# Option showing file hex offsets (-x) ignored; not supported in Graal bytecode.\n")
402-
403402
if asm_format == "header":
404403
show_module_header(
405404
version_tuple,

xdis/load.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def load_module_from_file_object(
236236

237237
try:
238238
# FIXME: use the internal routine below
239-
tuple_version = magic_int2tuple(magic_int)
239+
version_triple = magic_int2tuple(magic_int)
240240
except KeyError:
241241
if len(magic) >= 2:
242242
raise ImportError(
@@ -346,7 +346,7 @@ def load_module_from_file_object(
346346
fp.close()
347347

348348
return (
349-
tuple_version,
349+
version_triple,
350350
timestamp,
351351
magic_int,
352352
co,

xdis/magics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from xdis.version_info import IS_GRAAL, IS_PYPY, IS_RUST, version_tuple_to_str
4343

4444
GRAAL3_MAGICS = (21150, 21280, 21290)
45-
UNSUPPORTED_GRAAL3_MAGICS = (21150, 21280)
45+
UNSUPPORTED_GRAAL3_MAGICS = (21150,)
4646
JYTHON_MAGICS = (1011, 65526)
4747

4848
# See below for mapping to version numbers.

0 commit comments

Comments
 (0)