[pypy-svn] r26924 - pypy/dist/pypy/translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Sun May 7 11:06:45 CEST 2006
Author: arigo
Date: Sun May 7 11:06:45 2006
New Revision: 26924
Modified:
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
(pedronis, arigo)
A third different style of test in the same file. :-(
Commented out until the FrameworkGcPolicy has support for
destructors.
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 11:06:45 2006
@@ -12,13 +12,13 @@
from pypy import conftest
-def compile_func(fn, inputtypes, t=None):
+def compile_func(fn, inputtypes, t=None, gcpolicy=gc.RefcountingGcPolicy):
if t is None:
t = TranslationContext()
if inputtypes is not None:
t.buildannotator().build_types(fn, inputtypes)
t.buildrtyper().specialize()
- builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gc.RefcountingGcPolicy)
+ builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gcpolicy)
builder.generate_source(defines={'COUNT_OP_MALLOCS': 1})
builder.compile()
builder.import_module()
@@ -143,33 +143,36 @@
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)
+ for gcpolicy in [gc.RefcountingGcPolicy]: #, gc.FrameworkGcPolicy]:
+ S = lltype.GcStruct('S', ('x', lltype.Signed))
+ TRASH = lltype.GcStruct('TRASH', ('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)
+ # llop.gc__collect(lltype.Void)
+ return glob.x
- 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)
+ 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, gcpolicy=gcpolicy)
- res = fn(123)
- assert res == 124
+ res = fn(123)
+ assert res == 124
def test_del_catches():
import os
More information about the Pypy-commit
mailing list