[pypy-svn] r45954 - in pypy/branch/pypy-more-rtti-inprogress/rpython/tool: . test

fijal at codespeak.net fijal at codespeak.net
Fri Aug 24 16:41:43 CEST 2007


Author: fijal
Date: Fri Aug 24 16:41:42 2007
New Revision: 45954

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/tool/mkrffi.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_mkrffi.py
Log:
Minor improvements


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/mkrffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/mkrffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/mkrffi.py	Fri Aug 24 16:41:42 2007
@@ -86,15 +86,21 @@
             return "lltype.Ptr(%s)" % self.proc_tp(tp._type_)
         elif issubclass(tp, ctypes.Structure):
             return self.proc_struct(tp)
+        elif issubclass(tp, ctypes.Array):
+            return "lltype.Ptr(lltype.Array(%s, hints={'nolength': True}))" % \
+                   self.proc_tp(tp._type_)
         raise NotImplementedError("Not implemented mapping for %s" % tp)
 
     def proc_func(self, func):
-        print "proc_func", func
         name = func.__name__
+        if not self.extra_args:
+            extra_args = ""
+        else:
+            extra_args = ", " + self.extra_args
         src = py.code.Source("""
-        %s = rffi.llexternal('%s', [%s], %s, %s)
+        %s = rffi.llexternal('%s', [%s], %s%s)
         """%(name, name, ", ".join([self.proc_tp(arg) for arg in func.argtypes]),
-             self.proc_tp(func.restype), self.extra_args))
+             self.proc_tp(func.restype), extra_args))
         self.source = py.code.Source(self.source, src)
 
     def proc_namespace(self, ns):
@@ -103,11 +109,7 @@
             if id(value) in exempt: 
                 continue
             if isinstance(value, ctypes._CFuncPtr):
-                print "func", key, value
-                try:    
-                    self.proc_func(value)
-                except NotImplementedError:
-                    print "skipped:", value
+                self.proc_func(value)
             #print value, value.__class__.__name__
 
     def compiled(self):

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_mkrffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_mkrffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_mkrffi.py	Fri Aug 24 16:41:42 2007
@@ -25,7 +25,7 @@
     rffi_source = RffiSource()    
     assert rffi_source.proc_tp(ctypes.POINTER(ctypes.c_uint)) == \
            "lltype.Ptr(lltype.Array(rffi.UINT, hints={'nolength': True}))"
-    rffi_source.proc_tp(random_structure)
+    src = rffi_source.proc_tp(random_structure)
     _src = py.code.Source("""
     random_structure = lltype.Struct('random_structure', ('one', rffi.INT), ('two', lltype.Ptr(lltype.Array(rffi.INT, hints={'nolength': True}))),  hints={'external':'C'})
     """)
@@ -33,6 +33,12 @@
     assert src.strip() == _src.strip(), str(src) + "\n" + str(_src)
     assert rffi_source.compiled()
 
+def test_proc_tp_array():
+    rffi_source = RffiSource()
+    src = rffi_source.proc_tp(ctypes.c_uint * 12)
+    _src = "lltype.Ptr(lltype.Array(rffi.UINT, hints={'nolength': True}))"
+    assert src == _src
+
 class TestMkrffi(TestBasic):
     def test_single_func(self):
         func = self.lib.int_to_void_p
@@ -42,7 +48,7 @@
         src = RffiSource()
         src.proc_func(func)
         _src = py.code.Source("""
-        int_to_void_p = rffi.llexternal('int_to_void_p', [rffi.INT], rffi.VOIDP, )
+        int_to_void_p = rffi.llexternal('int_to_void_p', [rffi.INT], rffi.VOIDP)
         """)
 
         assert src.source == _src, str(src) + "\n" + str(_src)
@@ -58,8 +64,9 @@
         _src = py.code.Source("""
         random_structure = lltype.Struct('random_structure', ('one', rffi.INT), ('two', lltype.Ptr(lltype.Array(rffi.INT, hints={'nolength': True}))),  hints={'external':'C'})
 
-        int_int_to_struct_p = rffi.llexternal('int_int_to_struct_p', [rffi.INT, rffi.INT], lltype.Ptr(random_structure), )
+        int_int_to_struct_p = rffi.llexternal('int_int_to_struct_p', [rffi.INT, rffi.INT], lltype.Ptr(random_structure))
         """)
         src = rffi_source.source
         assert src.strip() == _src.strip(), str(src) + "\n" + str(_src)
         assert rffi_source.compiled()
+        



More information about the Pypy-commit mailing list