[pypy-svn] r76437 - in pypy/branch/fast-ctypes/pypy: module/jitffi rlib rlib/test
getxsick at codespeak.net
getxsick at codespeak.net
Mon Aug 2 19:43:17 CEST 2010
Author: getxsick
Date: Mon Aug 2 19:43:15 2010
New Revision: 76437
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:
pass wrappers for result in better way
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 Aug 2 19:43:15 2010
@@ -65,7 +65,21 @@
class W_Get(Wrappable):
def __init__(self, space, cpu, lib, func, args_type, res_type='v'):
self.space = space
- self.rget = rjitffi._Get(cpu, lib, func, args_type, res_type)
+
+ if res_type == 'i':
+ self.rget = rjitffi._Get(cpu, lib, func, args_type,
+ res_type, self.wrap_int)
+ elif res_type == 'f':
+ self.rget = rjitffi._Get(cpu, lib, func, args_type,
+ res_type, self.wrap_float)
+ elif res_type == 'v':
+ self.rget = rjitffi._Get(cpu, lib, func, args_type,
+ res_type, self.wrap_void)
+ else:
+ raise OperationError(
+ space.w_ValueError,
+ space.wrap('Unsupported type of result: %s'
+ % res_type))
def call_w(self, space, w_args=None):
if not space.is_w(w_args, space.w_None):
@@ -90,7 +104,11 @@
space.wrap('Unsupported type of argument: %s'
% self.rget.args_type[0]))
i += 1
- return self.rget.call(space.wrap)
+ return self.rget.call()
+
+ wrap_int = lambda self, value: self.space.wrap(value)
+ wrap_float = lambda self, value: self.space.wrap(value)
+ wrap_void = lambda self, value: self.space.wrap(value)
#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 Mon Aug 2 19:43:15 2010
@@ -19,8 +19,8 @@
self.name = name
self.cpu = GLOBAL_CPU
- def get(self, func, args_type, res_type='v'):
- return _Get(self.cpu, self.lib, func, args_type, res_type)
+ def get(self, func, args_type, res_type='v', push_result=None):
+ return _Get(self.cpu, self.lib, func, args_type, res_type, push_result)
class _LibHandler(object):
def __init__(self, name):
@@ -33,10 +33,11 @@
rffi.free_charp(name_ptr)
class _Get(object):
- def __init__(self, cpu, lib, func, args_type, res_type='v'):
+ def __init__(self, cpu, lib, func, args_type, res_type='v', push_result=None):
assert isinstance(args_type, list)
self.args_type = args_type
self.res_type = res_type
+ self.push_result = push_result
self.cpu = cpu
lib = lib.handler
bargs = []
@@ -98,13 +99,13 @@
calldescr = cls(arg_classes)
return calldescr
- def call(self, push_result):
+ def call(self):
self.cpu.execute_token(self.looptoken)
if self.res_type == 'i':
- r = push_result(self.cpu.get_latest_value_int(0))
+ r = self.push_result(self.cpu.get_latest_value_int(0))
elif self.res_type == 'f':
- r = push_result(self.cpu.get_latest_value_float(0))
+ r = self.push_result(self.cpu.get_latest_value_float(0))
elif self.res_type == 'v':
r = None
else:
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 2 19:43:15 2010
@@ -71,60 +71,60 @@
def test_get(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('add_integers', ['i', 'i'], 'i')
+ func = lib.get('add_integers', ['i', 'i'], 'i', self.push_result)
func.push_int(1)
func.push_int(2)
- assert func.call(self.push_result) == 3
+ assert func.call() == 3
- func = lib.get('add_integers', ['i', 'i'], 'i')
+ func = lib.get('add_integers', ['i', 'i'], 'i', self.push_result)
func.push_int(-1)
func.push_int(2)
- assert func.call(self.push_result) == 1
+ assert func.call() == 1
- func = lib.get('add_integers', ['i', 'i'], 'i')
+ func = lib.get('add_integers', ['i', 'i'], 'i', self.push_result)
func.push_int(0)
func.push_int(0)
- assert func.call(self.push_result) == 0
+ assert func.call() == 0
- func = lib.get('max3', ['i', 'i', 'i'], 'i')
+ func = lib.get('max3', ['i', 'i', 'i'], 'i', self.push_result)
func.push_int(2)
func.push_int(8)
func.push_int(3)
- assert func.call(self.push_result) == 8
+ assert func.call() == 8
- func = lib.get('add_floats', ['f', 'f'], 'f')
+ func = lib.get('add_floats', ['f', 'f'], 'f', self.push_result)
func.push_float(1.2)
func.push_float(1.5)
- assert func.call(self.push_result) == 2.7
+ assert func.call() == 2.7
def test_get_void(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('fvoid', [], 'i')
- assert func.call(self.push_result) == 1
+ func = lib.get('fvoid', [], 'i', self.push_result)
+ assert func.call() == 1
- func = lib.get('return_void', ['i', 'i'], 'v')
+ func = lib.get('return_void', ['i', 'i'], 'v', self.push_result)
func.push_int(1)
func.push_int(2)
- assert func.call(self.push_result) is None
+ assert func.call() is None
- func = lib.get('return_void', ['i', 'i'])
+ func = lib.get('return_void', ['i', 'i'], push_result=self.push_result)
func.push_int(1)
func.push_int(2)
- assert func.call(self.push_result) is None
+ assert func.call() is None
def test_various_type_args(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('add_intfloat', ['i', 'f'], 'i')
+ func = lib.get('add_intfloat', ['i', 'f'], 'i', self.push_result)
func.push_int(1)
func.push_float(2.9)
- assert func.call(self.push_result) == 3
+ assert func.call() == 3
# stack is cleaned up after calling
func.push_int(0)
func.push_float(1.3)
- assert func.call(self.push_result) == 1
+ assert func.call() == 1
def test_undefined_func(self):
lib = rjitffi.CDLL(self.lib_name)
More information about the Pypy-commit
mailing list