-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
BUG: Avoid data race in PyArray_CheckFromAny_int #28154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
88c712a
to
a539193
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
main
and doesn't anymore with this applied.