[pypy-svn] r76050 - in pypy/branch/fast-ctypes/pypy: module/jitffi rlib rlib/test

getxsick at codespeak.net getxsick at codespeak.net
Thu Jul 8 20:06:49 CEST 2010


Author: getxsick
Date: Thu Jul  8 20:06:47 2010
New Revision: 76050

Modified:
   pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
   pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
   pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
Log:
drop boxing for returned results. push results to app-level by the caller


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	Thu Jul  8 20:06:47 2010
@@ -91,8 +91,7 @@
                             space.wrap('Unsupported type of argument: %s'
                                         % self.args_type[0]))
                 i += 1
-        res = self.rget.call()
-        return space.wrap(res.value)
+        return self.rget.call(space.wrap)
 
 def W_Get___new__(space, w_type, cpu, lib, func, args_type, res_type):
     try:

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	Thu Jul  8 20:06:47 2010
@@ -98,20 +98,20 @@
             cache.append(_Func(self.args_type, self.res_type, self.looptoken))
         self.setup_stack()
 
-    def call(self):
+    def call(self, push_result):
         res = self.cpu.execute_token(self.looptoken)
 
         if self.res_type == 'i':
-            r = ReturnInt(self.cpu.get_latest_value_int(0))
+            r = push_result(self.cpu.get_latest_value_int(0))
         elif self.res_type == 'f':
-            r = ReturnFloat(self.cpu.get_latest_value_float(0))
+            r = push_result(self.cpu.get_latest_value_float(0))
         elif self.res_type == 'p':
-            r = ReturnPtr(self.cpu.get_latest_value_ref(0))
+            r = push_result(self.cpu.get_latest_value_ref(0))
         elif self.res_type == 'v':
-            r = ReturnNone(None)
+            r = None
         else:
             raise ValueError(self.res_type)
-
+        
         self.setup_stack() # clean up the stack
         return r
 
@@ -140,19 +140,3 @@
         self.args_type = args_type
         self.res_type = res_type
         self.looptoken = looptoken
-
-class Return(object):
-    def __init__(self, value):
-        self.value = value
-
-class ReturnInt(Return):
-    pass
-
-class ReturnFloat(Return):
-    pass
-
-class ReturnPtr(Return):
-    pass
-
-class ReturnNone(Return):
-    pass

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	Thu Jul  8 20:06:47 2010
@@ -62,6 +62,9 @@
     def setup_class(cls):
         cls.lib_name = cls.preprare_c_example()
 
+    def push_result(self, value): # mock function
+        return value
+
     def test_missing_lib(self):
         py.test.raises(OSError, rjitffi.CDLL, 'xxxfoo888baryyy')
 
@@ -71,44 +74,44 @@
         func = lib.get('add_integers', ['i', 'i'], 'i')
         func.push_int(1)
         func.push_int(2)
-        assert func.call().value == 3
+        assert func.call(self.push_result) == 3
 
         func = lib.get('add_integers', ['i', 'i'], 'i')
         func.push_int(-1)
         func.push_int(2)
-        assert func.call().value == 1
+        assert func.call(self.push_result) == 1
 
         func = lib.get('add_integers', ['i', 'i'], 'i')
         func.push_int(0)
         func.push_int(0)
-        assert func.call().value == 0
+        assert func.call(self.push_result) == 0
 
         func = lib.get('max3', ['i', 'i', 'i'], 'i')
         func.push_int(2)
         func.push_int(8)
         func.push_int(3)
-        assert func.call().value == 8
+        assert func.call(self.push_result) == 8
 
         func = lib.get('add_floats', ['f', 'f'], 'f')
         func.push_float(1.2)
         func.push_float(1.5)
-        assert func.call().value == 2.7
+        assert func.call(self.push_result) == 2.7
 
     def test_get_void(self):
         lib = rjitffi.CDLL(self.lib_name)
 
         func = lib.get('fvoid', [], 'i')
-        assert func.call().value == 1
+        assert func.call(self.push_result) == 1
 
         func = lib.get('return_void', ['i', 'i'], 'v')
         func.push_int(1)
         func.push_int(2)
-        assert func.call().value is None
+        assert func.call(self.push_result) is None
 
         func = lib.get('return_void', ['i', 'i'])
         func.push_int(1)
         func.push_int(2)
-        assert func.call().value is None
+        assert func.call(self.push_result) is None
 
     def test_various_type_args(self):
         lib = rjitffi.CDLL(self.lib_name)
@@ -116,12 +119,12 @@
         func = lib.get('add_intfloat', ['i', 'f'], 'i')
         func.push_int(1)
         func.push_float(2.9)
-        assert func.call().value == 3
+        assert func.call(self.push_result) == 3
         
         # stack is cleaned up after calling
         func.push_int(0)
         func.push_float(1.3)
-        assert func.call().value == 1
+        assert func.call(self.push_result) == 1
 
     def test_undefined_func(self):
         lib = rjitffi.CDLL(self.lib_name)



More information about the Pypy-commit mailing list