Author: Armin Rigo <[email protected]>
Branch:
Changeset: r75254:9d3eb04e5545
Date: 2015-01-07 21:23 +0100
http://bitbucket.org/pypy/pypy/changeset/9d3eb04e5545/
Log: Update for cffi/275285b314a7
diff --git a/pypy/module/_cffi_backend/ccallback.py
b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -45,8 +45,9 @@
#
cif_descr = self.getfunctype().cif_descr
if not cif_descr:
- raise OperationError(space.w_NotImplementedError,
- space.wrap("callbacks with '...'"))
+ raise oefmt(space.w_NotImplementedError,
+ "%s: callback with unsupported argument or "
+ "return type or with '...'", self.getfunctype().name)
res = clibffi.c_ffi_prep_closure(self.get_closure(), cif_descr.cif,
invoke_callback,
rffi.cast(rffi.VOIDP, self.unique_id))
diff --git a/pypy/module/_cffi_backend/ctypefunc.py
b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -34,6 +34,7 @@
could_cast_anything=False)
self.fargs = fargs
self.ellipsis = bool(ellipsis)
+ self.cif_descr = lltype.nullptr(CIF_DESCRIPTION)
# fresult is stored in self.ctitem
if not ellipsis:
@@ -41,7 +42,14 @@
# at all. The cif is computed on every call from the actual
# types passed in. For all other functions, the cif_descr
# is computed here.
- CifDescrBuilder(fargs, fresult).rawallocate(self)
+ builder = CifDescrBuilder(fargs, fresult)
+ try:
+ builder.rawallocate(self)
+ except OperationError, e:
+ if not e.match(space, space.w_NotImplementedError):
+ raise
+ # else, eat the NotImplementedError. We will get the
+ # exception if we see an actual call
def new_ctypefunc_completing_argtypes(self, args_w):
space = self.space
@@ -178,8 +186,6 @@
# ____________________________________________________________
-W_CTypeFunc.cif_descr = lltype.nullptr(CIF_DESCRIPTION) # default value
-
BIG_ENDIAN = sys.byteorder == 'big'
USE_C_LIBFFI_MSVC = getattr(clibffi, 'USE_C_LIBFFI_MSVC', False)
@@ -295,18 +301,18 @@
nflat = 0
for i, cf in enumerate(ctype.fields_list):
if cf.is_bitfield():
- raise OperationError(space.w_NotImplementedError,
- space.wrap("cannot pass as argument or return value "
- "a struct with bit fields"))
+ raise oefmt(space.w_NotImplementedError,
+ "ctype '%s' not supported as argument or return value"
+ " (it is a struct with bit fields)", ctype.name)
flat = 1
ct = cf.ctype
while isinstance(ct, ctypearray.W_CTypeArray):
flat *= ct.length
ct = ct.ctitem
if flat <= 0:
- raise OperationError(space.w_NotImplementedError,
- space.wrap("cannot pass as argument or return value "
- "a struct with a zero-length array"))
+ raise oefmt(space.w_NotImplementedError,
+ "ctype '%s' not supported as argument or return value"
+ " (it is a struct with a zero-length array)", ctype.name)
nflat += flat
if USE_C_LIBFFI_MSVC and is_result_type:
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1030,11 +1030,12 @@
BInt = new_primitive_type("int")
BArray0 = new_array_type(new_pointer_type(BInt), 0)
BStruct = new_struct_type("struct foo")
+ BStructP = new_pointer_type(BStruct)
complete_struct_or_union(BStruct, [('a', BArray0)])
- py.test.raises(NotImplementedError, new_function_type,
- (BStruct,), BInt, False)
- py.test.raises(NotImplementedError, new_function_type,
- (BInt,), BStruct, False)
+ BFunc = new_function_type((BStruct,), BInt, False)
+ py.test.raises(NotImplementedError, cast(BFunc, 123), cast(BStructP, 123))
+ BFunc2 = new_function_type((BInt,), BStruct, False)
+ py.test.raises(NotImplementedError, cast(BFunc2, 123), 123)
def test_call_function_9():
BInt = new_primitive_type("int")
@@ -1805,7 +1806,8 @@
new_function_type((), new_pointer_type(BFunc))
BUnion = new_union_type("union foo_u")
complete_struct_or_union(BUnion, [])
- py.test.raises(NotImplementedError, new_function_type, (), BUnion)
+ BFunc = new_function_type((), BUnion)
+ py.test.raises(NotImplementedError, cast(BFunc, 123))
py.test.raises(TypeError, new_function_type, (), BArray)
def test_struct_return_in_func():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit