[pypy-svn] r62818 - pypy/branch/pyjitpl5/pypy/rpython/lltypesystem
fijal at codespeak.net
fijal at codespeak.net
Tue Mar 10 17:28:56 CET 2009
Author: fijal
Date: Tue Mar 10 17:28:55 2009
New Revision: 62818
Modified:
pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lltype.py
Log:
a complex logic that preserves parentlinks when passing around pointers
to subclasses. A bit obscure, but works. Also I'm not sure about is not
vs != in lltype, but it's needed since ctypes objects are not the same
Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/ll2ctypes.py Tue Mar 10 17:28:55 2009
@@ -25,6 +25,7 @@
_ctypes_cache = {}
_eci_cache = {}
+_parent_cache = {}
def _setup_ctypes_cache():
from pypy.rpython.lltypesystem import rffi
@@ -620,6 +621,8 @@
raise NotImplementedError(T)
container._ctypes_storage_was_allocated()
storage = container._storage
+ if lltype.parentlink(container)[0] is not None:
+ _parent_cache[ctypes.addressof(storage)] = lltype.parentlink(container)
p = ctypes.pointer(storage)
if index:
p = ctypes.cast(p, ctypes.c_void_p)
@@ -683,6 +686,9 @@
ctypes.cast(cobj, ctypes_instance)))
container = lltype._struct(T.TO)
struct_use_ctypes_storage(container, cobj.contents)
+ addr = ctypes.addressof(cobj.contents)
+ if addr in _parent_cache:
+ container._setparentstructure(*_parent_cache[addr])
elif isinstance(T.TO, lltype.Array):
if T.TO._hints.get('nolength', False):
container = _array_of_unknown_length(T.TO)
Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lltype.py Tue Mar 10 17:28:55 2009
@@ -1163,7 +1163,7 @@
if parent is None:
raise RuntimeError("widening to trash: %r" % self)
PARENTTYPE = struc._parent_type
- if getattr(parent, PARENTTYPE._names[0]) is not struc:
+ if getattr(parent, PARENTTYPE._names[0]) != struc:
raise InvalidCast(CURTYPE, PTRTYPE) # xxx different exception perhaps?
struc = parent
u -= 1
More information about the Pypy-commit
mailing list