[pypy-svn] r48351 - in pypy/dist/pypy/translator/backendopt: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Nov 7 11:21:50 CET 2007


Author: cfbolz
Date: Wed Nov  7 11:21:49 2007
New Revision: 48351

Modified:
   pypy/dist/pypy/translator/backendopt/coalloc.py
   pypy/dist/pypy/translator/backendopt/test/test_coalloc.py
Log:
test + fix


Modified: pypy/dist/pypy/translator/backendopt/coalloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/coalloc.py	(original)
+++ pypy/dist/pypy/translator/backendopt/coalloc.py	Wed Nov  7 11:21:49 2007
@@ -348,7 +348,7 @@
 def do_coalloc(adi, graph, setblock, setop, fromcreps, tocrep):
     def find_coalloc_var():
         if block is setblock and seen_setvar:
-            return fromvar
+            return setop.args[0]
         for fromcrep in fromcreps:
             if fromcrep.creation_method == "constant":
                 return fromcrep.constant
@@ -362,27 +362,28 @@
                     return var
         return None
     result = 0
-    seen_setvar = False
-    for block, op in graph.iterblockops():
-        if op.result is setop.args[0]:
-            seen_setvar = True
-        if not op.opname.startswith("malloc"):
-            continue
-        if adi.getstate(op.result).get_crep(checksingle=True) is not tocrep:
-            continue
-        TYPE = op.result.concretetype.TO
-        # must not remove mallocs of structures that a destructor
-        if hasdestructor(TYPE):
-            continue
-        coallocvar = find_coalloc_var()
-        if coallocvar is None:
-            continue
-        op.opname = "coalloc" + op.opname[len("malloc"):]
-        op.args.insert(1, coallocvar)
-        mallocvarstate = adi.getstate(op.result)
-        malloccrep = mallocvarstate.get_crep(checksingle=True)
-        malloccrep.creation_method = "coalloc"
-        result += 1
+    for block in graph.iterblocks():
+        seen_setvar = False
+        for op in block.operations:
+            if block is setblock and op.result is setop.args[0]:
+                seen_setvar = True
+            if not op.opname.startswith("malloc"):
+                continue
+            if adi.getstate(op.result).get_crep(checksingle=True) is not tocrep:
+                continue
+            TYPE = op.result.concretetype.TO
+            # must not remove mallocs of structures that a destructor
+            if hasdestructor(TYPE):
+                continue
+            coallocvar = find_coalloc_var()
+            if coallocvar is None:
+                continue
+            op.opname = "coalloc" + op.opname[len("malloc"):]
+            op.args.insert(1, coallocvar)
+            mallocvarstate = adi.getstate(op.result)
+            malloccrep = mallocvarstate.get_crep(checksingle=True)
+            malloccrep.creation_method = "coalloc"
+            result += 1
     return result
 
 def hasdestructor(STRUCT):

Modified: pypy/dist/pypy/translator/backendopt/test/test_coalloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_coalloc.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_coalloc.py	Wed Nov  7 11:21:49 2007
@@ -254,6 +254,19 @@
     # this should really be mustremove=2, but for now I am happy
     t = check_malloc_to_coalloc(f, [], [], 1, must_remove=1)
 
+def test_coalloc_in_setblock_old():
+    class A(object):
+        pass
+    def g():
+        return A()
+    def f():
+        a = g()
+        a1 = A()
+        a.a = a1
+        return 1
+    t = check_malloc_to_coalloc(f, [], [], 1, must_remove=1)
+
+
 def test_nocoalloc_finalizer():
     class A(object):
         def __del__(self):



More information about the Pypy-commit mailing list