Author: Antonio Cuni <[email protected]>
Branch: jitypes2
Changeset: r44376:0045269d2c30
Date: 2011-05-23 11:40 +0200
http://bitbucket.org/pypy/pypy/changeset/0045269d2c30/
Log: - add a test checking that we do the right thing in case argtypes is
reset to None
- don't check it all the time, but reset the class as soon as it's
set
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
@@ -640,9 +640,18 @@
_is_fastpath = True
_slowpath_allowed = True # set to False by tests
+ def __rollback(self):
+ assert self._slowpath_allowed
+ self.__class__ = CFuncPtr
+
+ # disable the fast path if we reset argtypes
+ def _setargtypes(self, argtypes):
+ self.__rollback()
+ self._setargtypes(argtypes)
+ argtypes = property(CFuncPtr._getargtypes, _setargtypes)
+
def _are_assumptions_met(self, args):
- return (self._argtypes_ is not None and
- self.callable is None and
+ return (self.callable is None and
not self._com_index and
self._errcheck_ is None)
@@ -655,7 +664,6 @@
assert self.callable is None
assert not self._com_index
assert self._argtypes_ is not None
- argtypes = self._argtypes_
thisarg = None
argtypes = self._argtypes_
restype = self._restype_
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/support.py
b/pypy/module/test_lib_pypy/ctypes_tests/support.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/support.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/support.py
@@ -41,6 +41,7 @@
#
mod = sys.modules[cls.__module__]
del_funcptr_refs_maybe(mod, 'dll')
+ del_funcptr_refs_maybe(mod, 'dll2')
del_funcptr_refs_maybe(mod, 'lib')
del_funcptr_refs_maybe(mod, 'testdll')
del_funcptr_refs_maybe(mod, 'ctdll')
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
@@ -12,7 +12,8 @@
def setup_module(mod):
import conftest
_ctypes_test = str(conftest.sofile)
- mod.dll = MyCDLL(_ctypes_test)
+ mod.dll = MyCDLL(_ctypes_test) # slowpath not allowed
+ mod.dll2 = CDLL(_ctypes_test) # slowpath allowed
class TestFastpath(BaseCTypesTestChecker):
@@ -62,3 +63,13 @@
# supported only in the slow path so far
result = f("abcd", ord("b"))
assert result == "bcd"
+
+
+class TestFallbackToSlowpath(BaseCTypesTestChecker):
+
+ 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 = None # kill the fast path
+ assert tf_b(-126) == -42
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit