gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)
This commit is contained in:
@@ -2661,7 +2661,6 @@ PySet_Add(PyObject *anyset, PyObject *key)
|
||||
return rv;
|
||||
}
|
||||
|
||||
// TODO: Make thread-safe in free-threaded builds
|
||||
int
|
||||
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
|
||||
{
|
||||
@@ -2678,6 +2677,23 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
_PySet_NextEntryRef(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
|
||||
{
|
||||
setentry *entry;
|
||||
|
||||
if (!PyAnySet_Check(set)) {
|
||||
PyErr_BadInternalCall();
|
||||
return -1;
|
||||
}
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(set);
|
||||
if (set_next((PySetObject *)set, pos, &entry) == 0)
|
||||
return 0;
|
||||
*key = Py_NewRef(entry->key);
|
||||
*hash = entry->hash;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PySet_Pop(PyObject *set)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user