NUMPY_API * * XDECREF all objects in a single array item. This is complicated for * structured datatypes where the position of objects needs to be extracted. * The function is execute recursively for each nested field or subarrays dtype * such as as `np.dtype([("field1", "O"), ("field2", "f,O", (3,2))])` */
| 181 | * such as as `np.dtype([("field1", "O"), ("field2", "f,O", (3,2))])` |
| 182 | */ |
| 183 | NPY_NO_EXPORT void |
| 184 | PyArray_Item_XDECREF(char *data, PyArray_Descr *descr) |
| 185 | { |
| 186 | PyObject *temp; |
| 187 | |
| 188 | if (!PyDataType_REFCHK(descr)) { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | if (descr->type_num == NPY_OBJECT) { |
| 193 | memcpy(&temp, data, sizeof(temp)); |
| 194 | Py_XDECREF(temp); |
| 195 | } |
| 196 | else if (PyDataType_HASFIELDS(descr)) { |
| 197 | PyObject *key, *value, *title = NULL; |
| 198 | PyArray_Descr *new; |
| 199 | int offset; |
| 200 | Py_ssize_t pos = 0; |
| 201 | |
| 202 | while (PyDict_Next(descr->fields, &pos, &key, &value)) { |
| 203 | if (NPY_TITLE_KEY(key, value)) { |
| 204 | continue; |
| 205 | } |
| 206 | if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, |
| 207 | &title)) { |
| 208 | return; |
| 209 | } |
| 210 | PyArray_Item_XDECREF(data + offset, new); |
| 211 | } |
| 212 | } |
| 213 | else if (PyDataType_HASSUBARRAY(descr)) { |
| 214 | int size, i, inner_elsize; |
| 215 | |
| 216 | inner_elsize = descr->subarray->base->elsize; |
| 217 | if (inner_elsize == 0) { |
| 218 | /* There cannot be any elements, so return */ |
| 219 | return; |
| 220 | } |
| 221 | /* Subarrays are always contiguous in memory */ |
| 222 | size = descr->elsize / inner_elsize; |
| 223 | |
| 224 | for (i = 0; i < size; i++){ |
| 225 | /* Recursively decrement the reference count of subarray elements */ |
| 226 | PyArray_Item_XDECREF(data + i * inner_elsize, |
| 227 | descr->subarray->base); |
| 228 | } |
| 229 | } |
| 230 | else { |
| 231 | /* This path should not be reachable. */ |
| 232 | assert(0); |
| 233 | } |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | /* Used for arrays of python objects to increment the reference count of */ |
| 238 | /* every python object in the array. */ |
no outgoing calls
no test coverage detected