[pypy-svn] r44961 - in pypy/dist/pypy/rpython/tool: . test

fijal at codespeak.net fijal at codespeak.net
Thu Jul 12 15:14:01 CEST 2007


Author: fijal
Date: Thu Jul 12 15:14:00 2007
New Revision: 44961

Modified:
   pypy/dist/pypy/rpython/tool/mkrffi.py
   pypy/dist/pypy/rpython/tool/test/test_mkrffi.py
Log:
Make this a bit less vague


Modified: pypy/dist/pypy/rpython/tool/mkrffi.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/mkrffi.py	(original)
+++ pypy/dist/pypy/rpython/tool/mkrffi.py	Thu Jul 12 15:14:00 2007
@@ -3,36 +3,26 @@
 import ctypes
 
 import py
-from py.code import Source
 
+def primitive_pointer_repr(tp_s):
+    return 'lltype.Ptr(lltype.FixedSizeArray(%s, 1))' % tp_s
+
+# XXX any automatic stuff here?
+SIMPLE_TYPE_MAPPING = {
+    ctypes.c_int : 'rffi.INT',
+    ctypes.c_voidp : primitive_pointer_repr('lltype.Void')
+}
+
+def proc_tp(tp):
+    try:
+        return SIMPLE_TYPE_MAPPING[tp]
+    except KeyError:
+        raise NotImplementedError("Not implemented mapping for %s" % tp)
 
 def proc_func(func):
     name = func.__name__
-    src = Source("""
-    c_%s = rffi.llexternal('%s', [rffi.INT], 
-    lltype.Ptr(lltype.FixedSizeArray(lltype.Void, 1)))
-    """%(name, name))
+    src = py.code.Source("""
+    c_%s = rffi.llexternal('%s', [%s], %s)
+    """%(name, name, ",".join([proc_tp(arg) for arg in func.argtypes]),
+         proc_tp(func.restype)))
     return src
-
-def proc_module(module):
-
-    ns = module.__dict__
-
-    for key, value in ns.items():
-        print "found:", key
-        if isinstance(value, ctypes._CFuncPtr):
-            proc_func(value)
-
-if __name__ == "__main__":
-    test_1()
-
-
-
-
-
-
-
-
-
-
-

Modified: pypy/dist/pypy/rpython/tool/test/test_mkrffi.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/test/test_mkrffi.py	(original)
+++ pypy/dist/pypy/rpython/tool/test/test_mkrffi.py	Thu Jul 12 15:14:00 2007
@@ -2,6 +2,7 @@
 import ctypes
 from pypy.rpython.tool.mkrffi import *
 from pypy.rpython.tool.test.test_c import TestBasic
+import py
 
 class TestMkrffi(TestBasic):
     def test_single_func(self):
@@ -10,10 +11,8 @@
         func.restype = ctypes.c_voidp
 
         src = proc_func(func)
-        assert isinstance(src, Source)
-        _src = Source("""
-        c_int_to_void_p = rffi.llexternal('int_to_void_p', [rffi.INT], 
-        lltype.Ptr(lltype.FixedSizeArray(lltype.Void, 1)))
+        _src = py.code.Source("""
+        c_int_to_void_p = rffi.llexternal('int_to_void_p', [rffi.INT], lltype.Ptr(lltype.FixedSizeArray(lltype.Void, 1)))
         """)
 
         assert src == _src, str(src) + "\n" + str(_src)



More information about the Pypy-commit mailing list