[pypy-svn] r26922 - pypy/dist/pypy/translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Sun May 7 10:53:52 CEST 2006
Author: arigo
Date: Sun May 7 10:53:50 2006
New Revision: 26922
Modified:
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
(pedronis, arigo)
Added a passing test checking the basic __del__ support of the framework gc.
Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py Sun May 7 10:53:50 2006
@@ -15,8 +15,9 @@
def compile_func(fn, inputtypes, t=None):
if t is None:
t = TranslationContext()
- t.buildannotator().build_types(fn, inputtypes)
- t.buildrtyper().specialize()
+ if inputtypes is not None:
+ t.buildannotator().build_types(fn, inputtypes)
+ t.buildrtyper().specialize()
builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gc.RefcountingGcPolicy)
builder.generate_source(defines={'COUNT_OP_MALLOCS': 1})
builder.compile()
@@ -141,6 +142,34 @@
assert fn(1) == 4
assert fn(0) == 5
+def test_del_basic():
+ S = lltype.GcStruct('S', ('x', lltype.Signed))
+ lltype.attachRuntimeTypeInfo(S)
+ GLOBAL = lltype.Struct('GLOBAL', ('x', lltype.Signed))
+ glob = lltype.malloc(GLOBAL, immortal=True)
+ def destructor(s):
+ glob.x = s.x + 1
+ def type_info_S(s):
+ return lltype.getRuntimeTypeInfo(S)
+
+ def g(n):
+ s = lltype.malloc(S)
+ s.x = n
+ # now 's' should go away
+ def entrypoint(n):
+ g(n)
+ return glob.x
+
+ t = TranslationContext()
+ t.buildannotator().build_types(entrypoint, [int])
+ rtyper = t.buildrtyper()
+ destrptr = rtyper.annotate_helper_fn(destructor, [lltype.Ptr(S)])
+ rtyper.attachRuntimeTypeInfoFunc(S, type_info_S, destrptr=destrptr)
+ rtyper.specialize()
+ fn = compile_func(entrypoint, None, t)
+
+ res = fn(123)
+ assert res == 124
def test_del_catches():
import os
More information about the Pypy-commit
mailing list