From 088d15c842d57bdfd50d942d315e8f7761331de6 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 17 Jun 2016 13:25:01 +0300 Subject: Issue #27336: Fix compilation failures --without-threads --- Python/traceback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index 62a6b1e1a2..59552cae85 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -745,7 +745,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp, if (current_tstate == NULL) { /* Call _PyThreadState_UncheckedGet() instead of PyThreadState_Get() to not fail with a fatal error if the thread state is NULL. */ - current_thread = _PyThreadState_UncheckedGet(); + current_tstate = _PyThreadState_UncheckedGet(); } if (interp == NULL) { -- cgit v1.2.1 From 471ec83b9274103af494dac719ea8a7eb64ea351 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Mon, 15 Aug 2016 13:11:34 +1000 Subject: Issue #26823: Abbreviate recursive tracebacks Large sections of repeated lines in tracebacks are now abbreviated as "[Previous line repeated {count} more times]" by both the traceback module and the builtin traceback rendering. Patch by Emanuel Barry. --- Python/traceback.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index 59552cae85..15cde444f4 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -412,6 +412,11 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) { int err = 0; long depth = 0; + PyObject *last_file = NULL; + int last_line = -1; + PyObject *last_name = NULL; + long cnt = 0; + PyObject *line; PyTracebackObject *tb1 = tb; while (tb1 != NULL) { depth++; @@ -419,16 +424,39 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) } while (tb != NULL && err == 0) { if (depth <= limit) { - err = tb_displayline(f, - tb->tb_frame->f_code->co_filename, - tb->tb_lineno, - tb->tb_frame->f_code->co_name); + if (last_file != NULL && + tb->tb_frame->f_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) { + cnt++; + } else { + if (cnt > 3) { + line = PyUnicode_FromFormat( + " [Previous line repeated %d more times]\n", cnt-3); + err = PyFile_WriteObject(line, f, Py_PRINT_RAW); + } + last_file = tb->tb_frame->f_code->co_filename; + last_line = tb->tb_lineno; + last_name = tb->tb_frame->f_code->co_name; + cnt = 0; + } + if (cnt < 3) + err = tb_displayline(f, + tb->tb_frame->f_code->co_filename, + tb->tb_lineno, + tb->tb_frame->f_code->co_name); } depth--; tb = tb->tb_next; if (err == 0) err = PyErr_CheckSignals(); } + if (cnt > 3) { + line = PyUnicode_FromFormat( + " [Previous line repeated %d more times]\n", cnt-3); + err = PyFile_WriteObject(line, f, Py_PRINT_RAW); + } return err; } -- cgit v1.2.1 From 0a4fae5c7e47a3ad5314160df05d00527f5922ab Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 20 Aug 2016 03:05:13 +0200 Subject: Fix reference leak in tb_printinternal() Issue #26823. --- Python/traceback.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index 15cde444f4..b33156eaa7 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -435,6 +435,7 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) line = PyUnicode_FromFormat( " [Previous line repeated %d more times]\n", cnt-3); err = PyFile_WriteObject(line, f, Py_PRINT_RAW); + Py_DECREF(line); } last_file = tb->tb_frame->f_code->co_filename; last_line = tb->tb_lineno; @@ -456,6 +457,7 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) line = PyUnicode_FromFormat( " [Previous line repeated %d more times]\n", cnt-3); err = PyFile_WriteObject(line, f, Py_PRINT_RAW); + Py_DECREF(line); } return err; } -- cgit v1.2.1 From 06d0337c7565e35432fe744713260e2ef3e8a545 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Sep 2016 18:16:01 -0700 Subject: Avoid calling functions with an empty string as format string Directly pass NULL rather than an empty string. --- Python/traceback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index b33156eaa7..e8aac1bad8 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -314,7 +314,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) if (fob == NULL) { PyErr_Clear(); - res = _PyObject_CallMethodId(binary, &PyId_close, ""); + res = _PyObject_CallMethodId(binary, &PyId_close, NULL); Py_DECREF(binary); if (res) Py_DECREF(res); @@ -334,7 +334,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) break; } } - res = _PyObject_CallMethodId(fob, &PyId_close, ""); + res = _PyObject_CallMethodId(fob, &PyId_close, NULL); if (res) Py_DECREF(res); else -- cgit v1.2.1