[pypy-svn] r23385 - in pypy/dist/pypy: rpython/memory translator/c translator/c/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Feb 16 01:35:24 CET 2006
Author: cfbolz
Date: Thu Feb 16 01:35:21 2006
New Revision: 23385
Modified:
pypy/dist/pypy/rpython/memory/gctransform.py
pypy/dist/pypy/translator/c/gc.py
pypy/dist/pypy/translator/c/genc.py
pypy/dist/pypy/translator/c/test/test_boehm.py
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
(cfbolz, arigo):
added a minimal TransformerGcPolicy. added a test that just leaks some memory
(but actually compiles and runs)
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Thu Feb 16 01:35:21 2006
@@ -210,10 +210,12 @@
## print time.time() - T
return r
- def inittime_helper(self, ll_helper, args_s):
+ def inittime_helper(self, ll_helper, args_s, attach_empty_cleanup=False):
graph = self.annotate_helper(ll_helper, args_s)
self.translator.rtyper.specialize_more_blocks()
self.seen_graphs[graph] = True
+ if attach_empty_cleanup:
+ MinimalGCTransformer(self.translator).transform_graph(graph)
return const_funcptr_fromgraph(graph)
@@ -634,8 +636,6 @@
def ll_frameworkgc_setup():
stackbase = lladdress.raw_malloc(rootstacksize)
- if not stackbase:
- raise MemoryError
rootstack.top = stackbase
rootstack.base = stackbase
@@ -650,8 +650,8 @@
rootstack.top = top
return result
- self.frameworkgc_setup_ptr = self.inittime_helper(ll_frameworkgc_setup,
- [])
+ self.frameworkgc_setup_ptr = self.inittime_helper(
+ ll_frameworkgc_setup, [], attach_empty_cleanup=True)
self.push_root_ptr = self.inittime_helper(ll_push_root,
[annmodel.SomeAddress()])
self.pop_root_ptr = self.inittime_helper(ll_pop_root, [])
Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py (original)
+++ pypy/dist/pypy/translator/c/gc.py Thu Feb 16 01:35:21 2006
@@ -267,8 +267,19 @@
zero_malloc = RefcountingGcPolicy.zero_malloc.im_func
gc_libraries = RefcountingGcPolicy.gc_libraries.im_func
gc_startup_code = RefcountingGcPolicy.gc_startup_code.im_func
- rtti_type = RefcountingGcPolicy.rtti_type.im_func
def pre_pre_gc_code(self):
yield '#define USING_NO_GC'
+# the framework GC policy -- we are very optimistic tonight
+
+class FrameworkGcPolicy(NoneGcPolicy):
+ transformerclass = gctransform.FrameworkGCTransformer
+
+ def gc_startup_code(self):
+ fnptr = self.db.gctransformer.frameworkgc_setup_ptr.value
+ yield '%s();' % (self.db.get(fnptr),)
+
+ def OP_GC_RELOAD_POSSIBLY_MOVED(self, funcgen, op, err):
+ args = [funcgen.expr(v) for v in op.args]
+ return '%s = %s; /* for moving GCs */' % (args[1], args[0])
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Thu Feb 16 01:35:21 2006
@@ -44,6 +44,10 @@
# we need a concrete gcpolicy to do this
self.libraries += db.gcpolicy.gc_libraries()
+ # give the gc a chance to register interest in the start-up functions it
+ # need (we call this for its side-effects of db.get())
+ list(db.gcpolicy.gc_startup_code())
+
# XXX the following has the side effect to generate
# some needed things. Find out why.
pf = self.getentrypointptr()
Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py (original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py Thu Feb 16 01:35:21 2006
@@ -7,8 +7,8 @@
if not check_boehm_presence():
py.test.skip("Boehm GC not present")
-class TestUsingBoehm:
-
+class AbstractTestClass:
+
# deal with cleanups
def setup_method(self, meth):
self._cleanups = []
@@ -18,7 +18,6 @@
self._cleanups.pop()()
def getcompiled(self, func):
- from pypy.translator.c.gc import BoehmGcPolicy
t = TranslationContext(simplifying=True)
# builds starting-types from func_defs
argstypelist = []
@@ -31,7 +30,7 @@
t.buildrtyper().specialize()
t.checkgraphs()
def compile():
- cbuilder = CExtModuleBuilder(t, func, gcpolicy=BoehmGcPolicy)
+ cbuilder = CExtModuleBuilder(t, func, gcpolicy=self.gcpolicy)
c_source_filename = cbuilder.generate_source()
cbuilder.compile()
mod = cbuilder.isolated_import()
@@ -40,6 +39,9 @@
return skip_missing_compiler(compile)
+class TestUsingBoehm(AbstractTestClass):
+ from pypy.translator.c.gc import BoehmGcPolicy as gcpolicy
+
def test_malloc_a_lot(self):
def malloc_a_lot():
i = 0
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 Thu Feb 16 01:35:21 2006
@@ -184,3 +184,24 @@
fn = compile_func(f, [int])
res = fn(1)
assert res == 1
+
+# _______________________________________________________________
+# test framework
+
+from pypy.translator.c.test.test_boehm import AbstractTestClass
+
+class TestUsingFramework(AbstractTestClass):
+ from pypy.translator.c.gc import FrameworkGcPolicy as gcpolicy
+
+ def test_nongcing_gc(self):
+ def g(x):
+ return x + 1
+ class A(object):
+ pass
+ def f():
+ a = A()
+ a.b = g(1)
+ return a.b
+ fn = self.getcompiled(f)
+ res = fn()
+ assert res == 2
More information about the Pypy-commit
mailing list