[pypy-svn] r25936 - pypy/dist/pypy/rpython/rctypes/test

arigo at codespeak.net arigo at codespeak.net
Tue Apr 18 11:59:34 CEST 2006


Author: arigo
Date: Tue Apr 18 11:59:33 2006
New Revision: 25936

Added:
   pypy/dist/pypy/rpython/rctypes/test/test_overhead.py   (contents, props changed)
Log:
Yay!  malloc removal can now remove all this rctypes cruft,
at least in this simple case.


Added: pypy/dist/pypy/rpython/rctypes/test/test_overhead.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/rctypes/test/test_overhead.py	Tue Apr 18 11:59:33 2006
@@ -0,0 +1,39 @@
+"""
+Check that backendopt is able to remove most of the overhead introduced
+by the rctypes rtyping.
+"""
+
+import pypy.rpython.rctypes.implementation
+from pypy import conftest
+from pypy.rpython.test.test_llinterp import gengraph
+from pypy.translator.backendopt.all import backend_optimizations
+
+try:
+    import ctypes
+except ImportError:
+    py.test.skip("this test needs ctypes installed")
+
+from ctypes import c_int
+
+
+def find_mallocs(func, argtypes):
+    t, typer, graph = gengraph(func, argtypes)
+    backend_optimizations(t)
+    if conftest.option.view:
+        t.view()
+
+    result = []
+    for block in t.graphs[0].iterblocks():
+        for op in block.operations:
+            if op.opname.startswith('malloc'):
+                result.append(op.result.concretetype)
+    return result
+
+
+def test_simple():
+    def func(n):
+        x = c_int(n)
+        return x.value
+
+    mallocs = find_mallocs(func, [int])
+    assert not mallocs



More information about the Pypy-commit mailing list