[pypy-svn] r58675 - in pypy/branch/2.5-merge/pypy: interpreter lib module/__builtin__ module/__pypy__ module/sys
arigo at codespeak.net
arigo at codespeak.net
Mon Oct 6 17:56:51 CEST 2008
Author: arigo
Date: Mon Oct 6 17:56:50 2008
New Revision: 58675
Modified:
pypy/branch/2.5-merge/pypy/interpreter/pycode.py
pypy/branch/2.5-merge/pypy/lib/imp.py
pypy/branch/2.5-merge/pypy/module/__builtin__/importing.py
pypy/branch/2.5-merge/pypy/module/__pypy__/__init__.py
pypy/branch/2.5-merge/pypy/module/sys/__init__.py
pypy/branch/2.5-merge/pypy/module/sys/version.py
Log:
(iko, arigo)
Change -again- the way the magic numbers are stored
in the pyc files. This has the result that imp.get_magic()
on top of a pypy-c returns a number that is within the same
range as CPython's. This is necessary to make PyPy-on-pypy-c
work correctly :-/
Modified: pypy/branch/2.5-merge/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/interpreter/pycode.py (original)
+++ pypy/branch/2.5-merge/pypy/interpreter/pycode.py Mon Oct 6 17:56:50 2008
@@ -26,6 +26,12 @@
CO_NESTED = 0x0010
CO_GENERATOR = 0x0020
+# Magic numbers for the bytecode version in code objects.
+# See comments in pypy/module/__builtin__/importing.
+cpython_magic, = struct.unpack("<i", imp.get_magic()) # host magic number
+default_magic = (62131+2) | 0x0a0d0000 # this PyPy's magic
+ # (62131=CPython 2.5.1)
+
# cpython_code_signature helper
def cpython_code_signature(code):
"([list-of-arg-names], vararg-name-or-None, kwarg-name-or-None)."
@@ -44,16 +50,13 @@
kwargname = None
return argnames, varargname, kwargname
-cpython_magic, = struct.unpack("<i", imp.get_magic())
-default_magic = 62061 | 0x0a0d0000 # value for Python 2.4.1
-
class PyCode(eval.Code):
"CPython-style code objects."
def __init__(self, space, argcount, nlocals, stacksize, flags,
code, consts, names, varnames, filename,
name, firstlineno, lnotab, freevars, cellvars,
- hidden_applevel=False, magic = 62131 | 0x0a0d0000): # value for Python 2.5c2
+ hidden_applevel=False, magic = default_magic):
"""Initialize a new code object from parameters given by
the pypy compiler"""
self.space = space
Modified: pypy/branch/2.5-merge/pypy/lib/imp.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/lib/imp.py (original)
+++ pypy/branch/2.5-merge/pypy/lib/imp.py Mon Oct 6 17:56:50 2008
@@ -21,11 +21,11 @@
# PyPy-specific interface
try:
- from sys import _magic as _get_magic_as_int
+ import __pypy__
def get_magic():
"""Return the magic number for .pyc or .pyo files."""
import struct
- return struct.pack('<i', _get_magic_as_int())
+ return struct.pack('<i', __pypy__.PYC_MAGIC)
except ImportError:
# XXX CPython testing hack: delegate to the real imp.get_magic
get_magic = __import__('imp').get_magic
Modified: pypy/branch/2.5-merge/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/__builtin__/importing.py (original)
+++ pypy/branch/2.5-merge/pypy/module/__builtin__/importing.py Mon Oct 6 17:56:50 2008
@@ -380,25 +380,33 @@
"""
-# we decided to use our own magic number starting from 1024
-# and we have 10 potential bits for different opcodes free.
+# XXX picking a magic number is a mess. So far it works because we
+# have only two extra opcodes, which bump the magic number by +1 and
+# +2 respectively, and CPython leaves a gap of 10 when it increases
+# its own magic number. To avoid assigning exactly the same numbers
+# as CPython we always add a +2. We'll have to think again when we
+# get at the fourth new opcode :-(
#
-# The presence of special bytecodes bumps the
-# magic number:
+# * CALL_LIKELY_BUILTIN +1
+# * CALL_METHOD +2
#
-# * CALL_LIKELY_BUILTIN +2
-# * CALL_METHOD +4
+# In other words:
#
-#
-MAGIC = 1034 | (ord('\r')<<16) | (ord('\n')<<24)
+# default_magic -- used by CPython without the -U option
+# default_magic + 1 -- used by CPython with the -U option
+# default_magic + 2 -- used by PyPy without any extra opcode
+# ...
+# default_magic + 5 -- used by PyPy with both extra opcodes
+#
+from pypy.interpreter.pycode import default_magic
MARSHAL_VERSION_FOR_PYC = 2
def get_pyc_magic(space):
- result = MAGIC
+ result = default_magic
if space.config.objspace.opcodes.CALL_LIKELY_BUILTIN:
- result += 2
+ result += 1
if space.config.objspace.opcodes.CALL_METHOD:
- result += 4
+ result += 2
return result
Modified: pypy/branch/2.5-merge/pypy/module/__pypy__/__init__.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/__pypy__/__init__.py (original)
+++ pypy/branch/2.5-merge/pypy/module/__pypy__/__init__.py Mon Oct 6 17:56:50 2008
@@ -1,6 +1,7 @@
# Package initialisation
from pypy.interpreter.mixedmodule import MixedModule
+from pypy.module.__builtin__.importing import get_pyc_magic
class Module(MixedModule):
appleveldefs = {
@@ -12,6 +13,7 @@
}
def setup_after_space_initialization(self):
+ """NOT_RPYTHON"""
if not self.space.config.translating:
self.extra_interpdef('isfake', 'interp_magic.isfake')
self.extra_interpdef('interp_pdb', 'interp_magic.interp_pdb')
@@ -20,4 +22,5 @@
'interp_magic.method_cache_counter')
self.extra_interpdef('reset_method_cache_counter',
'interp_magic.reset_method_cache_counter')
-
+ PYC_MAGIC = get_pyc_magic(self.space)
+ self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
Modified: pypy/branch/2.5-merge/pypy/module/sys/__init__.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/sys/__init__.py (original)
+++ pypy/branch/2.5-merge/pypy/module/sys/__init__.py Mon Oct 6 17:56:50 2008
@@ -68,8 +68,6 @@
'getdefaultencoding' : 'interp_encoding.getdefaultencoding',
'setdefaultencoding' : 'interp_encoding.setdefaultencoding',
- # XXX hack
- '_magic' : 'version._magic',
}
appleveldefs = {
#'displayhook' : 'app.displayhook',
Modified: pypy/branch/2.5-merge/pypy/module/sys/version.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/sys/version.py (original)
+++ pypy/branch/2.5-merge/pypy/module/sys/version.py Mon Oct 6 17:56:50 2008
@@ -63,10 +63,6 @@
d[ver[3]] << 4 |
subver)
-def _magic(space):
- from pypy.module.__builtin__.importing import get_pyc_magic
- return space.wrap(get_pyc_magic(space))
-
def svn_revision():
"Return the last-changed svn revision number."
# NB. we hack the number directly out of the .svn directory to avoid
More information about the Pypy-commit
mailing list