mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
GH-96237: Allow non-functions as reference-holder in frames. (GH-96238)
This commit is contained in:
parent
8db7693bbf
commit
c09fa7542c
6 changed files with 26 additions and 13 deletions
|
@ -910,7 +910,7 @@ frame_dealloc(PyFrameObject *f)
|
|||
/* Don't clear code object until the end */
|
||||
co = frame->f_code;
|
||||
frame->f_code = NULL;
|
||||
Py_CLEAR(frame->f_func);
|
||||
Py_CLEAR(frame->f_funcobj);
|
||||
Py_CLEAR(frame->f_locals);
|
||||
PyObject **locals = _PyFrame_GetLocalsArray(frame);
|
||||
for (int i = 0; i < frame->stacktop; i++) {
|
||||
|
@ -1154,10 +1154,12 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
|
|||
// COPY_FREE_VARS has no quickened forms, so no need to use _PyOpcode_Deopt
|
||||
// here:
|
||||
int lasti = _PyInterpreterFrame_LASTI(frame);
|
||||
if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) {
|
||||
if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS
|
||||
&& PyFunction_Check(frame->f_funcobj))
|
||||
{
|
||||
/* Free vars have not been initialized -- Do that */
|
||||
PyCodeObject *co = frame->f_code;
|
||||
PyObject *closure = frame->f_func->func_closure;
|
||||
PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure;
|
||||
int offset = co->co_nlocals + co->co_nplaincellvars;
|
||||
for (int i = 0; i < co->co_nfreevars; ++i) {
|
||||
PyObject *o = PyTuple_GET_ITEM(closure, i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue