[pypy-svn] r22603 - in pypy/dist/pypy/rpython/rctypes: . test

gromit at codespeak.net gromit at codespeak.net
Tue Jan 24 17:06:28 CET 2006


Author: gromit
Date: Tue Jan 24 17:06:26 2006
New Revision: 22603

Modified:
   pypy/dist/pypy/rpython/rctypes/implementation.py
   pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
CHG: (stephan,gromit) Made c code generation work

Modified: pypy/dist/pypy/rpython/rctypes/implementation.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/implementation.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/implementation.py	Tue Jan 24 17:06:26 2006
@@ -10,7 +10,14 @@
 
 c_int.annotator_type = SomeInteger()
 c_int.ll_type = Signed
-
+c_char_p.annotator_type = None
+c_char_p.ll_type = None
+c_char_p.wrap_arg = staticmethod(
+        lambda ll_type, arg_name: "RPyString_AsString(%s)" % arg_name )
+POINTER( c_char ).annotator_type = None
+POINTER( c_char ).ll_type = None
+POINTER( c_char ).wrap_arg = staticmethod(
+        lambda ll_type, arg_name: "RPyString_AsString(%s)" % arg_name )
 
 class FunctionPointerTranslation(object):
 
@@ -29,7 +36,15 @@
                          convert_params=self.convert_params) 
 
         def convert_params(self, backend, param_info_list):
-            raise NotImplementedError
+            assert "c" == backend.lower()
+            assert self.argtypes is not None
+            answer = []
+            for ctype_type, (ll_type, arg_name) in zip(self.argtypes, param_info_list):
+                if ll_type == ctype_type.ll_type:
+                    answer.append(arg_name)
+                else:
+                    answer.append(ctype_type.wrap_arg(ll_type, arg_name))
+            return answer
 
 
 class RCDLL(CDLL):

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	Tue Jan 24 17:06:26 2006
@@ -22,8 +22,8 @@
 
         atoi = mylib.atoi
         atoi.restype = c_int
-        atoi.argstype = [c_char_p]
-        atoi.argstype = [POINTER(c_char)]
+        atoi.argtypes = [c_char_p]
+        atoi.argtypes = [POINTER(c_char)]
         def o_atoi(a):
            return atoi(a)
         mod.o_atoi = o_atoi
@@ -52,7 +52,7 @@
         t.buildrtyper().specialize()
         #d#t.view()
 
-    def x_test_compile_simple(self):
+    def test_compile_simple(self):
         fn = compile(o_atoi, [str])
         res = fn("42")
         assert res == 42



More information about the Pypy-commit mailing list