8000 BUG: fix data race setting up within dtype cats for legacy user dtypes · numpy/numpy@8120070 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8120070

Browse files
committed
BUG: fix data race setting up within dtype cats for legacy user dtypes
1 parent 9c407bd commit 8120070

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

numpy/_core/src/multiarray/convert_datatype.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,12 @@ ensure_castingimpl_exists(PyArray_DTypeMeta *from, PyArray_DTypeMeta *to)
188188
NPY_NO_EXPORT PyObject *
189189
PyArray_GetCastingImpl(PyArray_DTypeMeta *from, PyArray_DTypeMeta *to)
190190
{
191-
PyObject *res;
191+
PyObject *res = NULL;
192192
if (from == to) {
193-
res = Py_XNewRef((PyObject *)NPY_DT_SLOTS(from)->within_dtype_castingimpl);
193+
if ((NPY_DT_SLOTS(from)->within_dtype_castingimpl) != NULL) {
194+
res = Py_XNewRef(
195+
(PyObject *)NPY_DT_SLOTS(from)->within_dtype_castingimpl);
196+
}
194197
}
195198
else if (PyDict_GetItemRef(NPY_DT_SLOTS(from)->castingimpls,
196199
(PyObject *)to, &res) < 0) {

numpy/_core/src/multiarray/dtypemeta.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,12 @@ dtypemeta_wrap_legacy_descriptor(
12521252
return -1;
12531253
}
12541254
}
1255+
else {
1256+
// ensure the within dtype cast is populated for legacy user dtypes
1257+
if (PyArray_GetCastingImpl(dtype_class, dtype_class) == NULL) {
1258+
return -1;
1259+
}
1260+
}
12551261

12561262
return 0;
12571263
}

0 commit comments

Comments
 (0)
0