gh-118934: Make PyEval_GetLocals return borrowed reference (#119769)

Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
This commit is contained in:
Tian Gao
2024-07-16 12:17:47 -07:00
committed by GitHub
parent 162b41f577
commit e65cb4c6f0
5 changed files with 42 additions and 2 deletions

View File

@@ -1627,6 +1627,7 @@ frame_dealloc(PyFrameObject *f)
Py_CLEAR(f->f_back);
Py_CLEAR(f->f_trace);
Py_CLEAR(f->f_extra_locals);
Py_CLEAR(f->f_locals_cache);
PyObject_GC_Del(f);
Py_XDECREF(co);
Py_TRASHCAN_END;
@@ -1638,6 +1639,7 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg)
Py_VISIT(f->f_back);
Py_VISIT(f->f_trace);
Py_VISIT(f->f_extra_locals);
Py_VISIT(f->f_locals_cache);
if (f->f_frame->owner != FRAME_OWNED_BY_FRAME_OBJECT) {
return 0;
}
@@ -1650,6 +1652,7 @@ frame_tp_clear(PyFrameObject *f)
{
Py_CLEAR(f->f_trace);
Py_CLEAR(f->f_extra_locals);
Py_CLEAR(f->f_locals_cache);
/* locals and stack */
_PyStackRef *locals = _PyFrame_GetLocalsArray(f->f_frame);
@@ -1787,6 +1790,7 @@ _PyFrame_New_NoTrack(PyCodeObject *code)
f->f_trace_opcodes = 0;
f->f_lineno = 0;
f->f_extra_locals = NULL;
f->f_locals_cache = NULL;
return f;
}