[pypy-svn] r73595 - in pypy/branch/cpython-extension/pypy/lib: _ctypes app_test/ctypes_tests

afa at codespeak.net afa at codespeak.net
Fri Apr 9 19:30:55 CEST 2010


Author: afa
Date: Fri Apr  9 19:30:53 2010
New Revision: 73595

Modified:
   pypy/branch/cpython-extension/pypy/lib/_ctypes/pointer.py
   pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_keepalive.py
Log:
Merge r73589 from trunk


Modified: pypy/branch/cpython-extension/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/branch/cpython-extension/pypy/lib/_ctypes/pointer.py	Fri Apr  9 19:30:53 2010
@@ -126,5 +126,13 @@
         raise TypeError("cast() argument 1 must be a pointer, not %s"
                         % (type(obj),))
     result = tp()
+
+    # The casted objects '_objects' member:
+    # It must certainly contain the source objects one.
+    # It must contain the source object itself.
+    if obj._ensure_objects() is not None:
+        result._objects = {keepalive_key(0): obj._objects,
+                           keepalive_key(1): obj}
+
     result._buffer[0] = obj._buffer[0]
     return result

Modified: pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_keepalive.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_keepalive.py	(original)
+++ pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_keepalive.py	Fri Apr  9 19:30:53 2010
@@ -117,7 +117,14 @@
             pass
         cf = CFUNCTYPE(c_int, c_int)(f)
         assert cf._objects == {'0':cf}
-    
+
+    def test_cfunc_cast(self):
+        def f():
+            pass
+        cf = CFUNCTYPE(c_int, c_int)(f)
+        p1 = cast(cf, c_void_p)
+        assert p1._objects == {'1': cf, '0': {'0': cf}}
+
     def test_array_of_struct_with_pointer(self):
         class S(Structure):
             _fields_ = [('x', c_int)]



More information about the Pypy-commit mailing list