[pypy-svn] r51517 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
fijal at codespeak.net
fijal at codespeak.net
Fri Feb 15 12:43:03 CET 2008
Author: fijal
Date: Fri Feb 15 12:43:02 2008
New Revision: 51517
Added:
pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py (contents, props changed)
Modified:
pypy/dist/pypy/lib/_ctypes/array.py
pypy/dist/pypy/lib/_ctypes/basics.py
pypy/dist/pypy/lib/_ctypes/pointer.py
Log:
One test and keepalive logic simple enough to pass this test.
Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py (original)
+++ pypy/dist/pypy/lib/_ctypes/array.py Fri Feb 15 12:43:02 2008
@@ -110,6 +110,7 @@
def __init__(self, *args):
self._buffer = self._ffiarray(self._length_)
self._needs_free = True
+ self._objects = {}
for i, arg in enumerate(args):
self[i] = arg
@@ -135,8 +136,10 @@
if isinstance(index, slice):
self._slice_setitem(index, value)
return
- value = self._type_._CData_input(value)
index = self._fix_index(index)
+ if getattr(value, '_objects', None):
+ self._objects[str(index)] = value._objects
+ value = self._type_._CData_input(value)
if not isinstance(self._type_._ffishape, tuple):
self._buffer[index] = value[0]
# something more sophisticated, cannot set field directly
Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py (original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py Fri Feb 15 12:43:02 2008
@@ -57,6 +57,7 @@
""" The most basic object for all ctypes types
"""
__metaclass__ = _CDataMeta
+ _objects = None
def __init__(self, *args, **kwds):
raise TypeError("%s has no type" % (type(self),))
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 12:43:02 2008
@@ -78,6 +78,7 @@
if not isinstance(value, self._type_):
raise TypeError("expected %s instead of %s" % (
self._type_.__name__, type(value).__name__))
+ self._objects = {'1':value}
value = value._buffer
self._buffer[0] = value
Added: pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py Fri Feb 15 12:43:02 2008
@@ -0,0 +1,16 @@
+
+from ctypes import *
+
+class TestKeepalive:
+ """ Tests whether various objects land in _objects
+ or not
+ """
+ def test_array_of_pointers(self):
+ A = POINTER(c_int) * 24
+ a = A()
+ l = c_long(2)
+ p = pointer(l)
+ a[3] = p
+ assert l._objects is None
+ assert p._objects == {'1':l}
+ assert a._objects == {'3':{'1':l}}
More information about the Pypy-commit
mailing list