[pypy-commit] pypy kill-someobject: (alex, arigo, fijal) fix the argtypes to ctypes

fijal noreply at buildbot.pypy.org
Mon Oct 8 13:14:51 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: kill-someobject
Changeset: r57893:b3393134a743
Date: 2012-10-08 10:32 +0200
http://bitbucket.org/pypy/pypy/changeset/b3393134a743/

Log:	(alex, arigo, fijal) fix the argtypes to ctypes

diff --git a/pypy/translator/c/test/test_genc.py b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -1,20 +1,28 @@
 import py
 import ctypes
 
+from pypy.annotation import model, signature
 from pypy.rpython.lltypesystem.lltype import *
+from pypy.rpython.lltypesystem import ll2ctypes
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c import genc
 from pypy.translator.interactive import Translation
 from pypy.rlib.entrypoint import entrypoint
 from pypy.tool.nullpath import NullPyPathLocal
 
+
+def cast_to_ctypes(type):
+    s_tp = signature.annotation(type)
+    ll_tp = model.annotation_to_lltype(s_tp)
+    return ll2ctypes.get_ctypes_type(ll_tp)
+
 def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
             annotatorpolicy=None):
     t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
                     policy=annotatorpolicy)
     if not backendopt:
         t.disable(["backendopt_lltype"])
-    t.annotate()
+    s_res = t.annotate()
     # XXX fish
     t.driver.config.translation.countmallocs = True
     so_name = t.compile_c()
@@ -28,7 +36,10 @@
         for arg, argtype in zip(args, argtypes):
             assert isinstance(arg, argtype)
         dll = ctypes.CDLL(str(so_name))
-        return getattr(dll, 'pypy_g_' + fn.__name__)(*args)
+        func = getattr(dll, 'pypy_g_' + fn.__name__)
+        func.argtypes = [cast_to_ctypes(arg) for arg in argtypes]
+        func.restype = cast_to_ctypes(s_res)
+        return func(*args)
     f.__name__ = fn.__name__
     return f
 


More information about the pypy-commit mailing list