[pypy-svn] r20955 - in pypy/dist/pypy/translator/backendopt: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Dec 9 18:08:59 CET 2005
Author: cfbolz
Date: Fri Dec 9 18:08:58 2005
New Revision: 20955
Modified:
pypy/dist/pypy/translator/backendopt/malloc.py
pypy/dist/pypy/translator/backendopt/test/test_malloc.py
Log:
(johahn, cfbolz):
prevent the malloc removal to remove instances of classes that have a __del__
method (or other structs that have a destructor registered).
Modified: pypy/dist/pypy/translator/backendopt/malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/malloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/malloc.py Fri Dec 9 18:08:58 2005
@@ -119,6 +119,16 @@
continue # ok
return False
+ # 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:
+ return False
+ except (ValueError, AttributeError), e:
+ print e
+ pass
+
# success: replace each variable with a family of variables (one per field)
example = STRUCT._container_example()
flatnames = []
Modified: pypy/dist/pypy/translator/backendopt/test/test_malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_malloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_malloc.py Fri Dec 9 18:08:58 2005
@@ -1,6 +1,7 @@
+import py
from pypy.translator.backendopt.malloc import remove_simple_mallocs
from pypy.translator.backendopt.inline import inline_function
-from pypy.translator.translator import TranslationContext, graphof
+from pypy.translator.translator import TranslationContext, Translator, graphof
from pypy.objspace.flow.model import checkgraph, flatten, Block
from pypy.rpython.llinterp import LLInterpreter
@@ -109,3 +110,33 @@
keepalive_until_here(t)
return s*d
check(fn1, [int, int], [15, 10], 125)
+
+def test_dont_remove_with__del__():
+ import os
+ delcalls = [0]
+ class A(object):
+ nextid = 0
+ def __init__(self):
+ self.id = self.nextid
+ self.nextid += 1
+
+ def __del__(self):
+ delcalls[0] += 1
+ os.write(1, "__del__\n")
+
+ def f(x=int):
+ a = A()
+ i = 0
+ while i < x:
+ a = A()
+ os.write(1, str(delcalls[0]) + "\n")
+ i += 1
+ return 1
+ t = Translator(f)
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
+ graph = graphof(t, f)
+ t.backend_optimizations()
+ op = graph.startblock.exits[0].target.exits[1].target.operations[0]
+ assert op.opname == "malloc"
+
More information about the Pypy-commit
mailing list