Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2773,17 +2773,23 @@ PySet_Discard(PyObject *set, PyObject *key)
int
PySet_Add(PyObject *anyset, PyObject *key)
{
if (!PySet_Check(anyset) &&
(!PyFrozenSet_Check(anyset) || !_PyObject_IsUniquelyReferenced(anyset))) {
PyErr_BadInternalCall();
return -1;
if (_PyObject_IsUniquelyReferenced(anyset) && PyAnySet_Check(anyset)) {
// In free-threading, if the set or frozenset is uniquely referenced,
// no critical section is needed since only the owner thread is
// populating it.
Comment thread
yoney marked this conversation as resolved.
Outdated
return set_add_key((PySetObject *)anyset, key);
Comment thread
yoney marked this conversation as resolved.
Outdated
}

int rv;
Py_BEGIN_CRITICAL_SECTION(anyset);
rv = set_add_key((PySetObject *)anyset, key);
Py_END_CRITICAL_SECTION();
return rv;
if (PySet_Check(anyset)) {
int rv;
Py_BEGIN_CRITICAL_SECTION(anyset);
rv = set_add_key((PySetObject *)anyset, key);
Py_END_CRITICAL_SECTION();
return rv;
}

PyErr_BadInternalCall();
return -1;
}

int
Expand Down
Loading