mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767)
This commit is contained in:
parent
ac1ffd7785
commit
d17f28fed5
6 changed files with 30 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue