diff options
author | Armin Rigo <arigo@tunes.org> | 2012-11-29 17:54:31 -0800 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2012-11-29 17:54:31 -0800 |
commit | d20eaf7d123376bd2fe22ed0723c4da3281a453c (patch) | |
tree | dc89626a15809f2cc556b8088268a7e9d05eb52d /cffi/vengine_gen.py | |
parent | 249faab4740790359142e40e183bf44e99be1c60 (diff) | |
download | cffi-d20eaf7d123376bd2fe22ed0723c4da3281a453c.tar.gz |
Generalize the error reporting: attach the name of the current
function/struct when we get any error.
Diffstat (limited to 'cffi/vengine_gen.py')
-rw-r--r-- | cffi/vengine_gen.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py index e100062..389181c 100644 --- a/cffi/vengine_gen.py +++ b/cffi/vengine_gen.py @@ -78,13 +78,21 @@ class VGenericEngine(object): except AttributeError: raise ffiplatform.VerificationError( "not implemented in verify(): %r" % name) - method(tp, realname) + try: + method(tp, realname) + except Exception, e: + model.attach_exception_info(e, name) + raise def _load(self, module, step_name, **kwds): for name, tp in self._get_declarations(): kind, realname = name.split(' ', 1) method = getattr(self, '_%s_gen_%s' % (step_name, kind)) - method(tp, realname, module, **kwds) + try: + method(tp, realname, module, **kwds) + except Exception, e: + model.attach_exception_info(e, name) + raise def _generate_nothing(self, tp, name): pass @@ -154,11 +162,7 @@ class VGenericEngine(object): indirect_args.append(type) tp = model.FunctionPtrType(tuple(indirect_args), tp.result, tp.ellipsis) - try: - BFunc = self.ffi._get_cached_btype(tp) - except TypeError, e: - msg = 'function %s(): %s' % (name, e) - raise TypeError(msg) + BFunc = self.ffi._get_cached_btype(tp) wrappername = '_cffi_f_%s' % name newfunction = module.load_function(BFunc, wrappername) for i, type in indirections: @@ -280,8 +284,8 @@ class VGenericEngine(object): def check(realvalue, expectedvalue, msg): if realvalue != expectedvalue: raise ffiplatform.VerificationError( - "in %s: %s (we have %d, but C compiler says %d)" - % (cname, msg, expectedvalue, realvalue)) + "%s (we have %d, but C compiler says %d)" + % (msg, expectedvalue, realvalue)) ffi = self.ffi BStruct = ffi._get_cached_btype(tp) layout, cname = self._struct_pending_verification.pop(tp) @@ -390,10 +394,10 @@ class VGenericEngine(object): prnt('{') for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): prnt(' if (%s != %d) {' % (enumerator, enumvalue)) - prnt(' snprintf(out_error, 255, "in enum %s: ' - '%s has the real value %d, not %d",') - prnt(' "%s", "%s", (int)%s, %d);' % ( - name, enumerator, enumerator, enumvalue)) + prnt(' snprintf(out_error, 255,' + '"%s has the real value %d, not %d",') + prnt(' "%s", (int)%s, %d);' % ( + enumerator, enumerator, enumvalue)) prnt(' return -1;') prnt(' }') prnt(' return 0;') |