Seg fault arising from PyArray_DiscoverDTypeAndShape
ngoldbaum opened this issue · 2 comments
The following script currently seg faults during interpreter finalization when numpy is trying to de-allocate the dtype variable:
import os
os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
import numpy as np
from asciidtype import ASCIIDType
dtype = ASCIIDType(6)
a = np.array(["hello", "array"], dtype=dtype)
arr = np.array([a[0], a[1]])This script doesn't seg fault:
import os
os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
import numpy as np
from metadatadtype import MetadataDType
dtype = MetadataDType("hello")
a = np.array([1, 2], dtype=dtype)
arr = np.array([a[0], a[1]])I put watchpoints in gdb on the refcount of the dtypes in both scripts and found that the first time the behavior of the two scripts is different is that in the ASCIIDType script, this incref isn't getting executed: https://github.com/numpy/numpy/blob/main/numpy/core/src/multiarray/array_coercion.c#L691
I unfortunately ran out of time today before I could figure out why *out_descr is NULL in one case but not in the other but wanted to get this written up so I can come back to it on Monday. I suspect there's a missing call to Py_INCREF somewhere in Numpy.
MetadataDType not seg faulting ended up being a red herring, there was a missing decref that canceled out a missing incref. PR incoming...