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

Function array_dealloc

numpy/core/src/multiarray/arrayobject.c:419–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417/* array object functions */
418
419static void
420array_dealloc(PyArrayObject *self)
421{
422 PyArrayObject_fields *fa = (PyArrayObject_fields *)self;
423
424 if (_buffer_info_free(fa->_buffer_info, (PyObject *)self) < 0) {
425 PyErr_WriteUnraisable(NULL);
426 }
427
428 if (fa->weakreflist != NULL) {
429 PyObject_ClearWeakRefs((PyObject *)self);
430 }
431 if (fa->base) {
432 int retval;
433 if (PyArray_FLAGS(self) & NPY_ARRAY_WRITEBACKIFCOPY)
434 {
435 char const * msg = "WRITEBACKIFCOPY detected in array_dealloc. "
436 " Required call to PyArray_ResolveWritebackIfCopy or "
437 "PyArray_DiscardWritebackIfCopy is missing.";
438 /*
439 * prevent reaching 0 twice and thus recursing into dealloc.
440 * Increasing sys.gettotalrefcount, but path should not be taken.
441 */
442 Py_INCREF(self);
443 WARN_IN_DEALLOC(PyExc_RuntimeWarning, msg);
444 retval = PyArray_ResolveWritebackIfCopy(self);
445 if (retval < 0)
446 {
447 PyErr_Print();
448 PyErr_Clear();
449 }
450 }
451 /*
452 * If fa->base is non-NULL, it is something
453 * to DECREF -- either a view or a buffer object
454 */
455 Py_XDECREF(fa->base);
456 }
457
458 if ((fa->flags & NPY_ARRAY_OWNDATA) && fa->data) {
459 /* Free any internal references */
460 if (PyDataType_REFCHK(fa->descr)) {
461 if (PyArray_ClearArray(self) < 0) {
462 PyErr_WriteUnraisable(NULL);
463 }
464 }
465 if (fa->mem_handler == NULL) {
466 if (numpy_warn_if_no_mem_policy) {
467 char const *msg = "Trying to dealloc data, but a memory policy "
468 "is not set. If you take ownership of the data, you must "
469 "set a base owning the data (e.g. a PyCapsule).";
470 WARN_IN_DEALLOC(PyExc_RuntimeWarning, msg);
471 }
472 // Guess at malloc/free ???
473 free(fa->data);
474 }
475 else {
476 size_t nbytes = PyArray_NBYTES(self);

Callers

nothing calls this directly

Calls 7

_buffer_info_freeFunction · 0.85
PyArray_FLAGSFunction · 0.85
WARN_IN_DEALLOCFunction · 0.85
PyArray_ClearArrayFunction · 0.85
PyDataMem_UserFREEFunction · 0.85
npy_free_cache_dimFunction · 0.85

Tested by

no test coverage detected