summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-29 01:28:46 (GMT)
committerGitHub <noreply@github.com>2020-04-29 01:28:46 (GMT)
commit703647732359200c54f1d2e695cc3a06b9a96c9a (patch)
treef0ccd7a79f270fe9d7c3cba896461f3f7528131b /Modules
parent66abe98a816de84f89e2de4aa78cf09056227c25 (diff)
downloadcpython-703647732359200c54f1d2e695cc3a06b9a96c9a.zip
cpython-703647732359200c54f1d2e695cc3a06b9a96c9a.tar.gz
cpython-703647732359200c54f1d2e695cc3a06b9a96c9a.tar.bz2
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 'Modules')
-rw-r--r--Modules/_tracemalloc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 6f28f7f..ea7e012 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -3,7 +3,7 @@
#include "pycore_pymem.h" // _Py_tracemalloc_config
#include "pycore_traceback.h"
#include "hashtable.h"
-#include "frameobject.h"
+#include "frameobject.h" // PyFrame_GetBack()
#include "clinic/_tracemalloc.c.h"
/*[clinic input]
@@ -434,15 +434,19 @@ traceback_get_frames(traceback_t *traceback)
}
PyFrameObject *pyframe = PyThreadState_GetFrame(tstate);
- Py_XDECREF(pyframe); // use a borrowed reference
- for (; pyframe != NULL; pyframe = pyframe->f_back) {
+ for (; pyframe != NULL;) {
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
assert(traceback->frames[traceback->nframe].filename != NULL);
traceback->nframe++;
}
- if (traceback->total_nframe < UINT16_MAX)
+ if (traceback->total_nframe < UINT16_MAX) {
traceback->total_nframe++;
+ }
+
+ PyFrameObject *back = PyFrame_GetBack(pyframe);
+ Py_DECREF(pyframe);
+ pyframe = back;
}
}