summaryrefslogtreecommitdiffstats
path: root/Python/traceback.c
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 /Python/traceback.c
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 'Python/traceback.c')
-rw-r--r--Python/traceback.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 438a2c4..99b63af 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -4,7 +4,7 @@
#include "Python.h"
#include "code.h"
-#include "frameobject.h"
+#include "frameobject.h" // PyFrame_GetBack()
#include "structmember.h" // PyMemberDef
#include "osdefs.h" // SEP
#ifdef HAVE_FCNTL_H
@@ -798,22 +798,31 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
PUTS(fd, "Stack (most recent call first):\n");
}
- frame = tstate->frame;
+ frame = PyThreadState_GetFrame(tstate);
if (frame == NULL) {
PUTS(fd, "<no Python frame>\n");
return;
}
depth = 0;
- while (frame != NULL) {
+ while (1) {
if (MAX_FRAME_DEPTH <= depth) {
+ Py_DECREF(frame);
PUTS(fd, " ...\n");
break;
}
- if (!PyFrame_Check(frame))
+ if (!PyFrame_Check(frame)) {
+ Py_DECREF(frame);
break;
+ }
dump_frame(fd, frame);
- frame = frame->f_back;
+ PyFrameObject *back = PyFrame_GetBack(frame);
+ Py_DECREF(frame);
+
+ if (back == NULL) {
+ break;
+ }
+ frame = back;
depth++;
}
}