[pypy-commit] pypy lightweight-finalizers: a test and a fix

fijal noreply at buildbot.pypy.org
Sun Oct 2 01:16:29 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: lightweight-finalizers
Changeset: r47759:171d990aedfd
Date: 2011-10-01 15:15 -0300
http://bitbucket.org/pypy/pypy/changeset/171d990aedfd/

Log:	a test and a fix

diff --git a/pypy/rpython/memory/gctypelayout.py b/pypy/rpython/memory/gctypelayout.py
--- a/pypy/rpython/memory/gctypelayout.py
+++ b/pypy/rpython/memory/gctypelayout.py
@@ -250,7 +250,17 @@
     if builder.get_raw_mem_attr_name(TYPE):
         name = builder.get_raw_mem_attr_name(TYPE)
         infobits |= T_HAS_RAW_MEM_PTR
-        info.ofstorawptr = llmemory.offsetof(TYPE, 'inst_' + name)
+        # can be in a superclass
+        T = TYPE
+        l = []
+        while not hasattr(T, 'inst_' + name):
+            l.append(llmemory.offsetof(T, 'super'))
+            T = T.super
+        l.append(llmemory.offsetof(T, 'inst_' + name))
+        ofs = l[0]
+        for i in range(1, len(l)):
+            ofs += l[i]
+        info.ofstorawptr = ofs
     info.infobits = infobits | T_KEY_VALUE
 
 # ____________________________________________________________
diff --git a/pypy/rpython/memory/test/test_gc.py b/pypy/rpython/memory/test/test_gc.py
--- a/pypy/rpython/memory/test/test_gc.py
+++ b/pypy/rpython/memory/test/test_gc.py
@@ -141,10 +141,16 @@
                 if arg:
                     self.p = lltype.malloc(T, flavor='raw')
 
+        class B(AClass):
+            pass
+
         def f():
             a = AClass(0)
             for i in range(30):
-                a = AClass(3)
+                if i % 2:
+                    a = B(3)
+                else:
+                    a = AClass(3)
                 AClass(0)
             llop.gc__collect(lltype.Void)
             assert a.p
diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py
--- a/pypy/rpython/test/test_rclass.py
+++ b/pypy/rpython/test/test_rclass.py
@@ -998,7 +998,7 @@
         RTTI = getRuntimeTypeInfo(TYPE)
         RTTI._obj.query_funcptr # should not raise
         assert RTTI._obj.raw_mem_attr_name == 'p'
-    
+
     def test_del_inheritance(self):
         from pypy.rlib import rgc
         class State:


More information about the pypy-commit mailing list