Skip to content
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Update test case: used_race and exhaust_race
  • Loading branch information
hyongtao-code committed Feb 1, 2026
commit 21f1478423e09eee0ea7c082d46fe5d6291e2cc3
22 changes: 20 additions & 2 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,23 @@ setiter_len(PyObject *op, PyObject *Py_UNUSED(ignored))
{
setiterobject *si = (setiterobject*)op;
Py_ssize_t len = 0;
PySetObject *so = si->si_set;
if (so != NULL && si->si_used == FT_ATOMIC_LOAD_SSIZE_RELAXED(so->used))
#ifdef Py_GIL_DISABLED
Comment thread
hyongtao-code marked this conversation as resolved.
Outdated
Comment thread
hyongtao-code marked this conversation as resolved.
Outdated
PyObject *so_obj = FT_ATOMIC_LOAD_PTR_ACQUIRE(si->si_set);
if (so_obj != NULL) {
/* Turn borrowed si->si_set into a strong ref safely. */
if (_Py_TryIncrefCompare((PyObject **)&si->si_set, so_obj)) {
PySetObject *so = (PySetObject *)so_obj;
if (si->si_used == FT_ATOMIC_LOAD_SSIZE_RELAXED(so->used)) {
len = si->len;
}
Py_DECREF(so_obj);
}
}
#else
if (si->si_set != NULL && si->si_used == si->si_set->used) {
len = si->len;
}
#endif
return PyLong_FromSsize_t(len);
}

Expand Down Expand Up @@ -1125,7 +1139,11 @@ static PyObject *setiter_iternext(PyObject *self)
Py_END_CRITICAL_SECTION();
si->si_pos = i+1;
if (key == NULL) {
#ifdef Py_GIL_DISABLED
Comment thread
hyongtao-code marked this conversation as resolved.
Outdated
FT_ATOMIC_STORE_PTR_RELEASE(si->si_set, NULL);
#else
si->si_set = NULL;
#endif
Py_DECREF(so);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the decref to the section

       /* exhausted */
        si->si_pos = -1;
        si->len = 0;

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d prefer not to move the Py_DECREF into the Py_BEGIN_CRITICAL_SECTION block.

return NULL;
}
Expand Down
Loading