diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-29 03:28:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 03:28:46 +0200 |
commit | 703647732359200c54f1d2e695cc3a06b9a96c9a (patch) | |
tree | f0ccd7a79f270fe9d7c3cba896461f3f7528131b /Python/sysmodule.c | |
parent | 66abe98a816de84f89e2de4aa78cf09056227c25 (diff) | |
download | cpython-git-703647732359200c54f1d2e695cc3a06b9a96c9a.tar.gz |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 92ea5e7d63..914beb7e12 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; } |