[pypy-commit] cffi default: Improve the error messages
arigo
noreply at buildbot.pypy.org
Wed Sep 19 01:09:51 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r946:81754acf19ae
Date: 2012-09-19 01:09 +0200
http://bitbucket.org/cffi/cffi/changeset/81754acf19ae/
Log: Improve the error messages
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4009,18 +4009,23 @@
return NULL;
if (fieldname == Py_None) {
- if (!(ct->ct_flags & (CT_STRUCT|CT_UNION)))
- goto typeerror;
+ if (!(ct->ct_flags & (CT_STRUCT|CT_UNION))) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a struct or union ctype");
+ return NULL;
+ }
res = (PyObject *)ct;
offset = 0;
}
else {
if (ct->ct_flags & CT_POINTER)
ct = ct->ct_itemdescr;
- if (!(ct->ct_flags & (CT_STRUCT|CT_UNION)))
- goto typeerror;
- if (ct->ct_stuff == NULL)
- goto typeerror;
+ if (!(ct->ct_flags & (CT_STRUCT|CT_UNION)) || ct->ct_stuff == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected an initialized struct or union ctype, "
+ "or a pointer to one");
+ return NULL;
+ }
cf = (CFieldObject *)PyDict_GetItem(ct->ct_stuff, fieldname);
if (cf == NULL) {
PyErr_SetObject(PyExc_KeyError, fieldname);
@@ -4034,12 +4039,6 @@
offset = cf->cf_offset;
}
return Py_BuildValue("(On)", res, offset);
-
- typeerror:
- PyErr_SetString(PyExc_TypeError,
- "expected an initialized struct or union ctype, "
- "or a pointer to it");
- return NULL;
}
static PyObject *b_rawaddressof(PyObject *self, PyObject *args)
More information about the pypy-commit
mailing list