From 703647732359200c54f1d2e695cc3a06b9a96c9a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 29 Apr 2020 03:28:46 +0200 Subject: bpo-40421: Add PyFrame_GetBack() function (GH-19765) New PyFrame_GetBack() function: get the frame next outer frame. Replace frame->f_back with PyFrame_GetBack(frame) in most code but frameobject.c, ceval.c and genobject.c. --- Python/sysmodule.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 92ea5e7d637..914beb7e127 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -16,7 +16,7 @@ Data members: #include "Python.h" #include "code.h" -#include "frameobject.h" +#include "frameobject.h" // PyFrame_GetBack() #include "pycore_ceval.h" // _Py_RecursionLimitLowerWaterMark() #include "pycore_initconfig.h" #include "pycore_object.h" @@ -1787,14 +1787,17 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - PyFrameObject *f = tstate->frame; + PyFrameObject *f = PyThreadState_GetFrame(tstate); if (_PySys_Audit(tstate, "sys._getframe", "O", f) < 0) { + Py_DECREF(f); return NULL; } while (depth > 0 && f != NULL) { - f = f->f_back; + PyFrameObject *back = PyFrame_GetBack(f); + Py_DECREF(f); + f = back; --depth; } if (f == NULL) { @@ -1802,7 +1805,6 @@ sys__getframe_impl(PyObject *module, int depth) "call stack is not deep enough"); return NULL; } - Py_INCREF(f); return (PyObject*)f; } -- cgit v1.2.3