[pypy-svn] pypy jitypes2: make sure that we correctly cache the _ptr of a CFuncPtr.

antocuni commits-noreply at bitbucket.org
Tue Jan 18 16:35:20 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40874:26cd7883d450
Date: 2011-01-18 16:00 +0100
http://bitbucket.org/pypy/pypy/changeset/26cd7883d450/

Log:	make sure that we correctly cache the _ptr of a CFuncPtr. This is
	done by comparing argtypes by equality instead of by identity: in
	the next steps, we will make sure that the jit removes the overhead
	of the comparison

diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -435,3 +435,13 @@
         a[1].x = 33
         u = dll.ret_un_func(a[1])
         assert u.y == 33*10000
+
+    def test_cache_funcptr(self):
+        tf_b = dll.tf_b
+        tf_b.restype = c_byte
+        tf_b.argtypes = (c_byte,)
+        assert tf_b(-126) == -42
+        ptr = tf_b._ptr
+        assert ptr is not None
+        assert tf_b(-126) == -42
+        assert tf_b._ptr is ptr

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
@@ -68,7 +68,7 @@
                     raise TypeError(
                         "item %d in _argtypes_ has no from_param method" % (
                             i + 1,))
-            self._argtypes_ = argtypes
+            self._argtypes_ = list(argtypes)
     argtypes = property(_getargtypes, _setargtypes)
 
     def _getrestype(self):
@@ -265,7 +265,7 @@
         return _ffi.FuncPtr.fromaddr(address, '', ffiargs, ffires)
 
     def _getfuncptr(self, argtypes, restype, thisarg=None):
-        if self._ptr is not None and argtypes is self._argtypes_:
+        if self._ptr is not None and argtypes == self._argtypes_:
             return self._ptr
         if restype is None or not isinstance(restype, _CDataMeta):
             import ctypes
@@ -274,7 +274,7 @@
         resshape = restype._ffiargshape
         if self._buffer is not None:
             ptr = self._getfuncptr_fromaddress(argshapes, resshape)
-            if argtypes is self._argtypes_:
+            if argtypes == self._argtypes_:
                 self._ptr = ptr
             return ptr
 


More information about the Pypy-commit mailing list