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

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 17 15:28:14 CET 2006


Author: cfbolz
Date: Tue Jan 17 15:28:12 2006
New Revision: 22253

Modified:
   pypy/dist/pypy/translator/backendopt/escape.py
   pypy/dist/pypy/translator/backendopt/test/test_escape.py
Log:
as long as gc interaction is unclear at best, don't put allocations of objects
to the stack that have a deallocator.


Modified: pypy/dist/pypy/translator/backendopt/escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/escape.py	Tue Jan 17 15:28:12 2006
@@ -424,6 +424,14 @@
         for block in graph.iterblocks():
             for op in block.operations:
                 if op.opname == 'malloc':
+                    STRUCT = op.args[0].value
+                    # must not remove mallocs of structures that have a RTTI with a destructor
+                    try:
+                        destr_ptr = lltype.getRuntimeTypeInfo(STRUCT)._obj.destructor_funcptr
+                        if destr_ptr:
+                            continue
+                    except (ValueError, AttributeError), e:
+                        pass
                     varstate = aib.getstate(op.result)
                     assert len(varstate.creation_points) == 1
                     crep = varstate.creation_points.keys()[0]

Modified: pypy/dist/pypy/translator/backendopt/test/test_escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_escape.py	Tue Jan 17 15:28:12 2006
@@ -483,3 +483,17 @@
     t = check_malloc_removal(f, [int], [3], 3, must_remove=False)
     graph = graphof(t, f)
     assert graph.startblock.exits[0].target.exits[0].target.operations[0].opname == "malloc"
+
+def test_dont_remove_del_objects():
+    class A(object):
+        def __del__(self):
+            pass
+    def f():
+        a = A()
+        a.i = 1
+        return a.i        
+    t = check_malloc_removal(f, [], [], 1, must_remove=False)
+    graph = graphof(t, f)
+    assert graph.startblock.operations[0].opname == "malloc"
+   
+



More information about the Pypy-commit mailing list