Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe #114843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 14, 2024
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Feb 14, 2024
commit 6e170cc130ce662951ce4216a15aaa21ac9fc226
8 changes: 4 additions & 4 deletions 8 Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3393,19 +3393,19 @@ listiter_next(PyObject *self)
{
_PyListIterObject *it = (_PyListIterObject *)self;
Py_ssize_t index = LOAD_SSIZE(it->it_index);
if (it->it_seq == NULL || index < 0) {
if (index < 0) {
return NULL;
}

PyObject *item = list_get_item_ref(it->it_seq, index);
if (item == NULL) {
// out-of-bounds
STORE_SSIZE(it->it_index, -1);
#ifndef Py_GIL_DISABLED
PyListObject *seq = it->it_seq;
it->it_seq = NULL;
Py_DECREF(seq);
#endif
STORE_SSIZE(it->it_index, -1);
return NULL;
}
STORE_SSIZE(it->it_index, index + 1);
Expand Down Expand Up @@ -3551,19 +3551,19 @@ listreviter_next(PyObject *self)
assert(PyList_Check(seq));

Py_ssize_t index = LOAD_SSIZE(it->it_index);
if (it->it_seq == NULL || index < 0) {
if (index < 0) {
return NULL;
}
PyObject *item = list_get_item_ref(seq, index);
if (item != NULL) {
STORE_SSIZE(it->it_index, index - 1);
return item;
}
STORE_SSIZE(it->it_index, -1);
colesbury marked this conversation as resolved.
Show resolved Hide resolved
#ifndef Py_GIL_DISABLED
it->it_seq = NULL;
Py_DECREF(seq);
#endif
STORE_SSIZE(it->it_index, -1);
return NULL;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.