[pypy-commit] pypy custom-trace: A test in test_newgc too.
arigo
noreply at buildbot.pypy.org
Fri Jul 22 13:24:03 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: custom-trace
Changeset: r45870:8d3a4293d164
Date: 2011-07-21 21:35 +0200
http://bitbucket.org/pypy/pypy/changeset/8d3a4293d164/
Log: A test in test_newgc too.
diff --git a/pypy/translator/c/test/test_newgc.py b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -441,6 +441,45 @@
def test_del_raises(self):
self.run('del_raises') # does not raise
+ def define_custom_trace(cls):
+ from pypy.rpython.annlowlevel import llhelper
+ from pypy.rpython.lltypesystem import llmemory
+ #
+ S = lltype.GcStruct('S', ('x', llmemory.Address), rtti=True)
+ offset_of_x = llmemory.offsetof(S, 'x')
+ def customtrace(obj, prev):
+ if not prev:
+ return obj + offset_of_x
+ else:
+ return llmemory.NULL
+ CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
+ llmemory.Address)
+ customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
+ lltype.attachRuntimeTypeInfo(S, customtraceptr=customtraceptr)
+ #
+ def setup():
+ s = lltype.nullptr(S)
+ for i in range(10000):
+ t = lltype.malloc(S)
+ t.x = llmemory.cast_ptr_to_adr(s)
+ s = t
+ return s
+ def measure_length(s):
+ res = 0
+ while s:
+ res += 1
+ s = llmemory.cast_adr_to_ptr(s.x, lltype.Ptr(S))
+ return res
+ def f(n):
+ s1 = setup()
+ llop.gc__collect(lltype.Void)
+ return measure_length(s1)
+ return f
+
+ def test_custom_trace(self):
+ res = self.run('custom_trace', 0)
+ assert res == 10000
+
def define_weakref(cls):
import weakref
More information about the pypy-commit
mailing list