Skip to content

Commit 887f11e

Browse files
authored
Merge pull request #28201 from ngoldbaum/fix-2.2.2-bug
BUG: fix data race in a more minimal way on stable branch
2 parents 47c5af1 + bea630a commit 887f11e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

numpy/_core/src/multiarray/ctors.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,12 +1829,18 @@ PyArray_CheckFromAny_int(PyObject *op, PyArray_Descr *in_descr,
18291829
{
18301830
PyObject *obj;
18311831
if (requires & NPY_ARRAY_NOTSWAPPED) {
1832-
if (!in_descr && PyArray_Check(op)) {
1833-
in_descr = PyArray_DESCR((PyArrayObject *)op);
1834-
Py_INCREF(in_descr);
1832+
if (!in_descr && PyArray_Check(op) &&
1833+
PyArray_ISBYTESWAPPED((PyArrayObject* )op)) {
1834+
in_descr = PyArray_DescrNew(PyArray_DESCR((PyArrayObject *)op));
1835+
if (in_descr == NULL) {
1836+
return NULL;
1837+
}
1838+
}
1839+
else if (in_descr && !PyArray_ISNBO(in_descr->byteorder)) {
1840+
PyArray_DESCR_REPLACE(in_descr);
18351841
}
1836-
if (in_descr) {
1837-
PyArray_DESCR_REPLACE_CANONICAL(in_descr);
1842+
if (in_descr && in_descr->byteorder != NPY_IGNORE && in_descr->byteorder != NPY_NATIVE) {
1843+
in_descr->byteorder = NPY_NATIVE;
18381844
}
18391845
}
18401846

0 commit comments

Comments
 (0)