def test_cache(): configdir = configure.configdir with open(configdir.join('test_ctypes_platform2.h'), "w") as test_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') res = configure.configure(CConfig) cachefile = configdir.join('cache') dumpcache.dumpcache('', str(cachefile), res) 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_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') res = configure.configure(CConfig) cachefile = configdir.join('cache') dumpcache.dumpcache('', str(cachefile), res) 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_cache_array_array(): configdir = configure.configdir res = {'foo': (ctypes.c_int * 2) * 3} cachefile = configdir.join('cache_array_array') dumpcache.dumpcache('', str(cachefile), res) # d = {} execfile(str(cachefile), d) assert d['foo'] == res['foo']
def dumpcache2(basename, config): size = 32 if sys.maxint <= 2**32 else 64 filename = '_%s_%s_.py' % (basename, size) dumpcache.dumpcache(__file__, filename, config) # filename = os.path.join(os.path.dirname(__file__), '_%s_cache.py' % (basename,)) g = open(filename, 'w') print >> g, '''\ import sys _size = 32 if sys.maxsize <= 2**32 else 64 # XXX relative import, should be removed together with # XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib _mod = __import__("_%s_%%s_" %% (_size,), globals(), locals(), ["*"], level=1) globals().update(_mod.__dict__)\ ''' % (basename,) g.close()
def dumpcache2(basename, config): size = 32 if sys.maxint <= 2**32 else 64 filename = '_%s_%s_.py' % (basename, size) dumpcache.dumpcache(__file__, filename, config) # filename = os.path.join(os.path.dirname(__file__), '_%s_cache.py' % (basename, )) g = open(filename, 'w') print >> g, '''\ import sys _size = 32 if sys.maxsize <= 2**32 else 64 # XXX relative import, should be removed together with # XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib _mod = __import__("_%s_%%s_" %% (_size,), globals(), locals(), ["*"], level=1) globals().update(_mod.__dict__)\ ''' % (basename, ) g.close()
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() # XXX relative import, should be removed together with # XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib mod = __import__("_%s_%%s_" %% (cpumodel,), globals(), locals(), ["*"]) globals().update(mod.__dict__)\ ''' % (basename, ) g.close()
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() # XXX relative import, should be removed together with # XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib mod = __import__("_%s_%%s_" %% (cpumodel,), globals(), locals(), ["*"]) globals().update(mod.__dict__)\ ''' % (basename,) g.close()
""" 'ctypes_configure' source for _hashlib.py. Run this to rebuild _hashlib_cache.py. """ import autopath from ctypes import * from ctypes_configure import configure, dumpcache class CConfig: _compilation_info_ = configure.ExternalCompilationInfo( includes=['openssl/evp.h'], ) EVP_MD = configure.Struct('EVP_MD', []) EVP_MD_CTX = configure.Struct('EVP_MD_CTX', [('digest', c_void_p)]) config = configure.configure(CConfig) dumpcache.dumpcache(__file__, '_hashlib_cache.py', config)
libraries=["expat"], pre_include_lines=[ "#define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)" ], ) XML_Char = configure.SimpleType("XML_Char", c_char) XML_COMBINED_VERSION = configure.ConstantInteger("XML_COMBINED_VERSION") for name in [ "XML_PARAM_ENTITY_PARSING_NEVER", "XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE", "XML_PARAM_ENTITY_PARSING_ALWAYS", ]: locals()[name] = configure.ConstantInteger(name) XML_Encoding = configure.Struct( "XML_Encoding", [("data", c_void_p), ("convert", c_void_p), ("release", c_void_p), ("map", c_int * 256)] ) XML_Content = configure.Struct( "XML_Content", [("numchildren", c_int), ("children", c_void_p), ("name", c_char_p), ("type", c_int), ("quant", c_int)], ) # this is insanely stupid XML_FALSE = configure.ConstantInteger("XML_FALSE") XML_TRUE = configure.ConstantInteger("XML_TRUE") config = configure.configure(CConfigure) dumpcache.dumpcache(__file__, "_pyexpat_cache.py", config)
"LOG_LOCAL5", "LOG_LOCAL6", "LOG_LOCAL7", ) _OPTIONAL_CONSTANTS = ("LOG_NOWAIT", "LOG_PERROR", "LOG_SYSLOG", "LOG_CRON", "LOG_UUCP", "LOG_NEWS") # Constant aliases if there are not defined _ALIAS = (("LOG_SYSLOG", "LOG_DAEMON"), ("LOG_CRON", "LOG_DAEMON"), ("LOG_NEWS", "LOG_MAIL"), ("LOG_UUCP", "LOG_MAIL")) class SyslogConfigure: _compilation_info_ = ExternalCompilationInfo(includes=["sys/syslog.h"]) for key in _CONSTANTS: setattr(SyslogConfigure, key, ConstantInteger(key)) for key in _OPTIONAL_CONSTANTS: setattr(SyslogConfigure, key, DefinedConstantInteger(key)) config = configure(SyslogConfigure) for key in _OPTIONAL_CONSTANTS: if config[key] is None: del config[key] for alias, key in _ALIAS: config.setdefault(alias, config[key]) all_constants = config.keys() all_constants.sort() config["ALL_CONSTANTS"] = tuple(all_constants) dumpcache(__file__, "_syslog_cache.py", config)
"NOEXPR", "_DATE_FMT", ] for i in range(1, 8): langinfo_names.append("DAY_%d" % i) langinfo_names.append("ABDAY_%d" % i) for i in range(1, 13): langinfo_names.append("MON_%d" % i) langinfo_names.append("ABMON_%d" % i) class LanginfoConfigure: _compilation_info_ = eci nl_item = SimpleType("nl_item") for key in langinfo_names: setattr(LanginfoConfigure, key, DefinedConstantInteger(key)) langinfo_config = configure(LanginfoConfigure) for key, value in langinfo_config.items(): if value is None: del langinfo_config[key] langinfo_names.remove(key) config.update(langinfo_config) _CONSTANTS += langinfo_names # ____________________________________________________________ config["ALL_CONSTANTS"] = tuple(_CONSTANTS) config["HAS_LANGINFO"] = HAS_LANGINFO dumpcache(__file__, "_locale_cache.py", config)
'RLIMIT_NICE', 'RLIMIT_RTPRIO', 'RLIMIT_VMEM', 'RUSAGE_BOTH', 'RUSAGE_SELF', 'RUSAGE_CHILDREN', ) # Setup our configure class ResourceConfigure: _compilation_info_ = ExternalCompilationInfo(includes=['sys/resource.h']) rlim_t = SimpleType('rlim_t') for key in _CONSTANTS: setattr(ResourceConfigure, key, ConstantInteger(key)) for key in _OPTIONAL_CONSTANTS: setattr(ResourceConfigure, key, DefinedConstantInteger(key)) # Configure constants and types config = configure(ResourceConfigure) config['rlim_t_max'] = (1<<(sizeof(config['rlim_t']) * 8)) - 1 optional_constants = [] for key in _OPTIONAL_CONSTANTS: if config[key] is not None: optional_constants.append(key) else: del config[key] config['ALL_CONSTANTS'] = _CONSTANTS + tuple(optional_constants) dumpcache(__file__, '_resource_cache.py', config)