[Python-checkins] cpython: Issue #11393: _Py_DumpTraceback() writes the header even if there is no frame

victor.stinner python-checkins at python.org
Fri Apr 1 15:39:59 CEST 2011


http://hg.python.org/cpython/rev/7e3ed426962f
changeset:   69102:7e3ed426962f
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Fri Apr 01 15:34:01 2011 +0200
summary:
  Issue #11393: _Py_DumpTraceback() writes the header even if there is no frame

files:
  Include/traceback.h |   4 +---
  Python/traceback.c  |  14 +++++++-------
  2 files changed, 8 insertions(+), 10 deletions(-)


diff --git a/Include/traceback.h b/Include/traceback.h
--- a/Include/traceback.h
+++ b/Include/traceback.h
@@ -38,8 +38,6 @@
          ...
          File "xxx", line xxx in <xxx>
 
-   Return 0 on success, -1 on error.
-
    This function is written for debug purpose only, to dump the traceback in
    the worst case: after a segmentation fault, at fatal error, etc. That's why,
    it is very limited. Strings are truncated to 100 characters and encoded to
@@ -49,7 +47,7 @@
 
    This function is signal safe. */
 
-PyAPI_DATA(int) _Py_DumpTraceback(
+PyAPI_DATA(void) _Py_DumpTraceback(
     int fd,
     PyThreadState *tstate);
 
diff --git a/Python/traceback.c b/Python/traceback.c
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -556,18 +556,19 @@
     write(fd, "\n", 1);
 }
 
-static int
+static void
 dump_traceback(int fd, PyThreadState *tstate, int write_header)
 {
     PyFrameObject *frame;
     unsigned int depth;
 
+    if (write_header)
+        PUTS(fd, "Traceback (most recent call first):\n");
+
     frame = _PyThreadState_GetFrame(tstate);
     if (frame == NULL)
-        return -1;
+        return;
 
-    if (write_header)
-        PUTS(fd, "Traceback (most recent call first):\n");
     depth = 0;
     while (frame != NULL) {
         if (MAX_FRAME_DEPTH <= depth) {
@@ -580,13 +581,12 @@
         frame = frame->f_back;
         depth++;
     }
-    return 0;
 }
 
-int
+void
 _Py_DumpTraceback(int fd, PyThreadState *tstate)
 {
-    return dump_traceback(fd, tstate, 1);
+    dump_traceback(fd, tstate, 1);
 }
 
 /* Write the thread identifier into the file 'fd': "Current thread 0xHHHH:\" if

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list