Author: Antonio Cuni <[email protected]>
Branch: jitypes2
Changeset: r44379:4005d8453ec0
Date: 2011-05-23 12:20 +0200
http://bitbucket.org/pypy/pypy/changeset/4005d8453ec0/

Log:    make errcheck a property, too

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
@@ -660,15 +660,12 @@
             self._com_index = idx
         _com_index = property(lambda: None, _setcom_index)
 
-        def _are_assumptions_met(self, args):
-            return (self._errcheck_ is None)
+        def _seterrcheck(self, func):
+            self.__rollback()
+            self.errcheck = func
+        errcheck = property(lambda: None, _seterrcheck)
 
         def __call__(self, *args):
-            if not self._are_assumptions_met(args):
-                assert self._slowpath_allowed
-                self.__class__ = CFuncPtr
-                return self(*args)
-            #
             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
@@ -72,6 +72,7 @@
         tf_b.restype = c_byte
         tf_b.argtypes = (c_char_p,)  # this is intentionally wrong
         tf_b.argtypes = None # kill the fast path
+        assert not tf_b._is_fastpath
         assert tf_b(-126) == -42
 
     def test_callable_is_None(self):
@@ -79,4 +80,18 @@
         tf_b.restype = c_byte
         tf_b.argtypes = (c_byte,)
         tf_b.callable = lambda x: x+1
+        assert not tf_b._is_fastpath
         assert tf_b(-126) == -125
+        tf_b.callable = None
+
+    def test_errcheck_is_None(self):
+        def errcheck(result, func, args):
+            return result * 2
+        #
+        tf_b = dll2.tf_b
+        tf_b.restype = c_byte
+        tf_b.argtypes = (c_byte,)
+        tf_b.errcheck = errcheck
+        assert not tf_b._is_fastpath
+        assert tf_b(-126) == -84
+        del tf_b.errcheck
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to