Author: Armin Rigo <[email protected]>
Branch: inline-dict-ops
Changeset: r48310:cebb862ad03f
Date: 2011-10-21 15:12 +0200
http://bitbucket.org/pypy/pypy/changeset/cebb862ad03f/

Log:    Move this hack away from lltype. This logic is needed to have
        lltype correctly detect accesses inside dead GcStruct.

diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py 
b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -530,6 +530,10 @@
     def __str__(self):
         return repr(self)
 
+    def _setparentstructure(self, parent, parentindex):
+        super(_parentable_mixin, self)._setparentstructure(parent, parentindex)
+        self._keepparent = parent   # always keep a strong ref
+
 class _struct_mixin(_parentable_mixin):
     """Mixin added to _struct containers when they become ctypes-based."""
     __slots__ = ()
diff --git a/pypy/rpython/lltypesystem/lltype.py 
b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -1517,7 +1517,12 @@
         self._wrparent = weakref.ref(parent)
         self._parent_type = typeOf(parent)
         self._parent_index = parentindex
-        self._keepparent = parent
+        if (isinstance(self._parent_type, Struct)
+            and self._parent_type._names
+            and parentindex in (self._parent_type._names[0], 0)
+            and self._TYPE._gckind == typeOf(parent)._gckind):
+            # keep strong reference to parent, we share the same allocation
+            self._keepparent = parent
 
     def _parentstructure(self, check=True):
         if self._wrparent is not None:
@@ -1726,7 +1731,7 @@
         # Don't do it if we are inside a GC object, though -- it's someone
         # else's job to keep the GC object alive
         if (typeOf(top_container(parent))._gckind == 'raw' or
-            hasattr(top_container(parent)._storage, 'contents')):
+            hasattr(top_container(parent)._storage, 'contents')):  # ll2ctypes
             self._keepparent = parent
 
     def __str__(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to