diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-25 10:22:21 +0100 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-25 14:28:33 +0100 |
| commit | 770fe81cc2969d36af4bd1576ce5b69fcb03ffbf (patch) | |
| tree | c6617e6dbcff48b9c8c87327641e4f0aac691389 /numpy/core/src/multiarray | |
| parent | 5f04e748b8d4c92bc6ad4d7a38ee6601dc0ccf04 (diff) | |
| download | numpy-770fe81cc2969d36af4bd1576ce5b69fcb03ffbf.tar.gz | |
BUG: Allow no-op clearing of void dtypes
Some void dtypes think they contain objects but don't. Instead
of playing whack-a-mole to see if that can be fixed, simply make
the clearing a no-op here for them.
User dtypes are weirder, it should be OK to pass through.
Fixes the error message and use write-unraisable.
Closes gh-23277
Diffstat (limited to 'numpy/core/src/multiarray')
| -rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 4 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/dtype_traversal.c | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 4c8cfab06..0434e8676 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -455,7 +455,9 @@ array_dealloc(PyArrayObject *self) if ((fa->flags & NPY_ARRAY_OWNDATA) && fa->data) { /* Free any internal references */ if (PyDataType_REFCHK(fa->descr)) { - PyArray_ClearArray(self); + if (PyArray_ClearArray(self) < 0) { + PyErr_WriteUnraisable(NULL); + } } if (fa->mem_handler == NULL) { char *env = getenv("NUMPY_WARN_IF_NO_MEM_POLICY"); diff --git a/numpy/core/src/multiarray/dtype_traversal.c b/numpy/core/src/multiarray/dtype_traversal.c index e2197da0c..cefa7d6e1 100644 --- a/numpy/core/src/multiarray/dtype_traversal.c +++ b/numpy/core/src/multiarray/dtype_traversal.c @@ -454,10 +454,21 @@ npy_get_clear_void_and_legacy_user_dtype_loop( } return 0; } + else if (dtype->type_num == NPY_VOID) { + /* + * Void dtypes can have "ghosts" of objects marking the dtype because + * holes (or the raw bytes if fields are gone) may include objects. + * Paths that need those flags should probably be considered incorrect. + * But as long as this can happen (a V8 that indicates references) + * we need to make it a no-op here. + */ + *out_func = &clear_no_op; + return 0; + } PyErr_Format(PyExc_RuntimeError, "Internal error, tried to fetch clear function for the " - "user dtype '%s' without fields or subarray (legacy support).", + "user dtype '%S' without fields or subarray (legacy support).", dtype); return -1; } |
