[pypy-svn] r61767 - in pypy/trunk/pypy/lib: _ctypes app_test/ctypes_tests

afa at codespeak.net afa at codespeak.net
Thu Feb 12 09:39:06 CET 2009


Author: afa
Date: Thu Feb 12 09:39:05 2009
New Revision: 61767

Modified:
   pypy/trunk/pypy/lib/_ctypes/function.py
   pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py
Log:
Don't store the function ptr if the argtypes were guessed from the actual call.


Modified: pypy/trunk/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/function.py	(original)
+++ pypy/trunk/pypy/lib/_ctypes/function.py	Thu Feb 12 09:39:05 2009
@@ -145,9 +145,11 @@
         argshapes = [arg._ffiargshape for arg in argtypes]
         resshape = restype._ffiargshape
         if self._buffer is not None:
-            self._ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape,
-                                        self._flags_)
-            return self._ptr
+            ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape,
+                                  self._flags_)
+            if argtypes is self._argtypes_:
+                self._ptr = ptr
+            return ptr
 
         cdll = self.dll._handle
         try:

Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py	(original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py	Thu Feb 12 09:39:05 2009
@@ -186,3 +186,19 @@
         func.argtypes = (Adapter(),)
         # ArgumentError: argument 1: ValueError: 99
         raises(ArgumentError, func, 99)
+
+    def test_multiple_signature(self):
+        # when .argtypes is not set, calling a function with a certain
+        # set of parameters should not prevent another call with
+        # another set.
+        from ctypes import CDLL, byref
+        import conftest
+        dll = CDLL(str(conftest.sofile))
+        func = dll._testfunc_p_p
+
+        # This is call has too many arguments
+        assert func(None, 1) == 0
+
+        # This one is normal
+        assert func(None) == 0
+        



More information about the Pypy-commit mailing list