[pypy-svn] r77774 - in pypy/branch/jitffi/pypy/module/_ffi: . test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Oct 11 11:26:55 CEST 2010
Author: antocuni
Date: Mon Oct 11 11:26:53 2010
New Revision: 77774
Modified:
pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
Log:
raise TypeError if we try to use void as an argument type
Modified: pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py (original)
+++ pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py Mon Oct 11 11:26:53 2010
@@ -73,7 +73,7 @@
elif kind == 'f':
argchain.arg(space.float_w(w_arg))
else:
- assert False # XXX
+ assert False, "Argument kind '%s' not supported" % kind
return argchain
@unwrap_spec('self', ObjSpace, 'args_w')
@@ -111,13 +111,19 @@
self.name = name
self.space = space
- def ffitype(self, w_argtype):
- return self.space.interp_w(W_FFIType, w_argtype).ffitype
+ def ffitype(self, w_argtype, allow_void=False):
+ res = self.space.interp_w(W_FFIType, w_argtype).ffitype
+ if res is libffi.types.void and not allow_void:
+ space = self.space
+ msg = 'void is not a valid argument type'
+ raise OperationError(space.w_TypeError, space.wrap(msg))
+ return res
@unwrap_spec('self', ObjSpace, str, W_Root, W_Root)
def getfunc(self, space, name, w_argtypes, w_restype):
- argtypes = [self.ffitype(w_argtype) for w_argtype in space.listview(w_argtypes)]
- restype = self.ffitype(w_restype)
+ argtypes = [self.ffitype(w_argtype) for w_argtype in
+ space.listview(w_argtypes)]
+ restype = self.ffitype(w_restype, allow_void=True)
func = self.cdll.getpointer(name, argtypes, restype)
return W_FuncPtr(func)
Modified: pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py (original)
+++ pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py Mon Oct 11 11:26:53 2010
@@ -91,3 +91,9 @@
sum_xy = libfoo.getfunc('sum_xy', [types.sint, types.sint], types.sint)
raises(TypeError, "sum_xy(1, 2, 3)")
raises(TypeError, "sum_xy(1)")
+
+ def test_TypeError_voidarg(self):
+ from _ffi import CDLL, types
+ libfoo = CDLL(self.libfoo_name)
+ raises(TypeError, "libfoo.getfunc('sum_xy', [types.void], types.sint)")
+
More information about the Pypy-commit
mailing list