[pypy-svn] r51582 - pypy/dist/pypy/lib/_ctypes
fijal at codespeak.net
fijal at codespeak.net
Mon Feb 18 13:22:57 CET 2008
Author: fijal
Date: Mon Feb 18 13:22:56 2008
New Revision: 51582
Modified:
pypy/dist/pypy/lib/_ctypes/array.py
pypy/dist/pypy/lib/_ctypes/basics.py
pypy/dist/pypy/lib/_ctypes/structure.py
Log:
First approach at reasonable keepalives.
Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py (original)
+++ pypy/dist/pypy/lib/_ctypes/array.py Mon Feb 18 13:22:56 2008
@@ -143,8 +143,7 @@
if isinstance(index, slice):
return self._slice_getitem(index)
index = self._fix_index(index)
- return self._type_._CData_output(self._subarray(index), self,
- self._ffiarray.gettypecode(index)[0])
+ return self._type_._CData_output(self._subarray(index), self, index)
def __len__(self):
return self._length_
Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py (original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py Mon Feb 18 13:22:56 2008
@@ -4,6 +4,19 @@
keepalive_key = str # XXX fix this when provided with test
+def store_reference(where, base_key, target):
+ #self.__dict__['_objects'][key] = value._objects
+ if '_objects' in where.__dict__:
+ # shortcut
+ where.__dict__['_objects'][str(base_key)] = target
+ return
+ key = [base_key]
+ while not '_objects' in where.__dict__:
+ key.append(where.__dict__['_index'])
+ where = where.__dict__['_base']
+ real_key = ":".join([str(i) for i in key])
+ where.__dict__['_objects'][real_key] = target
+
class ArgumentError(Exception):
pass
Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py (original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py Mon Feb 18 13:22:56 2008
@@ -1,6 +1,7 @@
import _rawffi
-from _ctypes.basics import _CData, _CDataMeta, keepalive_key
+from _ctypes.basics import _CData, _CDataMeta, keepalive_key,\
+ store_reference
import inspect
def round_up(size, alignment):
@@ -166,7 +167,7 @@
raise AttributeError(name)
if getattr(value, '_objects', None):
key = keepalive_key(getattr(self.__class__, name).offset)
- self.__dict__['_objects'][key] = value._objects
+ store_reference(self, key, value._objects)
cobj, value = fieldtype._CData_input(value)
self._buffer.__setattr__(name, value[0])
More information about the Pypy-commit
mailing list