-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-128100: Atomic dict load in _PyObject_GenericGetAttrWithDict #128297
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1715,10 +1715,16 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, | |
dict = (PyObject *)_PyObject_GetManagedDict(obj); | ||
} | ||
else { | ||
Py_BEGIN_CRITICAL_SECTION(obj); | ||
#ifdef DISABLE_GIL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
PyObject **dictptr = _Py_atomic_load_ptr(_PyObject_ComputedDictPointer(obj)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the wrong thing to load atomically--dereferencing it should be the atomic operation. In fact, this doesn't do what you think it does: |
||
#else | ||
PyObject **dictptr = _PyObject_ComputedDictPointer(obj); | ||
#endif | ||
if (dictptr) { | ||
dict = *dictptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is where the atomic load should be. (And, as Sam said in the issue, we want |
||
} | ||
Py_END_CRITICAL_SECTION(); | ||
} | ||
} | ||
if (dict != NULL) { | ||
|
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.
In general, we don't need to lock something if we're going to use one of the
_Py_atomic
APIs, and vice versa.