Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 707
    • Issues 707
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
    • Model experiments
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPyPyPy
  • pypypypy
  • Issues
  • #3783
Closed
Open
Issue created Jul 19, 2022 by Michał Górny@mgornyDeveloper

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)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking