gh-137238: Fix data race in _Py_slot_tp_getattr_hook#137240
gh-137238: Fix data race in _Py_slot_tp_getattr_hook#137240colesbury merged 3 commits intopython:mainfrom
_Py_slot_tp_getattr_hook#137240Conversation
Replacing the slot isn't thread-safe if the GIL is disabled. Don't require that the slot has been replaced when specializing.
| if (has_custom_getattribute) { | ||
| if (getattro_slot == _Py_slot_tp_getattro && | ||
| !has_getattr && | ||
| if (!has_getattr && |
There was a problem hiding this comment.
@Fidget-Spinner, I removed the getattro_slot == _Py_slot_tp_getattro check here because:
- It would prevent specialization of
__getattribute__Python calls in the free threaded build with this change - I don't think it's necessary. The combined
has_custom_getattributeand!has_getattrchecks are sufficient.
Does this make sense to you?
There was a problem hiding this comment.
It makes sense for the FT build. Just reasoning out loud here: From what I see above, we replace the NULL slot with the special "__getattribute__ but no __getattr__" slot at some lookup time. But it's functionally the same as just saying get_attr == NULL. So the check for the slot is redundant?
There was a problem hiding this comment.
Yeah, I should add that we already check getattro_slot == _Py_slot_tp_getattr_hook || getattro_slot == _Py_slot_tp_getattro above.
Another way of saying this:
- There's a C pseudo-specialization process of rewriting
_Py_slot_tp_getattr_hookto_Py_slot_tp_getattro - The Python specialization of rewriting
LOAD_ATTRtoLOAD_ATTR_GETATTRIBUTE_OVERRIDDENshouldn't require_Py_slot_tp_getattr_hookto have already replaced by_Py_slot_tp_getattro. It just needs to ensure the conditions are correct (i.e,__getattribute__is present,__getattr__is not and thegetattro_slotisn't overridden with something else)
|
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Sorry, @colesbury, I could not cleanly backport this to |
|
GH-137416 is a backport of this pull request to the 3.14 branch. |
…ythongh-137240) Replacing the slot isn't thread-safe if the GIL is disabled. Don't require that the slot has been replaced when specializing. (cherry picked from commit 485b16b) Co-authored-by: Sam Gross <colesbury@gmail.com>
|
…h-137240) Replacing the slot isn't thread-safe if the GIL is disabled. Don't require that the slot has been replaced when specializing.
Replacing the slot isn't thread-safe if the GIL is disabled. Don't require that the slot has been replaced when specializing.
_Py_slot_tp_getattr_hook#137238