[pypy-svn] r74979 - in pypy/branch/fast-ctypes/pypy/module/jitffi: . test

getxsick at codespeak.net getxsick at codespeak.net
Mon May 31 18:41:09 CEST 2010


Author: getxsick
Date: Mon May 31 18:41:07 2010
New Revision: 74979

Modified:
   pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
   pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
Log:
return correct type of result

Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	Mon May 31 18:41:07 2010
@@ -5,7 +5,8 @@
 from pypy.rlib import rdynload
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.jit.backend.x86.runner import CPU
-from pypy.jit.metainterp.history import LoopToken, BasicFailDescr, BoxInt
+from pypy.jit.metainterp.history import LoopToken, BasicFailDescr
+from pypy.jit.metainterp.history import BoxInt, BoxFloat, BoxPtr
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.metainterp.typesystem import deref
 
@@ -20,8 +21,18 @@
         self.space = space
         self.cpu = CPU(None, None)
 
-    def call(self, space, func, a, b):  # XXX temporary fixed number of func args (ints)
-                                        # result_type argument?
+    def call(self, space, func, a, b, res_type):  # XXX temporary fixed number of func args (ints)
+        if res_type == 'int':
+            bres = BoxInt()
+        elif res_type == 'float':
+            bres = BoxFloat()
+        elif res_type == 'ref':
+            bres = BoxPtr()
+        elif res_type == 'void':
+            bres = None
+        else:
+            raise ValueError(res_type)
+
         try:
             addr = rffi.cast(lltype.Signed, rdynload.dlsym(self.lib, func))
         except KeyError:
@@ -31,7 +42,6 @@
         bfuncaddr = BoxInt(addr)
         barg0 = BoxInt(a)
         barg1 = BoxInt(b)
-        bres = BoxInt()
 
         FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Signed],
                           lltype.Signed))
@@ -56,8 +66,19 @@
             self.guard_failed = False
         else:
             self.guard_failed = True
-        return space.wrap(BoxInt(self.cpu.get_latest_value_int(0)).getint())
-    call.unwrap_spec = ['self', ObjSpace, str, int, int]
+
+        if res_type == 'int':
+            r = BoxInt(self.cpu.get_latest_value_int(0)).getint()
+        elif res_type == 'float':
+            r = BoxFloat(self.cpu.get_latest_value_float(0)).getfloat()
+        elif res_type == 'ref':
+            r = BoxPtr(self.cpu.get_latest_value_ref(0)).getref()
+        elif res_type == 'void':
+            r = None
+        else:
+            raise ValueError(res_type)
+        return space.wrap(r)
+    call.unwrap_spec = ['self', ObjSpace, str, int, int, str]
 
 def descr_new_cdll(space, w_type, name):
     try:

Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	Mon May 31 18:41:07 2010
@@ -14,7 +14,13 @@
         {
            return a+b;
         }
-        '''))
+
+        float return_float(int a, int b)
+        {
+           return a+b;
+        }
+        '''
+        ))
 
         symbols = ["add_integers"]
         eci = ExternalCompilationInfo(export_symbols=symbols)
@@ -32,9 +38,14 @@
         import jitffi
         lib = jitffi.CDLL(self.lib_name)
 
-        res = lib.call('add_integers', 1, 2)
+        res = lib.call('add_integers', 1, 2, 'int')
         assert 3 == res
-        res = lib.call('add_integers', -1, 2)
+        assert isinstance(res, int)
+        res = lib.call('add_integers', -1, 2, 'int')
         assert 1 == res
-        res = lib.call('add_integers', 0, 0)
+        res = lib.call('add_integers', 0, 0, 'int')
         assert 0 == res
+
+        res = lib.call('return_float', 1, 2, 'float')
+        assert 3.0 == res
+        assert isinstance(res, float)



More information about the Pypy-commit mailing list