summaryrefslogtreecommitdiffstats
path: root/Python/traceback.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-28 17:01:31 (GMT)
committerGitHub <noreply@github.com>2020-04-28 17:01:31 (GMT)
commita42ca74fa30227e2f89a619332557cf093a937d5 (patch)
treea3097e76897d8f8a0f054cab0736fd3cff80f8da /Python/traceback.c
parentb8f704d2190125a7750b50cd9b67267b9c20fd43 (diff)
downloadcpython-a42ca74fa30227e2f89a619332557cf093a937d5.zip
cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.gz
cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.bz2
bpo-40421: Add PyFrame_GetCode() function (GH-19757)
PyFrame_GetCode(frame): return a borrowed reference to the frame code. Replace frame->f_code with PyFrame_GetCode(frame) in most code, except in frameobject.c, genobject.c and ceval.c. Also add PyFrame_GetLineNumber() to the limited C API.
Diffstat (limited to 'Python/traceback.c')
-rw-r--r--Python/traceback.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 85e9124..1ea6cba 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -560,24 +560,23 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
tb = tb->tb_next;
}
while (tb != NULL && err == 0) {
+ PyCodeObject *code = PyFrame_GetCode(tb->tb_frame);
if (last_file == NULL ||
- tb->tb_frame->f_code->co_filename != last_file ||
+ code->co_filename != last_file ||
last_line == -1 || tb->tb_lineno != last_line ||
- last_name == NULL || tb->tb_frame->f_code->co_name != last_name) {
+ last_name == NULL || code->co_name != last_name) {
if (cnt > TB_RECURSIVE_CUTOFF) {
err = tb_print_line_repeated(f, cnt);
}
- last_file = tb->tb_frame->f_code->co_filename;
+ last_file = code->co_filename;
last_line = tb->tb_lineno;
- last_name = tb->tb_frame->f_code->co_name;
+ last_name = code->co_name;
cnt = 0;
}
cnt++;
if (err == 0 && cnt <= TB_RECURSIVE_CUTOFF) {
- err = tb_displayline(f,
- tb->tb_frame->f_code->co_filename,
- tb->tb_lineno,
- tb->tb_frame->f_code->co_name);
+ err = tb_displayline(f, code->co_filename, tb->tb_lineno,
+ code->co_name);
if (err == 0) {
err = PyErr_CheckSignals();
}
@@ -756,7 +755,7 @@ dump_frame(int fd, PyFrameObject *frame)
PyCodeObject *code;
int lineno;
- code = frame->f_code;
+ code = PyFrame_GetCode(frame);
PUTS(fd, " File ");
if (code != NULL && code->co_filename != NULL
&& PyUnicode_Check(code->co_filename))