[pypy-svn] r75853 - in pypy/branch/fast-ctypes/pypy: module/jitffi module/jitffi/test rlib rlib/test
getxsick at codespeak.net
getxsick at codespeak.net
Mon Jul 5 20:19:52 CEST 2010
Author: getxsick
Date: Mon Jul 5 20:19:51 2010
New Revision: 75853
Modified:
pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
Log:
use short names of types
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 Jul 5 20:19:51 2010
@@ -26,7 +26,7 @@
class W_Get(Wrappable, rjitffi._Get):
- def __init__(self, space, cpu, lib, func, args_type, res_type='void'):
+ def __init__(self, space, cpu, lib, func, args_type, res_type='v'):
self.space = space
rjitffi._Get.__init__(self, cpu, lib, func, args_type, res_type)
@@ -44,11 +44,11 @@
raise
break # done
- if self.args_type[i] == 'int':
+ if self.args_type[i] == 'i':
self.push_int(space.int_w(w_arg))
- elif self.args_type[i] == 'float':
+ elif self.args_type[i] == 'f':
self.push_float(space.float_w(w_arg))
- elif self.args_type[i] == 'ref':
+ elif self.args_type[i] == 'p':
self.push_ref(space.int_w(w_arg))
else:
raise OperationError(
@@ -80,7 +80,7 @@
except OSError, e:
raise OperationError(space.w_OSError, space.wrap(str(e)))
- def get_w(self, space, func, w_args_type, res_type='void'):
+ def get_w(self, space, func, w_args_type, res_type='v'):
args_type_w = [ space.str_w(w_x)
for w_x in space.listview(w_args_type) ]
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 Jul 5 20:19:51 2010
@@ -71,36 +71,36 @@
import jitffi
lib = jitffi.CDLL(self.lib_name)
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
assert 3 == func.call([1,2])
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
assert 1 == func.call([-1,2])
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
assert 0 == func.call([0,0])
- func = lib.get('max3', ['int', 'int', 'int'], 'int')
+ func = lib.get('max3', ['i', 'i', 'i'], 'i')
assert 8 == func.call([2, 8, 3])
- func = lib.get('add_floats', ['float', 'float'], 'float')
+ func = lib.get('add_floats', ['f', 'f'], 'f')
assert 2.7 == func.call([1.2, 1.5])
def test_get_void(self):
import jitffi
lib = jitffi.CDLL(self.lib_name)
- func = lib.get('fvoid', [], 'int')
+ func = lib.get('fvoid', [], 'i')
assert 1 == func.call()
- func = lib.get('return_void', ['int', 'int'], 'void')
+ func = lib.get('return_void', ['i', 'i'], 'v')
assert func.call([1, 2]) is None
- func = lib.get('return_void', ['int', 'int'])
+ func = lib.get('return_void', ['i', 'i'])
assert func.call([1, 2]) is None
def test_various_type_args(self):
import jitffi
lib = jitffi.CDLL(self.lib_name)
- func = lib.get('add_intfloat', ['int', 'float'], 'int')
+ func = lib.get('add_intfloat', ['i', 'f'], 'i')
assert func.call([1, 2.9]) == 3
assert func.call([0, 1.3]) == 1
@@ -109,13 +109,13 @@
lib = jitffi.CDLL(self.lib_name)
# xxxfoo888baryyy - not existed function
raises(ValueError, lib.get, 'xxxfoo888baryyy', [])
- raises(ValueError, lib.get, 'xxxfoo888baryyy', ['int'], 'int')
+ raises(ValueError, lib.get, 'xxxfoo888baryyy', ['i'], 'i')
def test_unknown_types(self):
import jitffi
lib = jitffi.CDLL(self.lib_name)
# xxxfoo888baryyy - not defined types (args_type, res_type etc.)
raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'])
- raises(ValueError, lib.get, 'fvoid', ['int','xxxfoo888baryyy'])
- raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'],'int')
+ raises(ValueError, lib.get, 'fvoid', ['i','xxxfoo888baryyy'])
+ raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'],'i')
raises(ValueError, lib.get, 'fvoid', [], 'xxxfoo888baryyy')
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 Jul 5 20:19:51 2010
@@ -16,7 +16,7 @@
self.name = name
self.cpu = CPU(None, None)
- def get(self, func, args_type, res_type='void'):
+ def get(self, func, args_type, res_type='v'):
return _Get(self.cpu, self.lib, func, args_type, res_type)
class _LibHandler(object):
@@ -27,7 +27,7 @@
raise OSError('%s: %s', name, e.msg or 'unspecified error')
class _Get(object):
- def __init__(self, cpu, lib, func, args_type, res_type='void'):
+ def __init__(self, cpu, lib, func, args_type, res_type='v'):
assert isinstance(args_type, list)
self.args_type = args_type
self.res_type = res_type
@@ -35,16 +35,16 @@
self.lib = lib.handler
self.setup_stack()
- if self.res_type == 'int':
+ if self.res_type == 'i':
self.bres = BoxInt()
res = lltype.Signed
- elif self.res_type == 'float':
+ elif self.res_type == 'f':
self.bres = BoxFloat()
res = lltype.Float
- elif self.res_type == 'ref':
+ elif self.res_type == 'p':
self.bres = BoxPtr()
res = lltype.Signed
- elif self.res_type == 'void':
+ elif self.res_type == 'v':
self.bres = NULLBOX
res = lltype.Void
else:
@@ -58,11 +58,11 @@
args = []
for arg in self.args_type:
- if arg == 'int':
+ if arg == 'i':
args.append(lltype.Signed)
- elif arg == 'float':
+ elif arg == 'f':
args.append(lltype.Float)
- elif arg == 'ref':
+ elif arg == 'p':
args.append(lltype.Signed)
else:
raise ValueError(arg)
@@ -90,13 +90,13 @@
self.setup_stack() # clean up the stack
- if self.res_type == 'int':
+ if self.res_type == 'i':
r = BoxInt(self.cpu.get_latest_value_int(0)).getint()
- elif self.res_type == 'float':
+ elif self.res_type == 'f':
r = BoxFloat(self.cpu.get_latest_value_float(0)).getfloat()
- elif self.res_type == 'ref':
+ elif self.res_type == 'p':
r = BoxPtr(self.cpu.get_latest_value_ref(0)).getref()
- elif self.res_type == 'void':
+ elif self.res_type == 'v':
r = None
else:
raise ValueError(self.res_type)
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 Jul 5 20:19:51 2010
@@ -68,28 +68,28 @@
def test_get(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(1)
func.push_int(2)
assert func.call() == 3
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(-1)
func.push_int(2)
assert func.call() == 1
- func = lib.get('add_integers', ['int', 'int'], 'int')
+ func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(0)
func.push_int(0)
assert func.call() == 0
- func = lib.get('max3', ['int', 'int', 'int'], 'int')
+ func = lib.get('max3', ['i', 'i', 'i'], 'i')
func.push_int(2)
func.push_int(8)
func.push_int(3)
assert func.call() == 8
- func = lib.get('add_floats', ['float', 'float'], 'float')
+ func = lib.get('add_floats', ['f', 'f'], 'f')
func.push_float(1.2)
func.push_float(1.5)
assert func.call() == 2.7
@@ -97,15 +97,15 @@
def test_get_void(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('fvoid', [], 'int')
+ func = lib.get('fvoid', [], 'i')
assert func.call() == 1
- func = lib.get('return_void', ['int', 'int'], 'void')
+ func = lib.get('return_void', ['i', 'i'], 'v')
func.push_int(1)
func.push_int(2)
assert func.call() is None
- func = lib.get('return_void', ['int', 'int'])
+ func = lib.get('return_void', ['i', 'i'])
func.push_int(1)
func.push_int(2)
assert func.call() is None
@@ -113,7 +113,7 @@
def test_various_type_args(self):
lib = rjitffi.CDLL(self.lib_name)
- func = lib.get('add_intfloat', ['int', 'float'], 'int')
+ func = lib.get('add_intfloat', ['i', 'f'], 'i')
func.push_int(1)
func.push_float(2.9)
assert func.call() == 3
@@ -127,12 +127,12 @@
lib = rjitffi.CDLL(self.lib_name)
# xxxfoo888baryyy - not existed function
py.test.raises(ValueError, lib.get, 'xxxfoo888baryyy', [])
- py.test.raises(ValueError, lib.get, 'xxxfoo888baryyy', ['int'], 'int')
+ py.test.raises(ValueError, lib.get, 'xxxfoo888baryyy', ['i'], 'i')
def test_unknown_types(self):
lib = rjitffi.CDLL(self.lib_name)
# xxxfoo888baryyy - not defined types (args_type, res_type etc.)
py.test.raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'])
- py.test.raises(ValueError, lib.get, 'fvoid', ['int','xxxfoo888baryyy'])
- py.test.raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'],'int')
+ py.test.raises(ValueError, lib.get, 'fvoid', ['i','xxxfoo888baryyy'])
+ py.test.raises(ValueError, lib.get, 'fvoid', ['xxxfoo888baryyy'],'i')
py.test.raises(ValueError, lib.get, 'fvoid', [], 'xxxfoo888baryyy')
More information about the Pypy-commit
mailing list