[pypy-svn] r76548 - in pypy/branch/fast-ctypes/pypy/rlib: . test

getxsick at codespeak.net getxsick at codespeak.net
Mon Aug 9 18:28:28 CEST 2010


Author: getxsick
Date: Mon Aug  9 18:28:27 2010
New Revision: 76548

Modified:
   pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
   pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
Log:
add support for C pointers as func arguments


Modified: pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py	Mon Aug  9 18:28:27 2010
@@ -61,6 +61,8 @@
                 bargs.append(BoxInt())
             elif arg == 'f':
                 bargs.append(BoxFloat())
+            elif arg == 'p':
+                bargs.append(BoxInt())
             else:
                 raise ValueError(arg)
 
@@ -120,6 +122,7 @@
         self.cpu.set_future_value_int(self.esp, value)
         self.esp += 1
     push_funcaddr = push_int
+    push_ref = push_int
 
     def push_float(self, value):
         self.cpu.set_future_value_float(self.esp, value)

Modified: pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py	Mon Aug  9 18:28:27 2010
@@ -52,11 +52,16 @@
             int c;
             c = a + b;
         }
+        int return_ptrvalue(int *a)
+        {
+            return *a;
+        }
         '''
         ))
 
         symbols = ['add_integers', 'add_floats', 'add_intfloat',
-                   'return_float', 'max3', 'fvoid', 'return_void']
+                   'return_float', 'max3', 'fvoid', 'return_void',
+                   'return_ptrvalue']
         eci = ExternalCompilationInfo(export_symbols=symbols)
 
         return str(platform.compile([c_file], eci, 'x1', standalone=False))
@@ -167,6 +172,16 @@
         func.push_float(1.3)
         assert func.call() == 1
 
+    def test_ptrargs(self):
+        lib = rjitffi.CDLL(self.lib_name)
+
+        func = lib.get('return_ptrvalue', ['p'], 'i', self.push_result)
+        intp = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+        intp[0] = 5
+        func.push_ref(rffi.cast(lltype.Signed, intp))
+        lltype.free(intp, flavor='raw')
+        assert func.call() == 5
+
     def test_nocache(self):
         lib = rjitffi.CDLL(self.lib_name)
 



More information about the Pypy-commit mailing list