gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767)

This commit is contained in:
Mikhail Efimov 2025-10-31 13:09:22 +03:00 committed by GitHub
parent ac1ffd7785
commit d17f28fed5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 1 deletions

View file

@ -407,11 +407,12 @@ gen_close(PyObject *self, PyObject *args)
}
_PyInterpreterFrame *frame = &gen->gi_iframe;
if (is_resume(frame->instr_ptr)) {
bool no_unwind_tools = _PyEval_NoToolsForUnwind(_PyThreadState_GET());
/* We can safely ignore the outermost try block
* as it is automatically generated to handle
* StopIteration. */
int oparg = frame->instr_ptr->op.arg;
if (oparg & RESUME_OPARG_DEPTH1_MASK) {
if (oparg & RESUME_OPARG_DEPTH1_MASK && no_unwind_tools) {
// RESUME after YIELD_VALUE and exception depth is 1
assert((oparg & RESUME_OPARG_LOCATION_MASK) != RESUME_AT_FUNC_START);
gen->gi_frame_state = FRAME_COMPLETED;