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

mwh at codespeak.net mwh at codespeak.net
Wed Feb 1 15:46:01 CET 2006


Author: mwh
Date: Wed Feb  1 15:45:59 2006
New Revision: 22922

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
   pypy/dist/pypy/rpython/memory/test/test_gctransform.py
Log:
cleanups to destructor graph generation.
allow the gctransform to insert a 'gc_free' at the end of the graph.


Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Wed Feb  1 15:45:59 2006
@@ -169,6 +169,12 @@
         result.concretetype = lltype.Void
         return [SpaceOperation("gc_pop_alive_pyobj", [var], result)]
 
+    def free(self, var):
+        result = Variable()
+        result.concretetype = lltype.Void
+        return [SpaceOperation("gc_free", [var], result)]        
+    
+
     # ----------------------------------------------------------------
 
     def _deallocator_body_for_type(self, v, TYPE, depth=1):
@@ -195,21 +201,37 @@
             yield '    '*depth + 'pop_alive(%s)'%v
 
     def deallocation_graph_for_type(self, translator, TYPE, var):
-        def compute_ll_ops(hop):
+        def compute_pop_alive_ll_ops(hop):
             hop.llops.extend(self.pop_alive(hop.args_v[1]))
             return hop.inputconst(hop.r_result.lowleveltype, hop.s_result.const)
         def pop_alive(var):
             pass
-        pop_alive.compute_ll_ops = compute_ll_ops
+        pop_alive.compute_ll_ops = compute_pop_alive_ll_ops
         pop_alive.llresult = lltype.Void
+        def compute_destroy_ll_ops(hop):
+            hop.llops.extend(self.free(hop.args_v[1]))
+            return hop.inputconst(hop.r_result.lowleveltype, hop.s_result.const)
+        def destroy(var):
+            pass
+        destroy.compute_ll_ops = compute_destroy_ll_ops
+        destroy.llresult = lltype.Void
 
         body = '\n'.join(self._deallocator_body_for_type('v', TYPE))
-        if not body:
-            return
-        src = 'def deallocator(v):\n' + body
-        d = {'pop_alive':pop_alive}
+        
+        src = 'def deallocator(v):\n' + body + '\n    destroy(v)\n'
+        d = {'pop_alive':pop_alive,
+             'destroy':destroy}
+        print
+        print src
+        print
         exec src in d
         this = d['deallocator']
         g = translator.rtyper.annotate_helper(this, [lltype.Ptr(TYPE)])
         translator.rtyper.specialize_more_blocks()
-        return g
+        opcount = 0
+        for block in g.iterblocks():
+            opcount += len(block.operations)
+        if opcount == 0:
+            return None
+        else:
+            return g

Modified: pypy/dist/pypy/rpython/memory/test/test_gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_gctransform.py	Wed Feb  1 15:45:59 2006
@@ -258,10 +258,15 @@
         t.view()
     return graph
 
-def dont_test_deallocator_simple():
+def test_deallocator_simple():
     S = lltype.GcStruct("S", ('x', lltype.Signed))
     dgraph = make_deallocator(S)
-    assert dgraph is None
+    ops = []
+    for block in dgraph.iterblocks():
+        ops.extend([op for op in block.operations if op.opname != 'same_as']) # XXX
+    assert len(ops) == 1
+    op, = ops
+    assert op.opname == 'gc_free'
 
 def test_deallocator_less_simple():
     TPtr = lltype.Ptr(lltype.GcStruct("T", ('a', lltype.Signed)))
@@ -272,8 +277,11 @@
         ('z', TPtr),
         )
     dgraph = make_deallocator(S)
+    ops = {}
+    for block in dgraph.iterblocks():
+        for op in block.operations:
+            ops.setdefault(op.opname, []).append(op)
 
-def test_deallocator_less_simple2():
-    S = lltype.GcArray(lltype.Ptr(lltype.GcStruct("S", ('x', lltype.Signed))))
-    dgraph = make_deallocator(S)
-    
+    assert len(ops['gc_pop_alive']) == 2
+    assert len(ops['getfield']) == 2
+    assert len(ops['gc_free']) == 1



More information about the Pypy-commit mailing list