Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r921:168df351a4de
Date: 2012-09-08 09:16 +0200
http://bitbucket.org/cffi/cffi/changeset/168df351a4de/

Log:    Add the keyword argument verify(tag='foo') and document it.

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -6,7 +6,7 @@
 class Verifier(object):
 
     def __init__(self, ffi, preamble, tmpdir=None, ext_package=None,
-                 force_generic_engine=False, **kwds):
+                 tag='', force_generic_engine=False, **kwds):
         self.ffi = ffi
         self.preamble = preamble
         vengine_class = _locate_engine_class(ffi, force_generic_engine)
@@ -22,7 +22,8 @@
         k1 = k1.lstrip('0x').rstrip('L')
         k2 = hex(binascii.crc32(key[1::2]) & 0xffffffff)
         k2 = k2.lstrip('0').rstrip('L')
-        modulename = '_cffi_%s%s%s' % (self._vengine._class_key, k1, k2)
+        modulename = '_cffi_%s_%s%s%s' % (tag, self._vengine._class_key,
+                                          k1, k2)
         suffix = _get_so_suffix()
         self.tmpdir = tmpdir or _caller_dir_pycache()
         self.sourcefilename = os.path.join(self.tmpdir, modulename + '.c')
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -420,7 +420,7 @@
 The verification step
 ---------------------
 
-``ffi.verify(source, tmpdir=.., ext_package=.., **kwargs)``:
+``ffi.verify(source, tmpdir=.., ext_package=.., tag='', **kwargs)``:
 verifies that the current ffi signatures
 compile on this machine, and return a dynamic library object.  The
 dynamic library can be used to call functions and access global
@@ -544,6 +544,10 @@
    compiled extension module should be looked from.  This is
    only useful after `distributing modules using CFFI`_.
 
+   The ``tag`` argument gives an extra string inserted in the
+   middle of the extension module's name: ``_cffi_<tag>_<hash>``.
+   Useful to give a bit more context, e.g. when debugging.
+
 
 Working with pointers, structures and arrays
 --------------------------------------------
@@ -1143,13 +1147,14 @@
 can be instantiated directly.  It is normally instantiated for you by
 ``ffi.verify()``, and the instance is attached as ``ffi.verifier``.
 
-- ``Verifier(ffi, preamble, tmpdir=.., ext_package='', **kwds)``:
+- ``Verifier(ffi, preamble, tmpdir=.., ext_package='', tag='', **kwds)``:
   instantiate the class with an
   FFI object and a preamble, which is C text that will be pasted into
   the generated C source.  The value of ``tmpdir`` defaults to the
   directory ``directory_of_the_caller/__pycache__``.  The value of
   ``ext_package`` is used when looking up an already-compiled, already-
-  installed version of the extension module.
+  installed version of the extension module.  The module name is
+  ``_cffi_<tag>_<hash>``.
   The keyword arguments are passed directly
   to `distutils when building the Extension object.`__
 
diff --git a/testing/test_zdistutils.py b/testing/test_zdistutils.py
--- a/testing/test_zdistutils.py
+++ b/testing/test_zdistutils.py
@@ -224,6 +224,15 @@
     def test_install_and_reload_module_package(self):
         self.test_install_and_reload_module(targetpackage='foo_iarmp')
 
+    def test_tag(self):
+        ffi = FFI()
+        ffi.cdef("/* test_tag */ double test1tag(double x);")
+        csrc = "double test1tag(double x) { return x - 42.0; }"
+        lib = ffi.verify(csrc, force_generic_engine=self.generic,
+                         tag='xxtest_tagxx')
+        assert lib.test1tag(143) == 101.0
+        assert '_cffi_xxtest_tagxx_' in ffi.verifier.modulefilename
+
 
 class TestDistUtilsCPython(DistUtilsTest):
     generic = False
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to