gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)

This commit is contained in:
Donghee Na
2024-04-19 00:18:22 +09:00
committed by GitHub
parent 40f4d641a9
commit 94444ea45a
9 changed files with 76 additions and 34 deletions

View File

@@ -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)
{