Skip to content

Commit 6e7edf3

Browse files
author
rocky
committed
Merge?
1 parent 5e5ce50 commit 6e7edf3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

xasm/assemble.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(self, python_version, is_pypy) -> None:
7171
self.size = 0 # Size of source code. Only relevant in version 3 and above
7272
self.is_pypy = is_pypy
7373
self.python_version = python_version
74+
self.is_pypy = is_pypy
7475
self.timestamp = None
7576
self.backpatch = [] # list of backpatch dicts, one for each function
7677
self.label = [] # list of label dists, one for each function
@@ -170,11 +171,11 @@ def asm_file(path) -> Optional[Assembler]:
170171
# FIXME: extract all code options below the top-level and asm.code_list
171172

172173
elif line.startswith("#"):
173-
match = re.match("^# (Pypy )?Python bytecode ", line)
174+
match = re.match("^# (PyPy )?Python bytecode ", line)
174175
if match:
175176
if match.group(1):
177+
is_pypy = True
176178
pypy_str = match.group(1)
177-
is_pypy = len(pypy_str)
178179
else:
179180
is_pypy = False
180181
pypy_str = ""
@@ -197,7 +198,7 @@ def asm_file(path) -> Optional[Assembler]:
197198
elif line.startswith("# Timestamp in code: "):
198199
text = line[len("# Timestamp in code: ") :].strip()
199200
time_str = text.split()[0]
200-
if is_int(time_str):
201+
if is_int(time_str) and hasattr(asm, "timestamp"):
201202
asm.timestamp = int(time_str)
202203
elif line.startswith("# Method Name: "):
203204
if method_name:
@@ -248,7 +249,9 @@ def asm_file(path) -> Optional[Assembler]:
248249
elif line.startswith("# Number of locals: "):
249250
l_str = line[len("# Number of locals: ") :].strip()
250251
asm.code.co_nlocals = int(l_str)
251-
elif line.startswith("# Source code size mod 2**32: "):
252+
elif line.startswith("# Source code size mod 2**32: ") and hasattr(
253+
asm, "size"
254+
):
252255
l_str = line[
253256
len("# Source code size mod 2**32: ") : -len(" bytes")
254257
].strip()

xasm/write_pyc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def write_pycfile(
1818
) -> int:
1919
rc = 0
2020
version_str = version_tuple_to_str(version_triple, end=2)
21+
if is_pypy:
22+
version_str += "pypy"
2123
magic_bytes = magics[version_str]
2224
magic_int = magic2int(magic_bytes)
2325
fp.write(magic_bytes)

0 commit comments

Comments
 (0)