[pypy-commit] pypy jitypes2: make sure that we enable the fastpath only if we are allowed to

antocuni noreply at buildbot.pypy.org
Mon May 23 15:06:32 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r44381:7039913ba67d
Date: 2011-05-23 15:17 +0200
http://bitbucket.org/pypy/pypy/changeset/7039913ba67d/

Log:	make sure that we enable the fastpath only if we are allowed to

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -96,7 +96,8 @@
             #
             # XXX tentative hack to make it jit-friendly
             if all([hasattr(argtype, '_ffiargshape') for argtype in argtypes]):
-                self.__class__ = make_specialized_subclass(self.__class__)
+                fastpath_cls = make_fastpath_subclass(self.__class__)
+                fastpath_cls.enable_fastpath_maybe(self)
             self._argtypes_ = list(argtypes)
     argtypes = property(_getargtypes, _setargtypes)
 
@@ -626,12 +627,12 @@
             self._needs_free = False
 
 
-def make_specialized_subclass(CFuncPtr):
+def make_fastpath_subclass(CFuncPtr):
     if CFuncPtr._is_fastpath:
         return CFuncPtr
     #
     try:
-        return make_specialized_subclass.memo[CFuncPtr]
+        return make_fastpath_subclass.memo[CFuncPtr]
     except KeyError:
         pass
 
@@ -640,6 +641,13 @@
         _is_fastpath = True
         _slowpath_allowed = True # set to False by tests
 
+        @classmethod
+        def enable_fastpath_maybe(cls, obj):
+            if (obj.callable is None and
+                obj._com_index is None and
+                obj._errcheck_ is None):
+                obj.__class__ = cls
+
         def __rollback(self):
             assert self._slowpath_allowed
             self.__class__ = CFuncPtr
@@ -677,6 +685,6 @@
                 return CFuncPtr.__call__(self, *args)
             return result
 
-    make_specialized_subclass.memo[CFuncPtr] = CFuncPtrFast
+    make_fastpath_subclass.memo[CFuncPtr] = CFuncPtrFast
     return CFuncPtrFast
-make_specialized_subclass.memo = {}
+make_fastpath_subclass.memo = {}
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -24,12 +24,21 @@
         #
         tf_b = dll.tf_b
         tf_b.restype = c_byte
+        #
+        # so far, it's still using the slowpath
+        assert not tf_b._is_fastpath
+        tf_b.errcheck = errcheck
         tf_b.argtypes = (c_byte,)
+        # errcheck prevented the fastpath to kick in
+        assert not tf_b._is_fastpath
+        #
+        del tf_b.errcheck
+        tf_b.argtypes = (c_byte,) # try to re-enable the fastpath
+        assert tf_b._is_fastpath
+        #
+        assert not tf_b._slowpath_allowed
         # errcheck disables the fastpath
         py.test.raises(AssertionError, "tf_b.errcheck = errcheck")
-        #
-        assert tf_b._is_fastpath
-        assert not tf_b._slowpath_allowed
         py.test.raises(AssertionError, "tf_b('aaa')") # force a TypeError
 
     def test_simple_args(self):


More information about the pypy-commit mailing list