[pypy-svn] r32902 - in pypy/dist/pypy/rpython/memory/gctransform2: . test
mwh at codespeak.net
mwh at codespeak.net
Thu Oct 5 11:08:58 CEST 2006
Author: mwh
Date: Thu Oct 5 11:08:57 2006
New Revision: 32902
Modified:
pypy/dist/pypy/rpython/memory/gctransform2/test/test_refcounting.py
pypy/dist/pypy/rpython/memory/gctransform2/test/test_transform.py
pypy/dist/pypy/rpython/memory/gctransform2/transform.py
Log:
add some more tests, and a couple of fixes thus required.
Modified: pypy/dist/pypy/rpython/memory/gctransform2/test/test_refcounting.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform2/test/test_refcounting.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform2/test/test_refcounting.py Thu Oct 5 11:08:57 2006
@@ -120,6 +120,44 @@
res = llinterp.eval_graph(graph, [0])
assert res == 3
+def test_simple_barrier():
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ T = lltype.GcStruct("T", ('s', lltype.Ptr(S)))
+ def f():
+ s1 = lltype.malloc(S)
+ s1.x = 1
+ s2 = lltype.malloc(S)
+ s2.x = 2
+ t = lltype.malloc(T)
+ t.s = s1
+ t.s = s2
+ return t
+ t, transformer = rtype_and_transform(f, [], RefcountingGCTransformer,
+ check=False)
+ graph = graphof(t, f)
+ ops = getops(graph)
+ assert len(ops['bare_getfield']) == 2
+ assert len(ops['bare_setfield']) == 4
+
+def test_arraybarrier():
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ A = lltype.GcArray(lltype.Ptr(S))
+ def f():
+ s1 = lltype.malloc(S)
+ s1.x = 1
+ s2 = lltype.malloc(S)
+ s2.x = 2
+ a = lltype.malloc(A, 1)
+ a[0] = s1
+ a[0] = s2
+ t, transformer = rtype_and_transform(f, [], RefcountingGCTransformer,
+ check=False)
+ graph = graphof(t, f)
+ ops = getops(graph)
+ assert len(ops['bare_getarrayitem']) == 2
+ assert len(ops['bare_setarrayitem']) == 2
+ assert len(ops['bare_setfield']) == 2
+
def make_deallocator(TYPE,
attr="static_deallocation_funcptr_for_type",
cls=RefcountingGCTransformer):
@@ -189,11 +227,11 @@
return lltype.getRuntimeTypeInfo(S)
qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
lltype.Ptr(lltype.RuntimeTypeInfo)),
- "type_info_S",
+ "type_info_S",
_callable=type_info_S)
dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
- lltype.Void),
- "destructor_funcptr",
+ lltype.Void),
+ "destructor_funcptr",
_callable=f)
pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
graph, t = make_deallocator(S)
@@ -215,25 +253,25 @@
return lltype.getRuntimeTypeInfo(T)
qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
lltype.Ptr(lltype.RuntimeTypeInfo)),
- "type_info_S",
+ "type_info_S",
_callable=type_info_S)
dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
- lltype.Void),
- "destructor_funcptr",
+ lltype.Void),
+ "destructor_funcptr",
_callable=f_S)
pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
- lltype.Void),
- "destructor_funcptr",
+ lltype.Void),
+ "destructor_funcptr",
_callable=f_S1)
pinf = lltype.attachRuntimeTypeInfo(S1, qp, destrptr=dp)
qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(T)],
lltype.Ptr(lltype.RuntimeTypeInfo)),
- "type_info_S",
+ "type_info_S",
_callable=type_info_T)
dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(T)],
- lltype.Void),
- "destructor_funcptr",
+ lltype.Void),
+ "destructor_funcptr",
_callable=f_T)
pinf = lltype.attachRuntimeTypeInfo(T, qp, destrptr=dp)
def f():
@@ -270,7 +308,7 @@
s_instance = t.annotator.bookkeeper.valueoftype(A)
TYPE = t.rtyper.getrepr(s_instance).lowleveltype.TO
p = transformer.dynamic_deallocation_funcptr_for_type(TYPE)
- t.rtyper.specialize_more_blocks()
+ t.rtyper.specialize_more_blocks()
def test_recursive_structure():
F = lltype.GcForwardReference()
Modified: pypy/dist/pypy/rpython/memory/gctransform2/test/test_transform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform2/test/test_transform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform2/test/test_transform.py Thu Oct 5 11:08:57 2006
@@ -207,3 +207,44 @@
return s.x
t, transformer = rtype_and_transform(g, [], _TestGCTransformer)
+def test_except_block():
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ def f(a, n):
+ if n == 0:
+ raise ValueError
+ a.x = 1
+ return a
+ def g(n):
+ a = lltype.malloc(S)
+ try:
+ return f(a, n).x
+ except ValueError:
+ return 0
+ t, transformer = rtype_and_transform(g, [int], _TestGCTransformer)
+
+def test_except_block2():
+ # the difference here is that f() returns Void, not a GcStruct
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ def f(a, n):
+ if n == 0:
+ raise ValueError
+ a.x = 1
+ def g(n):
+ a = lltype.malloc(S)
+ try:
+ f(a, n)
+ return a.x
+ except ValueError:
+ return 0
+ t, transformer = rtype_and_transform(g, [int], _TestGCTransformer)
+
+def test_no_livevars_with_exception():
+ def g():
+ raise TypeError
+ def f():
+ try:
+ g()
+ except TypeError:
+ return 0
+ return 1
+ t, transformer = rtype_and_transform(f, [], _TestGCTransformer)
Modified: pypy/dist/pypy/rpython/memory/gctransform2/transform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform2/transform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform2/transform.py Thu Oct 5 11:08:57 2006
@@ -313,7 +313,7 @@
if self.var_needs_set_transform(hop.spaceop.args[-1]):
self.transform_generic_set(hop)
else:
- self.default(hop)
+ hop.rename('bare_' + hop.spaceop.opname)
gct_setarrayitem = gct_setfield
def gct_safe_call(self, hop):
More information about the pypy-svn
mailing list