Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r1042:c4246fdf279a
Date: 2012-11-17 09:56 +0100
http://bitbucket.org/cffi/cffi/changeset/c4246fdf279a/

Log:    Minor performance improvement for PyPy.

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -34,7 +34,7 @@
         """Create an FFI instance.  The 'backend' argument is used to
         select a non-default backend, mostly for tests.
         """
-        from . import cparser
+        from . import cparser, model
         if backend is None:
             try:
                 import _cffi_backend as backend
@@ -62,8 +62,16 @@
         self.cdef('typedef struct _IO_FILE FILE;')
         del self._cdefsources[:]
         #
-        self.NULL = self.cast("void *", 0)
-        self.CData, self.CType = backend._get_types()
+        BVoidP = self._get_cached_btype(model.voidp_type)
+        if isinstance(backend, types.ModuleType):
+            # _cffi_backend: attach these constants to the class
+            if not hasattr(FFI, 'NULL'):
+                FFI.NULL = self.cast(BVoidP, 0)
+                FFI.CData, FFI.CType = backend._get_types()
+        else:
+            # ctypes backend: attach these constants to the instance
+            self.NULL = self.cast(BVoidP, 0)
+            self.CData, self.CType = backend._get_types()
 
     def cdef(self, csource, override=False):
         """Parse the given C source.  This registers all declared functions,
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -168,6 +168,8 @@
         BItem = self.totype.get_cached_btype(ffi, finishlist, can_delay=True)
         return global_cache(self, ffi, 'new_pointer_type', BItem)
 
+voidp_type = PointerType(void_type)
+
 
 class ConstPointerType(PointerType):
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to