[pypy-commit] pypy gc_no_cleanup_nursery: write a test showing the problem

fijal noreply at buildbot.pypy.org
Fri Sep 5 23:10:10 CEST 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: gc_no_cleanup_nursery
Changeset: r73332:189f50ca3955
Date: 2014-09-05 15:09 -0600
http://bitbucket.org/pypy/pypy/changeset/189f50ca3955/

Log:	write a test showing the problem

diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -1180,14 +1180,26 @@
 
     def gen_zero_gc_pointers(self, TYPE, v, llops, previous_steps=None,
                              everything=False):
+        if previous_steps is None:
+            previous_steps = []
         if isinstance(TYPE, lltype.Struct):
             for name in TYPE._names:
                 FIELD = getattr(TYPE, name)
+                c_name = rmodel.inputconst(lltype.Void, name)
+                if isinstance(FIELD, lltype.Struct):
+                    # parent
+                    self.gen_zero_gc_pointers(FIELD, v, llops,
+                                              previous_steps + [c_name],
+                                              everything=everything)
+                    continue
                 if ((isinstance(FIELD, lltype.Ptr) and FIELD._needsgc())
                     or everything):
-                    c_name = rmodel.inputconst(lltype.Void, name)
                     c_null = rmodel.inputconst(FIELD, FIELD._defl())
-                    llops.genop('bare_setfield', [v, c_name, c_null])
+                    if previous_steps:
+                        llops.genop('bare_setinteriorfield',
+                                [v] + previous_steps + [c_name, c_null])
+                    else:
+                        llops.genop('bare_setfield', [v, c_name, c_null])
                 elif (isinstance(FIELD, lltype.Array) and
                       isinstance(FIELD.OF, lltype.Ptr) and FIELD.OF._needsgc()):
                     xxx
diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -1194,13 +1194,40 @@
     def test_gcflag_extra(self):
         self.run("gcflag_extra")
 
+    def define_zeroing_class_works(self):
+        class A(object):
+            def __init__(self, x):
+                self.x = x
+
+        class BABA(A):
+            def __init__(self, y):
+                self.y = y
+
+        def fn(x):
+            if x > 3:
+                a = BABA(str(x))
+            else:
+                a = A(x)
+            assert not a.y
+            return 0
+
+        return fn
+
+    def test_zeroing_class_works(self):
+        self.run("zeroing_class_works", 13)
+
     def define_check_zero_works(self):
         S = lltype.GcStruct("s", ('x', lltype.Signed))
+        S2 = lltype.GcStruct("s2", ('parent',
+                                    lltype.Struct("s1", ("x", lltype.Signed))),
+                                    ('y', lltype.Signed))
         A = lltype.GcArray(lltype.Signed)
         
         def fn():
             s = lltype.malloc(S, zero=True)
             assert s.x == 0
+            s2 = lltype.malloc(S2, zero=True)
+            assert s2.parent.x == 0
             a = lltype.malloc(A, 3, zero=True)
             assert a[2] == 0
             return 0


More information about the pypy-commit mailing list