-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-112069: Do not require lock if the set has never been exposed. #118069
Conversation
Objects/setobject.c
Outdated
@@ -2334,6 +2334,12 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds) | |||
if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable)) | |||
return -1; | |||
|
|||
if (self->fill == 0 && Py_REFCNT(self) == 1) { |
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.
I think we should do the Py_REFCNT()
check first so that we don't access self->fill
without a lock in case there are other threads with references modifying self
.
Also, do we need to set self->hash = -1
as we do below?
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.
Also, do we need to set self->hash = -1 as we do below?
Well it will be more safe.
@colesbury gentle ping :) |
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.
Thanks!
set
thread-safe in--disable-gil
builds #112069