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

mwh at codespeak.net mwh at codespeak.net
Sat Jan 28 12:39:56 CET 2006


Author: mwh
Date: Sat Jan 28 12:39:54 2006
New Revision: 22770

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
   pypy/dist/pypy/rpython/memory/test/test_gctransform.py
Log:
(cfbolz, mwh)
Fix logic around handling gc pointer arguments to functions. 


Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Sat Jan 28 12:39:54 2006
@@ -37,6 +37,13 @@
 
     def transform_graph(self, graph):
         self.links_to_split = {} # link -> vars to pop_alive across the link
+
+        newops = []
+        for var in graph.startblock.inputargs:
+            if var_needsgc(var):
+                newops.extend(self.push_alive(var))
+        graph.startblock.operations[0:0] = newops
+        
         for block in graph.iterblocks():
             self.transform_block(block)
         for link, livecounts in self.links_to_split.iteritems():

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	Sat Jan 28 12:39:54 2006
@@ -5,11 +5,14 @@
 from pypy.objspace.flow.model import Variable
 
 def checkblock(block):
-    if not block.operations == ():
+    if block.operations == ():
         # a return/exception block -- don't want to think about them
         # (even though the test passes for somewhat accidental reasons)
         return
-    vars_in = len([v for v in block.inputargs if var_needsgc(v)])
+    if block.isstartblock:
+        refs_in = 0
+    else:
+        refs_in = len([v for v in block.inputargs if var_needsgc(v)])
     push_alives = len([op for op in block.operations
                        if op.opname.startswith('gc_push_alive')])
     pop_alives = len([op for op in block.operations
@@ -20,9 +23,9 @@
         # it's a block we inserted
         return
     for link in block.exits:
-        vars_out = len([v for v in link.args
+        refs_out = len([v for v in link.args
                         if isinstance(v, Variable) and var_needsgc(v)])
-        assert vars_in + push_alives + calls == pop_alives + vars_out
+        assert refs_in + push_alives + calls == pop_alives + refs_out
     
 
 def rtype_and_transform(func, inputtypes, transformcls):
@@ -34,6 +37,7 @@
     t.checkgraphs()
     for graph in t.graphs:
         for block in graph.iterblocks():
+            print graph, block, block.isstartblock
             checkblock(block)
     return t
 
@@ -159,3 +163,15 @@
                  if op.opname.startswith("gc_")]
     for op in gcops:
         assert op.opname.endswith("_pyobj")
+
+def test_pass_gc_pointer():
+    S = lltype.GcStruct("S", ('x', lltype.Signed))
+    def f(s):
+        s.x = 1
+    def g():
+        s = lltype.malloc(S)
+        f(s)
+        return s.x
+    t = rtype_and_transform(g, [], gctransform.GCTransformer)
+    ggraph = graphof(t, g)
+        



More information about the Pypy-commit mailing list