[pypy-svn] pypy jitypes2: add tests that check that the fastpath is actually taken
antocuni
commits-noreply at bitbucket.org
Mon Jan 31 18:27:39 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r41500:7ab03547b83a
Date: 2011-01-28 13:49 +0100
http://bitbucket.org/pypy/pypy/changeset/7ab03547b83a/
Log: add tests that check that the fastpath is actually taken
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
@@ -55,6 +55,7 @@
_paramflags = None
_com_index = None
_com_iid = None
+ _is_fastpath = False
def _getargtypes(self):
return self._argtypes_
@@ -517,6 +518,9 @@
def make_specialized_subclass(CFuncPtr):
+ if CFuncPtr._is_fastpath:
+ return CFuncPtr
+ #
try:
return make_specialized_subclass.memo[CFuncPtr]
except KeyError:
@@ -524,6 +528,9 @@
class CFuncPtrFast(CFuncPtr):
+ _is_fastpath = True
+ _slowpath_allowed = True # set to False by tests
+
def _are_assumptions_met(self, args):
return (self._argtypes_ is not None and
self.callable is None and
@@ -532,8 +539,11 @@
def __call__(self, *args):
if not self._are_assumptions_met(args):
+ assert self._slowpath_allowed
self.__class__ = CFuncPtr
return self(*args)
+
+ return self._rollback_to_slow_version(*args)
#
assert self.callable is None
assert not self._com_index
@@ -546,7 +556,8 @@
try:
result = self._call_funcptr(funcptr, *args)
except TypeError: # XXX, should be FFITypeError
- return CFuncPtr.__call__(self, *args) # XXX
+ assert self._slowpath_allowed
+ return CFuncPtr.__call__(self, *args)
assert self._errcheck_ is None
return result
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -0,0 +1,37 @@
+from ctypes import CDLL, c_byte
+import sys
+import py
+from support import BaseCTypesTestChecker
+
+class MyCDLL(CDLL):
+ def __getattr__(self, attr):
+ fn = self[attr] # this way it's not cached as an attribute
+ fn._slowpath_allowed = False
+ return fn
+
+def setup_module(mod):
+ import conftest
+ _ctypes_test = str(conftest.sofile)
+ mod.dll = MyCDLL(_ctypes_test)
+
+
+class TestFastpath(BaseCTypesTestChecker):
+
+ def test_fastpath_forbidden(self):
+ def errcheck(result, func, args):
+ return result
+ #
+ tf_b = dll.tf_b
+ tf_b.restype = c_byte
+ tf_b.argtypes = (c_byte,)
+ tf_b.errcheck = errcheck # errcheck disables the fastpath
+ assert tf_b._is_fastpath
+ assert not tf_b._slowpath_allowed
+ py.test.raises(AssertionError, "tf_b(-126)")
+ del tf_b.errcheck
+
+ def test_simple_args(self):
+ tf_b = dll.tf_b
+ tf_b.restype = c_byte
+ tf_b.argtypes = (c_byte,)
+ assert tf_b(-126) == -42
More information about the Pypy-commit
mailing list