[pypy-svn] r51534 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes

fijal at codespeak.net fijal at codespeak.net
Fri Feb 15 15:07:26 CET 2008


Author: fijal
Date: Fri Feb 15 15:07:25 2008
New Revision: 51534

Modified:
   pypy/dist/pypy/lib/_ctypes/pointer.py
   pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py
Log:
A test and a fix


Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py	Fri Feb 15 15:07:25 2008
@@ -79,6 +79,8 @@
             raise TypeError("expected %s instead of %s" % (
                 self._type_.__name__, type(value).__name__))
         self._objects = {keepalive_key(1):value}
+        if getattr(value, '_objects', None):
+            self._objects[keepalive_key(0)] = value._objects
         value = value._buffer
         self._buffer[0] = value
 

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py	Fri Feb 15 15:07:25 2008
@@ -41,6 +41,16 @@
         assert c_char_p("abc")._objects == "abc"
         assert c_int(3)._objects is None
 
+    def test_pointer_to_pointer(self):
+        l = c_long(2)
+        assert l._objects is None
+
+        p1 = pointer(l)
+        assert p1._objects == {'1':l}
+
+        p2 = pointer(p1)
+        assert p2._objects == {'1':p1, '0':{'1':l}}
+
     def test_cfunc(self):
         def f():
             pass



More information about the Pypy-commit mailing list