/* * check whether arrays with datatype dtype might have object fields. This will * only happen for structured dtypes (which may have hidden objects even if the * HASOBJECT flag is false), object dtypes, or subarray dtypes whose base type * is either of these. */ NPY_NO_EXPORT int _may_have_objects(PyArray_Descr *dtype) { PyArray_Descr *base = dtype; if (PyDataType_HASSUBARRAY(dtype)) { base = dtype->subarray->base; } return (PyDataType_HASFIELDS(base) || PyDataType_FLAGCHK(base, NPY_ITEM_HASOBJECT) ); }
static void array_dealloc(PyArrayObject *self) { _array_dealloc_buffer_info(self); if (self->weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject *)self); } if (self->base) { /* * UPDATEIFCOPY means that base points to an * array that should be updated with the contents * of this array upon destruction. * self->base->flags must have been WRITEABLE * (checked previously) and it was locked here * thus, unlock it. */ if (self->flags & UPDATEIFCOPY) { ((PyArrayObject *)self->base)->flags |= WRITEABLE; Py_INCREF(self); /* hold on to self in next call */ if (PyArray_CopyAnyInto((PyArrayObject *)self->base, self) < 0) { PyErr_Print(); PyErr_Clear(); } /* * Don't need to DECREF -- because we are deleting *self already... */ } /* * In any case base is pointing to something that we need * to DECREF -- either a view or a buffer object */ Py_DECREF(self->base); } if ((self->flags & OWNDATA) && self->data) { /* Free internal references if an Object array */ if (PyDataType_FLAGCHK(self->descr, NPY_ITEM_REFCOUNT)) { Py_INCREF(self); /*hold on to self */ PyArray_XDECREF(self); /* * Don't need to DECREF -- because we are deleting * self already... */ } PyDataMem_FREE(self->data); } PyDimMem_FREE(self->dimensions); Py_DECREF(self->descr); Py_TYPE(self)->tp_free((PyObject *)self); }