[pypy-commit] cffi default: Improve the error message.
arigo
noreply at buildbot.pypy.org
Thu Sep 13 08:49:47 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r926:da8b284ba665
Date: 2012-09-13 08:49 +0200
http://bitbucket.org/cffi/cffi/changeset/da8b284ba665/
Log: Improve the error message.
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -38,7 +38,7 @@
return 'void' + replace_with
def finish_backend_type(self, ffi):
- return global_cache(ffi, 'new_void_type')
+ return global_cache(self, ffi, 'new_void_type')
void_type = VoidType()
@@ -64,7 +64,7 @@
return self.name in ('double', 'float')
def finish_backend_type(self, ffi):
- return global_cache(ffi, 'new_primitive_type', self.name)
+ return global_cache(self, ffi, 'new_primitive_type', self.name)
class BaseFunctionType(BaseType):
@@ -108,7 +108,7 @@
args = []
for tp in self.args:
args.append(ffi._get_cached_btype(tp))
- return global_cache(ffi, 'new_function_type',
+ return global_cache(self, ffi, 'new_function_type',
tuple(args), result, self.ellipsis)
@@ -123,7 +123,7 @@
def finish_backend_type(self, ffi):
BItem = ffi._get_cached_btype(self.totype)
- return global_cache(ffi, 'new_pointer_type', BItem)
+ return global_cache(self, ffi, 'new_pointer_type', BItem)
class ConstPointerType(PointerType):
@@ -166,7 +166,7 @@
def finish_backend_type(self, ffi):
BPtrItem = ffi._get_cached_btype(PointerType(self.item))
- return global_cache(ffi, 'new_array_type', BPtrItem, self.length)
+ return global_cache(self, ffi, 'new_array_type', BPtrItem, self.length)
class StructOrUnionOrEnum(BaseType):
@@ -313,7 +313,7 @@
tp = StructType('*$%s' % name, None, None, None)
return NamedPointerType(tp, name)
-def global_cache(ffi, funcname, *args):
+def global_cache(srctype, ffi, funcname, *args):
try:
return ffi._backend.__typecache[args]
except KeyError:
@@ -327,6 +327,9 @@
ffi._backend.__typecache = weakref.WeakValueDictionary()
else:
type(ffi._backend).__typecache = weakref.WeakValueDictionary()
- res = getattr(ffi._backend, funcname)(*args)
+ try:
+ res = getattr(ffi._backend, funcname)(*args)
+ except NotImplementedError, e:
+ raise NotImplementedError("%r: %s" % (srctype, e))
ffi._backend.__typecache[args] = res
return res
diff --git a/testing/test_ffi_backend.py b/testing/test_ffi_backend.py
--- a/testing/test_ffi_backend.py
+++ b/testing/test_ffi_backend.py
@@ -1,4 +1,6 @@
+import py
from testing import backend_tests, test_function, test_ownlib
+from cffi import FFI
import _cffi_backend
@@ -10,3 +12,11 @@
@staticmethod
def Backend():
return _cffi_backend
+
+ def test_not_supported_bitfield_in_result(self):
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("struct foo_s { int x:1; };")
+ e = py.test.raises(NotImplementedError, ffi.callback,
+ "struct foo_s foo(void)", lambda: 42)
+ assert str(e.value) == ("<struct foo_s(*)(void)>: "
+ "cannot pass as argument or return value a struct with bit fields")
More information about the pypy-commit
mailing list