Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r86673:cea8ccfe05f4
Date: 2016-08-29 09:53 +0200
http://bitbucket.org/pypy/pypy/changeset/cea8ccfe05f4/
Log: Hack at importlib/_bootstrap_external.py to use the same magic
version number for pyc files as the one declared in
pypy/interpreter/pycode.py.
diff --git a/lib-python/3/importlib/_bootstrap_external.py
b/lib-python/3/importlib/_bootstrap_external.py
--- a/lib-python/3/importlib/_bootstrap_external.py
+++ b/lib-python/3/importlib/_bootstrap_external.py
@@ -228,7 +228,14 @@
# longer be understood by older implementations of the eval loop (usually
# due to the addition of new opcodes).
-MAGIC_NUMBER = (3350).to_bytes(2, 'little') + b'\r\n'
+# MAGIC_NUMBER = (3350).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.
+
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -35,7 +35,8 @@
# we compute the magic number in a similar way to CPython, but we use a
# different value for the highest 16 bits. Bump pypy_incremental_magic every
-# time you make pyc files incompatible
+# time you make pyc files incompatible. This value ends up in the frozen
+# importlib, via MAGIC_NUMBER in module/_frozen_importlib/__init__.
pypy_incremental_magic = 80 # bump it by 16
assert pypy_incremental_magic % 16 == 0
diff --git a/pypy/module/_frozen_importlib/__init__.py
b/pypy/module/_frozen_importlib/__init__.py
--- a/pypy/module/_frozen_importlib/__init__.py
+++ b/pypy/module/_frozen_importlib/__init__.py
@@ -28,10 +28,15 @@
def install(self):
"""NOT_RPYTHON"""
+ from pypy.module.imp import interp_imp
+
super(Module, self).install()
space = self.space
# "import importlib/_boostrap_external.py"
w_mod = Module(space, space.wrap("_frozen_importlib_external"))
+ # hack: inject MAGIC_NUMBER into this module's dict
+ space.setattr(w_mod, space.wrap('MAGIC_NUMBER'),
+ interp_imp.get_magic(space))
self._compile_bootstrap_module(
space, '_bootstrap_external', w_mod.w_name, w_mod.w_dict)
space.sys.setmodule(w_mod)
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -24,7 +24,11 @@
PREFIX = 'pypy3-'
DEFAULT_SOABI = '%s%d%d' % ((PREFIX,) + PYPY_VERSION[:2])
-PYC_TAG = '%s%d%d' % ((PREFIX,) + PYPY_VERSION[:2])
+PYC_TAG = '%s%d%d' % ((PREFIX,) + PYPY_VERSION[:2]) # 'pypy3-XY'
+
+# see also pypy_incremental_magic in interpreter/pycode.py for the magic
+# version number stored inside pyc files.
+
@specialize.memo()
def get_so_extension(space):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit