BUG: Avoid data race in PyArray_CheckFromAny_int#28154
Conversation
88c712a to
a539193
Compare
seberg
left a comment
There was a problem hiding this comment.
Looks good, but it would be nice to remove the PyArray_DescrNew in the above branch (replace it with an INCREF).
(Can't "suggest" unfortunately)
If this doesn't change metadata (if you don't want check I am happy to just assume/hope!), then we could also just call PyArray_DESCR_REPLACE_CANONICAL unconditionally for all I care (yes, changes meaning slightly more, but OK).
If it does change the metadata, could skip backporting, but I suspect it doesn't and don't think it matters overall.
| } | ||
| if (in_descr && in_descr->byteorder != NPY_IGNORE) { | ||
| in_descr->byteorder = NPY_NATIVE; | ||
| PyArray_DESCR_REPLACE_CANONICAL(in_descr); |
There was a problem hiding this comment.
A bit clearer maybe to just set in_descr = ... (with a new reference) in the first branch. Then we can call PyArray_DESCR_REPLACE_CANONICAL unconditionally.
There was a problem hiding this comment.
Unfortunately it looks like there are cases where PyArray_Check(op) is False but in_descr is NULL, so I still need the if (in_descr) check, but I think this is a lot simpler now.
* BUG: Avoid data race in PyArray_CheckFromAny_int * TST: add test * MAINT: simplify byteswapping code in PyArray_CheckFromAny_int * MAINT: drop ISBYTESWAPPED check
Fixes #28143.
I verified the test triggers TSAN warnings on
mainand doesn't anymore with this applied.