[pypy-commit] pypy py35-getbuiltin: Don't 'inject' the .pyc magic number from the outside, but import it from __pypy__.

amauryfa pypy.commits at gmail.com
Fri Sep 30 02:06:09 EDT 2016


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py35-getbuiltin
Changeset: r87462:e5b6f76186cf
Date: 2016-09-29 23:17 +0200
http://bitbucket.org/pypy/pypy/changeset/e5b6f76186cf/

Log:	Don't 'inject' the .pyc magic number from the outside, but import it
	from __pypy__. This fixes the reload of test_importlib.util.

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
@@ -232,11 +232,10 @@
 #
 # 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.
+# different than CPython's, always < 3000.
+from __pypy__ import PYC_MAGIC as _RAW_MAGIC_NUMBER
 
-_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little')  # For import.c
+MAGIC_NUMBER = _RAW_MAGIC_NUMBER.to_bytes(4, 'little')
 
 _PYCACHE = '__pycache__'
 _OPT = 'opt-'
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -570,10 +570,16 @@
         w_builtin.install()
         self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
 
+        from pypy.module.__pypy__ import Module
+        w_name = self.wrap('__pypy__')
+        mod = Module(self, w_name)
+        mod.install()
+
         # exceptions was bootstrapped as '__exceptions__' but still
         # lives in pypy/module/exceptions, we rename it below for
         # sys.builtin_module_names
-        bootstrap_modules = set(('sys', 'imp', 'builtins', 'exceptions'))
+        bootstrap_modules = set(('sys', 'imp', 'builtins',
+                                 'exceptions', '__pypy__'))
         installed_builtin_modules = list(bootstrap_modules)
 
         exception_types_w = self.export_builtin_exceptions()
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -1,7 +1,6 @@
 import sys
 
 from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module.imp.importing import get_pyc_magic
 
 class BuildersModule(MixedModule):
     appleveldefs = {}
@@ -91,6 +90,7 @@
         '_promote'                   : 'interp_magic._promote',
         'normalize_exc'             : 'interp_magic.normalize_exc',
         'StdErrPrinter'             : 'interp_stderrprinter.W_StdErrPrinter',
+        'PYC_MAGIC'                 : 'space.wrap(interp_magic.default_magic)',
     }
 
     submodules = {
@@ -110,8 +110,6 @@
                                  'interp_magic.reset_method_cache_counter')
             self.extra_interpdef('mapdict_cache_counter',
                                  'interp_magic.mapdict_cache_counter')
-        PYC_MAGIC = get_pyc_magic(self.space)
-        self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
         try:
             from rpython.jit.backend import detect_cpu
             model = detect_cpu.autodetect()
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -1,6 +1,7 @@
 from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.gateway import WrappedDefault, unwrap_spec
 from pypy.interpreter.pycode import CodeHookCache
+from pypy.interpreter.pycode import default_magic
 from pypy.interpreter.pyframe import PyFrame
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rlib.objectmodel import we_are_translated
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
@@ -34,9 +34,6 @@
         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)


More information about the pypy-commit mailing list