diff options
Diffstat (limited to 'Python/traceback.c')
-rw-r--r-- | Python/traceback.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index 2bea29e..71ffecd 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -13,7 +13,7 @@ #define OFF(x) offsetof(PyTracebackObject, x) -#define PUTS(fd, str) write(fd, str, (int)strlen(str)) +#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) #define MAX_STRING_LENGTH 500 #define MAX_FRAME_DEPTH 100 #define MAX_NTHREADS 100 @@ -231,7 +231,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * } strcpy(namebuf, PyBytes_AS_STRING(path)); Py_DECREF(path); - if (strlen(namebuf) != len) + if (strlen(namebuf) != (size_t)len) continue; /* v contains '\0' */ if (len > 0 && namebuf[len-1] != SEP) namebuf[len++] = SEP; @@ -512,7 +512,7 @@ dump_decimal(int fd, int value) len++; } while (value); reverse_string(buffer, len); - write(fd, buffer, len); + _Py_write_noraise(fd, buffer, len); } /* Format an integer in range [0; 0xffffffff] to hexadecimal of 'width' digits, @@ -532,7 +532,7 @@ dump_hexadecimal(int fd, unsigned long value, int width) len++; } while (len < width || value); reverse_string(buffer, len); - write(fd, buffer, len); + _Py_write_noraise(fd, buffer, len); } /* Write an unicode object into the file fd using ascii+backslashreplace. @@ -582,15 +582,16 @@ dump_ascii(int fd, PyObject *text) ch = PyUnicode_READ(kind, data, i); else ch = wstr[i]; - if (ch < 128) { + if (' ' <= ch && ch <= 126) { + /* printable ASCII character */ char c = (char)ch; - write(fd, &c, 1); + _Py_write_noraise(fd, &c, 1); } - else if (ch < 0xff) { + else if (ch <= 0xff) { PUTS(fd, "\\x"); dump_hexadecimal(fd, ch, 2); } - else if (ch < 0xffff) { + else if (ch <= 0xffff) { PUTS(fd, "\\u"); dump_hexadecimal(fd, ch, 4); } @@ -618,9 +619,9 @@ dump_frame(int fd, PyFrameObject *frame) if (code != NULL && code->co_filename != NULL && PyUnicode_Check(code->co_filename)) { - write(fd, "\"", 1); + PUTS(fd, "\""); dump_ascii(fd, code->co_filename); - write(fd, "\"", 1); + PUTS(fd, "\""); } else { PUTS(fd, "???"); } @@ -637,7 +638,7 @@ dump_frame(int fd, PyFrameObject *frame) else PUTS(fd, "???"); - write(fd, "\n", 1); + PUTS(fd, "\n"); } static void @@ -667,6 +668,12 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header) } } +/* Dump the traceback of a Python thread into fd. Use write() to write the + traceback and retry if write() is interrupted by a signal (failed with + EINTR), but don't call the Python signal handler. + + The caller is responsible to call PyErr_CheckSignals() to call Python signal + handlers if signals were received. */ void _Py_DumpTraceback(int fd, PyThreadState *tstate) { @@ -685,10 +692,16 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current) PUTS(fd, "Current thread 0x"); else PUTS(fd, "Thread 0x"); - dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(long)*2); + dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(unsigned long)*2); PUTS(fd, " (most recent call first):\n"); } +/* Dump the traceback of all Python threads into fd. Use write() to write the + traceback and retry if write() is interrupted by a signal (failed with + EINTR), but don't call the Python signal handler. + + The caller is responsible to call PyErr_CheckSignals() to call Python signal + handlers if signals were received. */ const char* _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp, PyThreadState *current_thread) @@ -704,10 +717,11 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp, /* Dump the traceback of each thread */ tstate = PyInterpreterState_ThreadHead(interp); nthreads = 0; + _Py_BEGIN_SUPPRESS_IPH do { if (nthreads != 0) - write(fd, "\n", 1); + PUTS(fd, "\n"); if (nthreads >= MAX_NTHREADS) { PUTS(fd, "...\n"); break; @@ -717,6 +731,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp, tstate = PyThreadState_Next(tstate); nthreads++; } while (tstate != NULL); + _Py_END_SUPPRESS_IPH return NULL; } |