Commit 842d921a authored by Amaury Forgeot d'Arc's avatar Amaury Forgeot d'Arc

ctypes: Slightly better error message when a struct field name is not a string.

parent 154f2b47
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment