[pypy-svn] r71854 - in pypy/branch/ctypes-configure-cache-2/pypy/lib: . ctypes_config_cache ctypes_config_cache/test

arigo at codespeak.net arigo at codespeak.net
Sat Mar 6 12:49:52 CET 2010


Author: arigo
Date: Sat Mar  6 12:49:51 2010
New Revision: 71854

Added:
   pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/hashlib.ctc.py   (contents, props changed)
   pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/test/   (props changed)
   pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/test/test_cache.py   (contents, props changed)
Modified:
   pypy/branch/ctypes-configure-cache-2/pypy/lib/_hashlib.py
   pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/syslog.ctc.py
Log:
Add hashlib.ctc.py, and write tests for *.ctc.py.


Modified: pypy/branch/ctypes-configure-cache-2/pypy/lib/_hashlib.py
==============================================================================
--- pypy/branch/ctypes-configure-cache-2/pypy/lib/_hashlib.py	(original)
+++ pypy/branch/ctypes-configure-cache-2/pypy/lib/_hashlib.py	Sat Mar  6 12:49:51 2010
@@ -1,6 +1,8 @@
 from ctypes import *
 import ctypes.util
-from ctypes_configure import configure
+
+# load the platform-specific cache made by running hashlib.ctc.py
+from ctypes_config_cache._hashlib_cache import *
 
 # Note: OpenSSL on OS X only provides md5 and sha1
 libpath = ctypes.util.find_library('ssl')
@@ -16,18 +18,6 @@
     else:
         return buffer(x)[:]
 
-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)])
-c = configure.configure(CConfig)
-EVP_MD_CTX = c['EVP_MD_CTX']
-EVP_MD = c['EVP_MD']
-
 def patch_fields(fields):
     res = []
     for k, v in fields:
@@ -39,7 +29,6 @@
 
 class EVP_MD_CTX(Structure):
     _fields_ = patch_fields(EVP_MD_CTX._fields_)
-del c
 
 # OpenSSL initialization
 lib.OpenSSL_add_all_digests()

Added: pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/hashlib.ctc.py
==============================================================================
--- (empty file)
+++ pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/hashlib.ctc.py	Sat Mar  6 12:49:51 2010
@@ -0,0 +1,21 @@
+"""
+'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)

Modified: pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/syslog.ctc.py
==============================================================================
--- pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/syslog.ctc.py	(original)
+++ pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/syslog.ctc.py	Sat Mar  6 12:49:51 2010
@@ -4,8 +4,9 @@
 """
 
 import autopath
-from ctypes_configure.configure import (configure, dumpcache,
+from ctypes_configure.configure import (configure,
     ExternalCompilationInfo, ConstantInteger, DefinedConstantInteger)
+from ctypes_configure.dumpcache import dumpcache
 
 
 _CONSTANTS = (

Added: pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/test/test_cache.py
==============================================================================
--- (empty file)
+++ pypy/branch/ctypes-configure-cache-2/pypy/lib/ctypes_config_cache/test/test_cache.py	Sat Mar  6 12:49:51 2010
@@ -0,0 +1,32 @@
+import py
+import sys, os
+from pypy.tool.udir import udir
+
+dirpath = py.path.local(__file__).dirpath().dirpath()
+
+
+def run(filename, outputname):
+    filepath = dirpath.join(filename)
+    tmpdir = udir.ensure('testcache-' + filename, dir=True)
+    outputpath = tmpdir.join(outputname)
+    d = {'__file__': str(outputpath)}
+    path = sys.path[:]
+    try:
+        sys.path.insert(0, str(dirpath))
+        execfile(str(filepath), d)
+    finally:
+        sys.path[:] = path
+    #
+    assert outputpath.check(exists=1)
+    d = {}
+    execfile(str(outputpath), d)
+    return d
+
+
+def test_syslog():
+    d = run('syslog.ctc.py', '_syslog_cache.py')
+    assert 'LOG_NOTICE' in d
+
+def test_hashlib():
+    d = run('hashlib.ctc.py', '_hashlib_cache.py')
+    assert hasattr(d['EVP_MD_CTX'], 'digest')



More information about the Pypy-commit mailing list