[pypy-svn] r71851 - in pypy/branch/ctypes-configure-cache-2/ctypes_configure: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 6 12:30:22 CET 2010
Author: arigo
Date: Sat Mar 6 12:30:20 2010
New Revision: 71851
Modified:
pypy/branch/ctypes-configure-cache-2/ctypes_configure/cbuild.py
pypy/branch/ctypes-configure-cache-2/ctypes_configure/configure.py
pypy/branch/ctypes-configure-cache-2/ctypes_configure/test/test_configure.py
Log:
Merge the content of branch/ctypes-configure-cache/ctypes_configure,
with minor edits and a different interface.
Modified: pypy/branch/ctypes-configure-cache-2/ctypes_configure/cbuild.py
==============================================================================
--- pypy/branch/ctypes-configure-cache-2/ctypes_configure/cbuild.py (original)
+++ pypy/branch/ctypes-configure-cache-2/ctypes_configure/cbuild.py Sat Mar 6 12:30:20 2010
@@ -5,7 +5,7 @@
debug = 0
-configdir = py.path.local.make_numbered_dir(prefix='ctypes_configure')
+configdir = py.path.local.make_numbered_dir(prefix='ctypes_configure-')
class ExternalCompilationInfo(object):
Modified: pypy/branch/ctypes-configure-cache-2/ctypes_configure/configure.py
==============================================================================
--- pypy/branch/ctypes-configure-cache-2/ctypes_configure/configure.py (original)
+++ pypy/branch/ctypes-configure-cache-2/ctypes_configure/configure.py Sat Mar 6 12:30:20 2010
@@ -164,7 +164,7 @@
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
- entries.append((key, value))
+ entries.append((key, value))
if entries: # can be empty if there are only CConfigSingleEntries
writer = _CWriter(CConfig)
@@ -201,7 +201,6 @@
writer = _CWriter(CConfig)
writer.write_header()
res[key] = value.question(writer.ask_gcc)
-
return res
# ____________________________________________________________
@@ -210,7 +209,6 @@
class CConfigEntry(object):
"Abstract base class."
-
class Struct(CConfigEntry):
"""An entry in a CConfig class that stands for an externally
defined structure.
@@ -313,7 +311,6 @@
S.__name__ = name
return S
-
class SimpleType(CConfigEntry):
"""An entry in a CConfig class that stands for an externally
defined simple numeric type.
@@ -350,7 +347,6 @@
ctype = fixup_ctype(ctype, self.name, (size, sign))
return ctype
-
class ConstantInteger(CConfigEntry):
"""An entry in a CConfig class that stands for an externally
defined integer constant.
@@ -588,14 +584,42 @@
# ____________________________________________________________
+def ctypes_repr(cls):
+ # ctypes_configure does not support nested structs so far
+ # so let's ignore it
+ assert isinstance(cls, ctypes._SimpleCData.__class__)
+ return "ctypes." + cls.__name__
+
def dumpcache(referencefilename, filename, config):
dirname = os.path.dirname(referencefilename)
filename = os.path.join(dirname, filename)
f = open(filename, 'w')
+ print >> f, 'import ctypes'
+ print >> f
names = config.keys()
names.sort()
- for name in names:
- print >> f, '%s = %r' % (name, config[name])
+ for key in names:
+ val = config[key]
+ if isinstance(val, (int, long)):
+ f.write("%s = %d\n" % (key, val))
+ elif val is None:
+ f.write("%s = None\n" % key)
+ elif isinstance(val, ctypes._SimpleCData.__class__):
+ # a simple type
+ f.write("%s = %s\n" % (key, ctypes_repr(val)))
+ elif isinstance(val, ctypes.Structure.__class__):
+ f.write("class %s(ctypes.Structure):\n" % key)
+ f.write(" _fields_ = [\n")
+ for k, v in val._fields_:
+ f.write(" ('%s', %s),\n" % (k, ctypes_repr(v)))
+ f.write(" ]\n")
+ elif isinstance(val, (tuple, list)):
+ for x in val:
+ assert isinstance(x, (int, long, str)), \
+ "lists of integers or strings only"
+ f.write("%s = %r\n" % (key, val))
+ else:
+ raise NotImplementedError("Saving of %r" % (val,))
f.close()
print 'Wrote %s.' % (filename,)
Modified: pypy/branch/ctypes-configure-cache-2/ctypes_configure/test/test_configure.py
==============================================================================
--- pypy/branch/ctypes-configure-cache-2/ctypes_configure/test/test_configure.py (original)
+++ pypy/branch/ctypes-configure-cache-2/ctypes_configure/test/test_configure.py Sat Mar 6 12:30:20 2010
@@ -126,6 +126,39 @@
'ushort': ctypes.c_ushort,
'XYZZY': 42}
+def test_cache():
+ configdir = configure.configdir
+ test_h = configdir.join('test_ctypes_platform2.h')
+ test_h.write('#define XYZZY 42\n'
+ "#define large 2147483648L\n")
+
+ class CConfig:
+ _compilation_info_ = ExternalCompilationInfo(
+ pre_include_lines = ["/* a C comment */",
+ "#include <stdio.h>",
+ "#include <test_ctypes_platform2.h>"],
+ include_dirs = [str(configdir)]
+ )
+
+ FILE = configure.Struct('FILE', [])
+ ushort = configure.SimpleType('unsigned short')
+ XYZZY = configure.ConstantInteger('XYZZY')
+ XUZ = configure.Has('XUZ')
+ large = configure.DefinedConstantInteger('large')
+ undef = configure.Defined('really_undefined')
+
+ cachefile = configdir.join('cache')
+ res = configure.configure(CConfig, savecache=configdir.join('cache'))
+ d = {}
+ execfile(str(cachefile), d)
+ assert d['XYZZY'] == res['XYZZY']
+ assert d['ushort'] == res['ushort']
+ assert d['FILE']._fields_ == res['FILE']._fields_
+ assert d['FILE'].__mro__[1:] == res['FILE'].__mro__[1:]
+ assert d['undef'] == res['undef']
+ assert d['large'] == res['large']
+ assert d['XUZ'] == res['XUZ']
+
def test_ifdef():
class CConfig:
_compilation_info_ = ExternalCompilationInfo(
More information about the Pypy-commit
mailing list