mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-118272: Clear generator frame's locals when the generator is closed (#118451)
This commit is contained in:
parent
f61de0de64
commit
238efbecab
5 changed files with 39 additions and 5 deletions
|
@ -115,6 +115,18 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
|
||||
{
|
||||
assert(frame->stacktop >= 0);
|
||||
int stacktop = frame->stacktop;
|
||||
frame->stacktop = 0;
|
||||
for (int i = 0; i < stacktop; i++) {
|
||||
Py_XDECREF(frame->localsplus[i]);
|
||||
}
|
||||
Py_CLEAR(frame->f_locals);
|
||||
}
|
||||
|
||||
void
|
||||
_PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
|
||||
{
|
||||
|
@ -135,12 +147,8 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
|
|||
}
|
||||
Py_DECREF(f);
|
||||
}
|
||||
assert(frame->stacktop >= 0);
|
||||
for (int i = 0; i < frame->stacktop; i++) {
|
||||
Py_XDECREF(frame->localsplus[i]);
|
||||
}
|
||||
_PyFrame_ClearLocals(frame);
|
||||
Py_XDECREF(frame->frame_obj);
|
||||
Py_XDECREF(frame->f_locals);
|
||||
Py_DECREF(frame->f_funcobj);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue