[pypy-commit] pypy kill-someobject: merge

fijal noreply at buildbot.pypy.org
Fri Oct 12 16:58:34 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: kill-someobject
Changeset: r58060:acc09674af79
Date: 2012-10-12 16:58 +0200
http://bitbucket.org/pypy/pypy/changeset/acc09674af79/

Log:	merge

diff --git a/pypy/translator/c/test/test_refcount.py b/pypy/translator/c/test/test_refcount.py
--- a/pypy/translator/c/test/test_refcount.py
+++ b/pypy/translator/c/test/test_refcount.py
@@ -3,33 +3,12 @@
 
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c import genc
+from pypy.translator.c.test.test_genc import compile
 from pypy.rpython.lltypesystem import lltype
 from pypy import conftest
 
-def compile_func(fn, inputtypes, t=None, gcpolicy="ref"):
-    from pypy.config.pypyoption import get_pypy_config
-    config = get_pypy_config(translating=True)
-    config.translation.gc = gcpolicy
-    config.translation.countmallocs = True
-    if t is None:
-        t = TranslationContext(config=config)
-    if inputtypes is not None:
-        t.buildannotator().build_types(fn, inputtypes)
-        t.buildrtyper().specialize()
-    builder = genc.CExtModuleBuilder(t, fn, config=config)
-    builder.generate_source()
-    builder.compile()
-    if conftest.option.view:
-        t.view()
-    compiled_fn = builder.get_entry_point()
-    malloc_counters = builder.get_malloc_counters()
-    def checking_fn(*args, **kwds):
-        try:
-            return compiled_fn(*args, **kwds)
-        finally:
-            mallocs, frees = malloc_counters()
-            assert mallocs == frees
-    return checking_fn
+def compile_func(func, args):
+    return compile(func, args, gcpolicy='ref')
 
 def test_something():
     def f():
@@ -129,35 +108,35 @@
     assert fn(0) == 5
 
 def test_del_basic():
-    for gcpolicy in ["ref"]: #, "framework"]:
-        S = lltype.GcStruct('S', ('x', lltype.Signed), rtti=True)
-        TRASH = lltype.GcStruct('TRASH', ('x', lltype.Signed))
-        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)
+    py.test.skip("xxx fix or kill")
+    S = lltype.GcStruct('S', ('x', lltype.Signed), rtti=True)
+    TRASH = lltype.GcStruct('TRASH', ('x', lltype.Signed))
+    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)
+        # llop.gc__collect(lltype.Void)
+        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, gcpolicy=gcpolicy)
+    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
+    res = fn(123)
+    assert res == 124
 
 def test_del_catches():
     import os
@@ -179,7 +158,7 @@
         return a.b
     fn = compile_func(f, [int])
     assert fn(0) == 1
-    assert py.test.raises(TypeError, fn, 1)
+    fn(1, expected_exception_name="TypeError")
 
 def test_del_raises():
     class B(object):
@@ -210,29 +189,3 @@
     fn = compile_func(f, [int])
     res = fn(1)
     assert res == 1
-
-def test_wrong_startblock_incref():
-    class B(object):
-        pass
-    def g(b):
-        while True:
-            b.x -= 10
-            if b.x < 0:
-                return b.x
-    def f(n):
-        b = B()
-        b.x = n
-        return g(b)
-
-    # XXX obscure: remove the first empty block in the graph of 'g'
-    t = TranslationContext()
-    graph = t.buildflowgraph(g)
-    assert graph.startblock.operations == []
-    graph.startblock = graph.startblock.exits[0].target
-    from pypy.objspace.flow.model import checkgraph
-    checkgraph(graph)
-    t._prebuilt_graphs[g] = graph
-
-    fn = compile_func(f, [int], t)
-    res = fn(112)
-    assert res == -8
diff --git a/pypy/translator/c/test/test_rtagged.py b/pypy/translator/c/test/test_rtagged.py
--- a/pypy/translator/c/test/test_rtagged.py
+++ b/pypy/translator/c/test/test_rtagged.py
@@ -67,7 +67,7 @@
 from pypy import conftest
 
 def test_tagged_boehm():
-    t = Translation(entry_point, standalone=True, gc='boehm', taggedpointers=True)
+    t = Translation(entry_point, gc='boehm', taggedpointers=True)
     try:
         exename = str(t.compile_c())
     finally:
diff --git a/pypy/translator/c/test/test_standalone.py b/pypy/translator/c/test/test_standalone.py
--- a/pypy/translator/c/test/test_standalone.py
+++ b/pypy/translator/c/test/test_standalone.py
@@ -131,14 +131,14 @@
             os.write(1, str(tot))
             return 0
         from pypy.translator.interactive import Translation
-        t = Translation(entry_point, backend='c', standalone=True)
+        t = Translation(entry_point, backend='c')
         # no counters
         t.backendopt(inline_threshold=100, profile_based_inline="500")
         exe = t.compile()
         out = py.process.cmdexec("%s 500" % exe)
         assert int(out) == 500*501/2
 
-        t = Translation(entry_point, backend='c', standalone=True)
+        t = Translation(entry_point, backend='c')
         # counters
         t.backendopt(inline_threshold=all.INLINE_THRESHOLD_FOR_TEST*0.5,
                      profile_based_inline="500")
@@ -171,13 +171,13 @@
             return 0
         from pypy.translator.interactive import Translation
         # XXX this is mostly a "does not crash option"
-        t = Translation(entry_point, backend='c', standalone=True, profopt="100")
+        t = Translation(entry_point, backend='c', profopt="100")
         # no counters
         t.backendopt()
         exe = t.compile()
         out = py.process.cmdexec("%s 500" % exe)
         assert int(out) == 500*501/2
-        t = Translation(entry_point, backend='c', standalone=True, profopt="100",
+        t = Translation(entry_point, backend='c', profopt="100",
                         noprofopt=True)
         # no counters
         t.backendopt()
@@ -208,12 +208,12 @@
             return 0
         from pypy.translator.interactive import Translation
         # XXX this is mostly a "does not crash option"
-        t = Translation(entry_point, backend='c', standalone=True, profopt="")
+        t = Translation(entry_point, backend='c', profopt="")
         # no counters
         t.backendopt()
         exe = t.compile()
         #py.process.cmdexec(exe)
-        t = Translation(entry_point, backend='c', standalone=True, profopt="",
+        t = Translation(entry_point, backend='c', profopt="",
                         noprofopt=True)
         # no counters
         t.backendopt()
diff --git a/pypy/translator/c/test/test_symbolic.py b/pypy/translator/c/test/test_symbolic.py
--- a/pypy/translator/c/test/test_symbolic.py
+++ b/pypy/translator/c/test/test_symbolic.py
@@ -1,15 +1,9 @@
 from pypy.translator.interactive import Translation
+from pypy.translator.c.test.test_genc import compile
 from pypy import conftest
 from pypy.rpython.lltypesystem import llmemory, lltype
 from pypy.rlib.objectmodel import ComputedIntSymbolic
 
-def getcompiled(f, args):
-    t = Translation(f, args)
-    fn = t.compile_c()
-    if conftest.option.view:
-        t.view()
-    return fn, t
-
 def test_offsetof():
     STRUCT = lltype.GcStruct("s", ("x", lltype.Signed), ("y", lltype.Signed))
     offsetx = llmemory.offsetof(STRUCT, 'x')
@@ -21,7 +15,7 @@
         result = (adr + offsetx).signed[0]
         (adr + offsety).signed[0] = 2
         return result * 10 + s.y
-    fn, t = getcompiled(f, [])
+    fn = compile(f, [])
     res = fn()
     assert res == 12
 
@@ -31,7 +25,7 @@
     signedsize = llmemory.sizeof(lltype.Signed)
     def f():
         return arraysize-signedsize*10
-    fn, t = getcompiled(f, [])
+    fn = compile(f, [])
     res = fn()
     assert res == 0
 
@@ -51,7 +45,7 @@
         for i in range(5):
             result = 10 * result + a[i]
         return result
-    fn, t = getcompiled(f, [])
+    fn = compile(f, [])
     res = fn()
     assert res == 1234501234
 
@@ -71,7 +65,7 @@
         for i in range(5):
             result = 10 * result + a[i]
         return result
-    fn, t = getcompiled(f, [])
+    fn = compile(f, [])
     res = fn()
     assert res == 1234501234
 
@@ -88,7 +82,7 @@
         result = (adr + offsety).signed[0] * 10 + int(offsety < sizeofs)
         llmemory.raw_free(adr)
         return result
-    fn, t = getcompiled(f, [])
+    fn = compile(f, [])
     res = fn()
     assert res == 51
 
@@ -98,7 +92,7 @@
         assert not too_early
         return 7
     k = ComputedIntSymbolic(compute_fn)
-    def f():
+    def f(ignored):
         return k*6
 
     t = Translation(f)
@@ -106,6 +100,6 @@
     if conftest.option.view:
         t.view()
     too_early = False
-    fn = t.compile_c()
-    res = fn()
+    fn = compile(f, [int])
+    res = fn(0)
     assert res == 42


More information about the pypy-commit mailing list