Repository navigation
gh-160496: Clear inline values with atomic release stores - #160510
Conversation
Py_CLEAR writes NULL non-atomically, racing with the acquire load in _PyObject_TryGetInstanceAttribute. Invalidating the inline values does not exclude lookups already in flight. Use a release store before decref, preserving the clear-before-decref ordering.
| for (Py_ssize_t i = 0; i < values->capacity; i++) { | ||
| Py_CLEAR(values->values[i]); | ||
| PyObject *value = values->values[i]; | ||
| FT_ATOMIC_STORE_PTR_RELEASE(values->values[i], NULL); |
There was a problem hiding this comment.
Is it worth a comment about what the conflicting reads are?
|
Maybe more explicit about where the load is, e.g. // Pair with the acquire load in _PyObject_TryGetInstanceAttribute(),
// which may read this slot after passing the initial validity check.
FT_ATOMIC_STORE_PTR_RELEASE(values->values[i], NULL);Or, do you not want to explicitly name the function? |
I was explicitly not naming the function to avoid the situation where the comment gets out of date due to refactoring. |
|
Thanks @mpage for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @mpage for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-160709 is a backport of this pull request to the 3.14 branch. |
|
GH-160710 is a backport of this pull request to the 3.15 branch. |
Py_CLEAR writes NULL non-atomically, racing with the acquire load in _PyObject_TryGetInstanceAttribute. Invalidating the inline values does not exclude lookups already in flight.
Authored with AI.
_PyObject_TryGetInstanceAttributeandclear_inline_values#160496