[pypy-commit] pypy jitypes2: remove explicit check of callable during __call__; replace it with a property which reverts to the slowpath as soon as we set it

antocuni noreply at buildbot.pypy.org
Mon May 23 12:18:04 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r44377:1c0556181e1f
Date: 2011-05-23 12:09 +0200
http://bitbucket.org/pypy/pypy/changeset/1c0556181e1f/

Log:	remove explicit check of callable during __call__; replace it with a
	property which reverts to the slowpath as soon as we set it

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
@@ -650,9 +650,13 @@
             self._setargtypes(argtypes)
         argtypes = property(CFuncPtr._getargtypes, _setargtypes)
 
+        def _setcallable(self, func):
+            self.__rollback()
+            self.callable = func
+        callable = property(lambda: None, _setcallable)
+
         def _are_assumptions_met(self, args):
-            return (self.callable is None and
-                    not self._com_index and
+            return (not self._com_index and
                     self._errcheck_ is None)
 
         def __call__(self, *args):
@@ -661,9 +665,7 @@
                 self.__class__ = CFuncPtr
                 return self(*args)
             #
-            assert self.callable is None
             assert not self._com_index
-            assert self._argtypes_ is not None
             thisarg = None
             argtypes = self._argtypes_
             restype = self._restype_
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
@@ -70,6 +70,13 @@
     def test_argtypes_is_None(self):
         tf_b = dll2.tf_b
         tf_b.restype = c_byte
-        tf_b.argtypes = (c_char_p,)
+        tf_b.argtypes = (c_char_p,)  # this is intentionally wrong
         tf_b.argtypes = None # kill the fast path
         assert tf_b(-126) == -42
+
+    def test_callable_is_None(self):
+        tf_b = dll2.tf_b
+        tf_b.restype = c_byte
+        tf_b.argtypes = (c_byte,)
+        tf_b.callable = lambda x: x+1
+        assert tf_b(-126) == -125


More information about the pypy-commit mailing list