Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
gh-140431: Fix GC crash due to partially initialized coroutines
The `make_gen()` function creates and tracks generator/coro objects, but
doesn't fully initialize all the fields. At a minimum, we need to
initialize all the fields that may be accessed by gen_traverse because
the call to `compute_cr_origin()` can trigger a GC.
  • Loading branch information
colesbury committed Oct 22, 2025
commit c1e2a6eb62c4271431d2455281b5b10d9aa3f1c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in Python's :term:`garbage collector <garbage collection>` due to
partially initialized :term:`coroutine` objects when coroutine origin tracking
depth is enabled (:func:`sys.set_coroutine_origin_tracking_depth`).
1 change: 1 addition & 0 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
gen->gi_weakreflist = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.previous_item = NULL;
gen->gi_iframe.f_executable = PyStackRef_None;
assert(func->func_name != NULL);
gen->gi_name = Py_NewRef(func->func_name);
assert(func->func_qualname != NULL);
Expand Down
Loading