[pypy-svn] r13379 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jun 14 12:40:26 CEST 2005


Author: arigo
Date: Tue Jun 14 12:40:23 2005
New Revision: 13379

Modified:
   pypy/dist/pypy/rpython/lltype.py
   pypy/dist/pypy/rpython/rclass.py
   pypy/dist/pypy/rpython/test/test_lltype.py
Log:
- sanitize rclass.ll_cast_to_object().
- bug fix with test in the parent structure reference code.


Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Tue Jun 14 12:40:23 2005
@@ -544,7 +544,9 @@
         self._wrparent = weakref.ref(parent)
         self._parent_type = typeOf(parent)
         self._parent_index = parentindex
-        if parentindex == 0 and self._TYPE._gcstatus() == typeOf(parent)._gcstatus():
+        if (isinstance(self._parent_type, Struct)
+            and parentindex == self._parent_type._names[0]
+            and self._TYPE._gcstatus() == typeOf(parent)._gcstatus()):
             # keep strong reference to parent, we share the same allocation
             self._keepparent = parent 
 

Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py	(original)
+++ pypy/dist/pypy/rpython/rclass.py	Tue Jun 14 12:40:23 2005
@@ -483,15 +483,10 @@
 #  Low-level implementation of operations on classes and instances
 
 def ll_cast_to_object(obj):
-    # This strange recursive version is type-safe :-)
-    # Each ll_cast_to_object() call below is done with a different type.
-    if typeOf(obj) == OBJECTPTR:
-        return obj
-    else:
-        return ll_cast_to_object(obj.super)
+    return cast_pointer(OBJECTPTR, obj)
 
 def ll_type(obj):
-    return ll_cast_to_object(obj).typeptr
+    return cast_pointer(OBJECTPTR, obj).typeptr
 
 def ll_issubclass(subcls, cls):
     while subcls != cls:

Modified: pypy/dist/pypy/rpython/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_lltype.py	(original)
+++ pypy/dist/pypy/rpython/test/test_lltype.py	Tue Jun 14 12:40:23 2005
@@ -328,5 +328,13 @@
     py.test.raises(TypeError, "a[0] = s")
     S = Struct('s', ('last', Array(S)))
     py.test.raises(TypeError, "Array(S)")
-    
-    
+
+def test_immortal_parent():
+    S1 = GcStruct('substruct', ('x', Signed))
+    S  = GcStruct('parentstruct', ('s1', S1))
+    p = malloc(S, immortal=True)
+    p1 = p.s1
+    p1.x = 5
+    del p
+    p = cast_pointer(Ptr(S), p1)
+    assert p.s1.x == 5



More information about the Pypy-commit mailing list