[pypy-svn] r78871 - in pypy/trunk: lib_pypy/ctypes_config_cache lib_pypy/ctypes_config_cache/test pypy/jit/backend pypy/module/__pypy__ pypy/module/__pypy__/test
arigo at codespeak.net
arigo at codespeak.net
Mon Nov 8 13:58:42 CET 2010
Author: arigo
Date: Mon Nov 8 13:58:40 2010
New Revision: 78871
Added:
pypy/trunk/lib_pypy/ctypes_config_cache/dumpcache.py
Modified:
pypy/trunk/lib_pypy/ctypes_config_cache/ (props changed)
pypy/trunk/lib_pypy/ctypes_config_cache/hashlib.ctc.py
pypy/trunk/lib_pypy/ctypes_config_cache/locale.ctc.py
pypy/trunk/lib_pypy/ctypes_config_cache/pyexpat.ctc.py
pypy/trunk/lib_pypy/ctypes_config_cache/rebuild.py
pypy/trunk/lib_pypy/ctypes_config_cache/resource.ctc.py
pypy/trunk/lib_pypy/ctypes_config_cache/syslog.ctc.py
pypy/trunk/lib_pypy/ctypes_config_cache/test/test_cache.py
pypy/trunk/pypy/jit/backend/detect_cpu.py
pypy/trunk/pypy/module/__pypy__/__init__.py
pypy/trunk/pypy/module/__pypy__/test/test_special.py
Log:
Tweaks to allow the ctypes_config_cache to contain both 32-bit
and 64-bit versions. Previously, it only contained the version
of the most recently built pypy-c, and if you tried to use it
with a pypy-c built for the other word size, you would get random
segfaults.
Added: pypy/trunk/lib_pypy/ctypes_config_cache/dumpcache.py
==============================================================================
--- (empty file)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/dumpcache.py Mon Nov 8 13:58:40 2010
@@ -0,0 +1,23 @@
+import os
+from ctypes_configure import dumpcache
+from pypy.jit.backend import detect_cpu
+
+def dumpcache2(basename, config):
+ model = detect_cpu.autodetect_main_model_and_size()
+ filename = '_%s_%s_.py' % (basename, model)
+ dumpcache.dumpcache(__file__, filename, config)
+ #
+ filename = os.path.join(os.path.dirname(__file__),
+ '_%s_cache.py' % (basename,))
+ g = open(filename, 'w')
+ print >> g, '''\
+try:
+ from __pypy__ import cpumodel
+except ImportError:
+ from pypy.jit.backend import detect_cpu
+ cpumodel = detect_cpu.autodetect_main_model_and_size()
+mod = __import__("ctypes_config_cache._%s_%%s_" %% (cpumodel,),
+ None, None, ["*"])
+globals().update(mod.__dict__)\
+''' % (basename,)
+ g.close()
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/hashlib.ctc.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/hashlib.ctc.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/hashlib.ctc.py Mon Nov 8 13:58:40 2010
@@ -4,7 +4,8 @@
"""
from ctypes import *
-from ctypes_configure import configure, dumpcache
+from ctypes_configure import configure
+import dumpcache
class CConfig:
@@ -17,4 +18,4 @@
[('digest', c_void_p)])
config = configure.configure(CConfig)
-dumpcache.dumpcache(__file__, '_hashlib_cache.py', config)
+dumpcache.dumpcache2('hashlib', config)
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/locale.ctc.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/locale.ctc.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/locale.ctc.py Mon Nov 8 13:58:40 2010
@@ -5,7 +5,7 @@
from ctypes_configure.configure import (configure, ExternalCompilationInfo,
ConstantInteger, DefinedConstantInteger, SimpleType, check_eci)
-from ctypes_configure.dumpcache import dumpcache
+import dumpcache
# ____________________________________________________________
@@ -70,4 +70,4 @@
config['ALL_CONSTANTS'] = tuple(_CONSTANTS)
config['HAS_LANGINFO'] = HAS_LANGINFO
-dumpcache(__file__, '_locale_cache.py', config)
+dumpcache.dumpcache2('locale', config)
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/pyexpat.ctc.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/pyexpat.ctc.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/pyexpat.ctc.py Mon Nov 8 13:58:40 2010
@@ -5,7 +5,8 @@
import ctypes
from ctypes import c_char_p, c_int, c_void_p, c_char
-from ctypes_configure import configure, dumpcache
+from ctypes_configure import configure
+import dumpcache
class CConfigure:
@@ -41,4 +42,4 @@
config = configure.configure(CConfigure)
-dumpcache.dumpcache(__file__, '_pyexpat_cache.py', config)
+dumpcache.dumpcache2('pyexpat', config)
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/rebuild.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/rebuild.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/rebuild.py Mon Nov 8 13:58:40 2010
@@ -31,10 +31,25 @@
sys.path[:] = path
def try_rebuild():
+ from pypy.jit.backend import detect_cpu
+ model = detect_cpu.autodetect_main_model_and_size()
+ # remove the files '_*_model_.py'
+ left = {}
+ for p in os.listdir(_dirpath):
+ if p.startswith('_') and (p.endswith('_%s_.py' % model) or
+ p.endswith('_%s_.pyc' % model)):
+ os.unlink(os.path.join(_dirpath, p))
+ elif p.startswith('_') and (p.endswith('_.py') or
+ p.endswith('_.pyc')):
+ for i in range(2, len(p)-4):
+ left[p[:i]] = True
+ # remove the files '_*_cache.py' if there is no '_*_*_.py' left around
for p in os.listdir(_dirpath):
if p.startswith('_') and (p.endswith('_cache.py') or
p.endswith('_cache.pyc')):
- os.unlink(os.path.join(_dirpath, p))
+ if p[:-9] not in left:
+ os.unlink(p)
+ #
for p in os.listdir(_dirpath):
if p.endswith('.ctc.py'):
try:
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/resource.ctc.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/resource.ctc.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/resource.ctc.py Mon Nov 8 13:58:40 2010
@@ -4,7 +4,7 @@
"""
from ctypes import sizeof
-from ctypes_configure.dumpcache import dumpcache
+import dumpcache
from ctypes_configure.configure import (configure,
ExternalCompilationInfo, ConstantInteger, DefinedConstantInteger,
SimpleType)
@@ -58,4 +58,4 @@
del config[key]
config['ALL_CONSTANTS'] = _CONSTANTS + tuple(optional_constants)
-dumpcache(__file__, '_resource_cache.py', config)
+dumpcache.dumpcache2('resource', config)
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/syslog.ctc.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/syslog.ctc.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/syslog.ctc.py Mon Nov 8 13:58:40 2010
@@ -5,7 +5,7 @@
from ctypes_configure.configure import (configure,
ExternalCompilationInfo, ConstantInteger, DefinedConstantInteger)
-from ctypes_configure.dumpcache import dumpcache
+import dumpcache
_CONSTANTS = (
@@ -72,4 +72,4 @@
all_constants = config.keys()
all_constants.sort()
config['ALL_CONSTANTS'] = tuple(all_constants)
-dumpcache(__file__, '_syslog_cache.py', config)
+dumpcache.dumpcache2('syslog', config)
Modified: pypy/trunk/lib_pypy/ctypes_config_cache/test/test_cache.py
==============================================================================
--- pypy/trunk/lib_pypy/ctypes_config_cache/test/test_cache.py (original)
+++ pypy/trunk/lib_pypy/ctypes_config_cache/test/test_cache.py Mon Nov 8 13:58:40 2010
@@ -7,19 +7,27 @@
def run(filename, outputname):
filepath = dirpath.join(filename)
- tmpdir = udir.ensure('testcache-' + filename, dir=True)
- outputpath = tmpdir.join(outputname)
- d = {'__file__': str(outputpath)}
+ tmpdir2 = udir.ensure('testcache-' + filename, dir=True)
+ tmpdir = tmpdir2.ensure('ctypes_config_cache', dir=True)
+ tmpdir.join('__init__.py').write('\n')
+ tmpdir.join('dumpcache.py').write(dirpath.join('dumpcache.py').read())
path = sys.path[:]
try:
- sys.path.insert(0, str(dirpath))
- execfile(str(filepath), d)
+ sys.path.insert(0, str(tmpdir))
+ execfile(str(filepath), {})
finally:
sys.path[:] = path
+ sys.modules.pop('dumpcache', None)
#
+ outputpath = tmpdir.join(outputname)
assert outputpath.check(exists=1)
d = {}
- execfile(str(outputpath), d)
+ try:
+ sys.path.insert(0, str(tmpdir2))
+ execfile(str(outputpath), d)
+ finally:
+ sys.path[:] = path
+ sys.modules.pop('ctypes_config_cache', None)
return d
Modified: pypy/trunk/pypy/jit/backend/detect_cpu.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/detect_cpu.py (original)
+++ pypy/trunk/pypy/jit/backend/detect_cpu.py Mon Nov 8 13:58:40 2010
@@ -34,7 +34,17 @@
'x86_64': 'x86',
}[mach]
except KeyError:
- raise ProcessorAutodetectError, "unsupported processor '%s'" % mach
+ return mach
+
+def autodetect_main_model_and_size():
+ model = autodetect_main_model()
+ if sys.maxint == 2**31-1:
+ model += '_32'
+ elif sys.maxint == 2**63-1:
+ model += '_64'
+ else:
+ raise AssertionError, "bad value for sys.maxint"
+ return model
def autodetect():
model = autodetect_main_model()
Modified: pypy/trunk/pypy/module/__pypy__/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/__pypy__/__init__.py (original)
+++ pypy/trunk/pypy/module/__pypy__/__init__.py Mon Nov 8 13:58:40 2010
@@ -25,3 +25,7 @@
'interp_magic.reset_method_cache_counter')
PYC_MAGIC = get_pyc_magic(self.space)
self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
+ #
+ from pypy.jit.backend import detect_cpu
+ model = detect_cpu.autodetect_main_model_and_size()
+ self.extra_interpdef('cpumodel', 'space.wrap(%r)' % model)
Modified: pypy/trunk/pypy/module/__pypy__/test/test_special.py
==============================================================================
--- pypy/trunk/pypy/module/__pypy__/test/test_special.py (original)
+++ pypy/trunk/pypy/module/__pypy__/test/test_special.py Mon Nov 8 13:58:40 2010
@@ -17,3 +17,7 @@
from __pypy__ import isfake
import select
assert isfake(select)
+
+ def test_cpumodel(self):
+ import __pypy__
+ assert hasattr(__pypy__, 'cpumodel')
More information about the Pypy-commit
mailing list