[pypy-svn] r51520 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
fijal at codespeak.net
fijal at codespeak.net
Fri Feb 15 13:26:24 CET 2008
Author: fijal
Date: Fri Feb 15 13:26:24 2008
New Revision: 51520
Modified:
pypy/dist/pypy/lib/_ctypes/keepalive.txt
pypy/dist/pypy/lib/_ctypes/structure.py
pypy/dist/pypy/lib/app_test/ctypes/test_keepalive.py
Log:
Keepalive for struct.
Modified: pypy/dist/pypy/lib/_ctypes/keepalive.txt
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/keepalive.txt (original)
+++ pypy/dist/pypy/lib/_ctypes/keepalive.txt Fri Feb 15 13:26:24 2008
@@ -32,5 +32,3 @@
* set contents on pointer
* set value on primitive or __init__ on primitive
-
-
\ No newline at end of file
Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py (original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py Fri Feb 15 13:26:24 2008
@@ -117,6 +117,7 @@
self.__setattr__(name, arg)
for name, arg in kwds.items():
self.__setattr__(name, arg)
+ self.__dict__['_objects'] = {}
res.__init__ = __init__
@@ -163,6 +164,9 @@
fieldtype = self._fieldtypes[name].ctype
except KeyError:
raise AttributeError(name)
+ if getattr(value, '_objects', None):
+ self._objects[str(getattr(self.__class__, name).offset)] = \
+ value._objects
value = fieldtype._CData_input(value)
self._buffer.__setattr__(name, value[0])
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 13:26:24 2008
@@ -6,6 +6,7 @@
or not
"""
def test_array_of_pointers(self):
+ # tests array item assignements & pointer.contents = ...
A = POINTER(c_int) * 24
a = A()
l = c_long(2)
@@ -14,3 +15,15 @@
assert l._objects is None
assert p._objects == {'1':l}
assert a._objects == {'3':{'1':l}}
+
+ def test_structure_with_pointers(self):
+ class X(Structure):
+ _fields_ = [('x', POINTER(c_int))]
+
+ x = X()
+ u = c_int(3)
+ p = pointer(u)
+ x.x = p
+ assert x.x._objects is None
+ assert p._objects == {'1': u}
+ assert x._objects == {'0': p._objects}
More information about the Pypy-commit
mailing list