From: Amaury Forgeot d'Arc Date: Fri, 2 Sep 2011 21:07:54 +0000 (+0200) Subject: ctypes: Slightly better error message when a struct field name is not a string. X-Git-Tag: v3.3.0a1~1576 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=842d921a79273cd04113d154b127622ff243f9c0;p=thirdparty%2FPython%2Fcpython.git ctypes: Slightly better error message when a struct field name is not a string. --- diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 14dc16fc0297..63f956bbcaa5 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -426,9 +426,9 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct StgDictObject *dict; int bitsize = 0; - if (!pair || !PyArg_ParseTuple(pair, "OO|i", &name, &desc, &bitsize)) { - PyErr_SetString(PyExc_AttributeError, - "'_fields_' must be a sequence of pairs"); + if (!pair || !PyArg_ParseTuple(pair, "UO|i", &name, &desc, &bitsize)) { + PyErr_SetString(PyExc_TypeError, + "'_fields_' must be a sequence of (name, C type) pairs"); Py_XDECREF(pair); return -1; } @@ -478,6 +478,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct } } else bitsize = 0; + if (isStruct && !isPacked) { char *fieldfmt = dict->format ? dict->format : "B"; char *fieldname = _PyUnicode_AsString(name); @@ -487,10 +488,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct if (fieldname == NULL) { - PyErr_Format(PyExc_TypeError, - "structure field name must be string not %s", - name->ob_type->tp_name); - Py_DECREF(pair); return -1; } @@ -509,6 +506,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct return -1; } } + if (isStruct) { prop = PyCField_FromDesc(desc, i, &field_size, bitsize, &bitofs,