Skip to content

Commit 95bf38c

Browse files
committed
gh-158660: Add ASSERT_SET_LOCKED() to _PySet_NextEntry()
_PySet_NextEntryRef() already has the same ASSERT_SET_LOCKED(). Add also some assertions to other setobject.c functions to make sure that a set is locked when calling set_next() on it.
1 parent 5f4aeba commit 95bf38c

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎Objects/setobject.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,7 @@ static PyObject *
21932193
set_difference_untracked(PySetObject *so, PyObject *other)
21942194
{
21952195
ASSERT_SET_LOCKED(so);
2196+
ASSERT_OTHER_LOCKED(other);
21962197

21972198
PyObject *result;
21982199
PyObject *key;
@@ -2522,6 +2523,8 @@ static PyObject *
25222523
set_issubset_impl(PySetObject *so, PyObject *other)
25232524
/*[clinic end generated code: output=b2b59d5f314555ce input=f2a4fd0f2537758b]*/
25242525
{
2526+
ASSERT_SET_LOCKED(so);
2527+
25252528
setentry *entry;
25262529
Py_ssize_t pos = 0;
25272530
int rv;
@@ -3246,14 +3249,16 @@ PySet_Add(PyObject *anyset, PyObject *key)
32463249
int
32473250
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
32483251
{
3249-
setentry *entry;
3250-
32513252
if (!PyAnySet_Check(set)) {
32523253
PyErr_BadInternalCall();
32533254
return -1;
32543255
}
3255-
if (set_next((PySetObject *)set, pos, &entry) == 0)
3256+
ASSERT_SET_LOCKED(set);
3257+
3258+
setentry *entry;
3259+
if (set_next((PySetObject *)set, pos, &entry) == 0) {
32563260
return 0;
3261+
}
32573262
*key = entry->key;
32583263
*hash = entry->hash;
32593264
return 1;
@@ -3262,15 +3267,16 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash
32623267
int
32633268
_PySet_NextEntryRef(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
32643269
{
3265-
setentry *entry;
3266-
32673270
if (!PyAnySet_Check(set)) {
32683271
PyErr_BadInternalCall();
32693272
return -1;
32703273
}
32713274
ASSERT_SET_LOCKED(set);
3272-
if (set_next((PySetObject *)set, pos, &entry) == 0)
3275+
3276+
setentry *entry;
3277+
if (set_next((PySetObject *)set, pos, &entry) == 0) {
32733278
return 0;
3279+
}
32743280
*key = Py_NewRef(entry->key);
32753281
*hash = entry->hash;
32763282
return 1;

0 commit comments

Comments
 (0)