8000 gh-123471: Make concurrent iteration over itertools.pairwise safe under free-threading by eendebakpt · Pull Request #123848 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-123471: Make concurrent iteration over itertools.pairwise safe under free-threading #123848

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

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
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
add missing incref/decref pair
  • Loading branch information
eendebakpt committed Sep 8, 2024
commit f93d93a093dc714f8033d4e6cb34e246d04dec45
7 changes: 6 additions & 1 deletion Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ pairwise_next(pairwiseobject *po)
_Py_atomic_store_int_relaxed(&po->iterator_exhausted, 1);
return NULL;
}
// we need to incref new before handing it over to po->old
Py_INCREF(new);
old = ( PyObject *)_Py_atomic_exchange_ptr(&po->old, new);
// we have acquired old and we hold a reference to it
#endif
Expand Down Expand Up @@ -420,7 +422,10 @@ pairwise_next(pairwiseobject *po)
#ifndef Py_GIL_DISABLED
Py_XSETREF(po->old, new);
#else
// update was already done
// update to old was already done, but we still have to decref new
// note: we can avoid the incref/decref on new, but this would duplicate a
// bit more code from the normal and free-threading build
Py_DECREF(new);
#endif

Py_DECREF(old);
Expand Down
0