MCPcopy Create free account
hub / github.com/numpy/numpy / _array_descr_walk_fields

Function _array_descr_walk_fields

numpy/core/src/multiarray/hashdescr.c:108–186  ·  view source on GitHub ↗

* Walk inside the fields and add every item which will be used for hashing * into the list l * * Return 0 on success */

Source from the content-addressed store, hash-verified

106 * Return 0 on success
107 */
108static int _array_descr_walk_fields(PyObject *names, PyObject* fields, PyObject* l)
109{
110 PyObject *key, *value, *foffset, *fdescr, *ftitle;
111 Py_ssize_t pos = 0;
112 int st;
113
114 if (!PyTuple_Check(names)) {
115 PyErr_SetString(PyExc_SystemError,
116 "(Hash) names is not a tuple ???");
117 return -1;
118 }
119 if (!PyDict_Check(fields)) {
120 PyErr_SetString(PyExc_SystemError,
121 "(Hash) fields is not a dict ???");
122 return -1;
123 }
124
125 for (pos = 0; pos < PyTuple_GET_SIZE(names); pos++) {
126 /*
127 * For each field, add the key + descr + offset to l
128 */
129 key = PyTuple_GET_ITEM(names, pos);
130 value = PyDict_GetItem(fields, key);
131 /* XXX: are those checks necessary ? */
132 if (value == NULL) {
133 PyErr_SetString(PyExc_SystemError,
134 "(Hash) names and fields inconsistent ???");
135 return -1;
136 }
137 if (!PyUnicode_Check(key)) {
138 PyErr_SetString(PyExc_SystemError,
139 "(Hash) key of dtype dict not a string ???");
140 return -1;
141 }
142 if (!PyTuple_Check(value)) {
143 PyErr_SetString(PyExc_SystemError,
144 "(Hash) value of dtype dict not a dtype ???");
145 return -1;
146 }
147 if (PyTuple_GET_SIZE(value) < 2) {
148 PyErr_SetString(PyExc_SystemError,
149 "(Hash) Less than 2 items in dtype dict ???");
150 return -1;
151 }
152 PyList_Append(l, key);
153
154 fdescr = PyTuple_GET_ITEM(value, 0);
155 if (!PyArray_DescrCheck(fdescr)) {
156 PyErr_SetString(PyExc_SystemError,
157 "(Hash) First item in compound dtype tuple not a descr ???");
158 return -1;
159 }
160 else {
161 Py_INCREF(fdescr);
162 st = _array_descr_walk((PyArray_Descr*)fdescr, l);
163 Py_DECREF(fdescr);
164 if (st) {
165 return -1;

Callers 1

_array_descr_walkFunction · 0.85

Calls 1

_array_descr_walkFunction · 0.85

Tested by

no test coverage detected