3.9: MAGIC_NUMBER injection does not seem to work (i.e. .pyc files end up using CPython's magic)
If I understand the code in https://foss.heptapod.net/pypy/pypy/-/blob/branch/py3.9/lib-python/3/importlib/_bootstrap_external.py#L349-361 correctly:
MAGIC_NUMBER = (3425).to_bytes(2, 'little') + b'\r\n'
#
# PyPy change: the MAGIC_NUMBER is defined in
# pypy/interpreter/pycode.py, 'default_magic'. It is based on a number
# different than CPython's, always < 3000. We get the 4-bytes string
# here via a hack: MAGIC_NUMBER is set in the module from
# module/_frozen_importlib/__init__.py before the module is executed.
# FOR TESTS ONLY, we make it default to imp.get_magic().
try:
MAGIC_NUMBER
except NameError:
import imp
MAGIC_NUMBER = imp.get_magic()
some magic should be happening here that replaces CPython's magic number (3425 in this stdlib version) with PyPy-specific one (pypy_incremental_magic = 336
FWICS). However, this does not seem to work:
>>>> import importlib._bootstrap_external
>>>> importlib._bootstrap_external.MAGIC_NUMBER
b'a\r\r\n'
>>>> importlib._bootstrap_external._RAW_MAGIC_NUMBER & 0xffff
3425
Notably, .pyc files seem to have magic numbers matching CPython ranges:
$ hexdump -C /usr/lib/pypy3.9/__pycache__/abc.pypy39.pyc | head -1
00000000 61 0d 0d 0a 00 00 00 00 e8 95 42 62 38 13 00 00 |a.........Bb8...|
$ hexdump -C /usr/lib/python3.9/__pycache__/abc.cpython-39.pyc | head -1
00000000 61 0d 0d 0a 00 00 00 00 e9 6b 84 62 38 13 00 00 |a........k.b8...|
(though obviously the contents are different)