Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6d023c9 | 1995-01-04 19:12:13 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 32 | /* Traceback implementation */ |
| 33 | |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | |
| 36 | #include "compile.h" |
| 37 | #include "frameobject.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 38 | #include "structmember.h" |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 39 | #include "osdefs.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 40 | |
| 41 | typedef struct _tracebackobject { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 42 | PyObject_HEAD |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 43 | struct _tracebackobject *tb_next; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 44 | PyFrameObject *tb_frame; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 45 | int tb_lasti; |
| 46 | int tb_lineno; |
| 47 | } tracebackobject; |
| 48 | |
| 49 | #define OFF(x) offsetof(tracebackobject, x) |
| 50 | |
| 51 | static struct memberlist tb_memberlist[] = { |
| 52 | {"tb_next", T_OBJECT, OFF(tb_next)}, |
| 53 | {"tb_frame", T_OBJECT, OFF(tb_frame)}, |
| 54 | {"tb_lasti", T_INT, OFF(tb_lasti)}, |
| 55 | {"tb_lineno", T_INT, OFF(tb_lineno)}, |
| 56 | {NULL} /* Sentinel */ |
| 57 | }; |
| 58 | |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 59 | static PyObject * |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 60 | tb_getattr(tb, name) |
| 61 | tracebackobject *tb; |
| 62 | char *name; |
| 63 | { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 64 | return PyMember_Get((char *)tb, tb_memberlist, name); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void |
| 68 | tb_dealloc(tb) |
| 69 | tracebackobject *tb; |
| 70 | { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 71 | Py_XDECREF(tb->tb_next); |
| 72 | Py_XDECREF(tb->tb_frame); |
| 73 | PyMem_DEL(tb); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Guido van Rossum | 9d78d8d | 1995-09-18 21:29:36 +0000 | [diff] [blame] | 76 | #define Tracebacktype PyTraceBack_Type |
| 77 | #define is_tracebackobject PyTraceBack_Check |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 78 | |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 79 | PyTypeObject Tracebacktype = { |
| 80 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 81 | 0, |
| 82 | "traceback", |
| 83 | sizeof(tracebackobject), |
| 84 | 0, |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 85 | (destructor)tb_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 86 | 0, /*tp_print*/ |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 87 | (getattrfunc)tb_getattr, /*tp_getattr*/ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 88 | 0, /*tp_setattr*/ |
| 89 | 0, /*tp_compare*/ |
| 90 | 0, /*tp_repr*/ |
| 91 | 0, /*tp_as_number*/ |
| 92 | 0, /*tp_as_sequence*/ |
| 93 | 0, /*tp_as_mapping*/ |
| 94 | }; |
| 95 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 96 | static tracebackobject * |
| 97 | newtracebackobject(next, frame, lasti, lineno) |
| 98 | tracebackobject *next; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 99 | PyFrameObject *frame; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 100 | int lasti, lineno; |
| 101 | { |
| 102 | tracebackobject *tb; |
| 103 | if ((next != NULL && !is_tracebackobject(next)) || |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 104 | frame == NULL || !PyFrame_Check(frame)) { |
| 105 | PyErr_BadInternalCall(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 106 | return NULL; |
| 107 | } |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 108 | tb = PyObject_NEW(tracebackobject, &Tracebacktype); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 109 | if (tb != NULL) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 110 | Py_XINCREF(next); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 111 | tb->tb_next = next; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 112 | Py_XINCREF(frame); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 113 | tb->tb_frame = frame; |
| 114 | tb->tb_lasti = lasti; |
| 115 | tb->tb_lineno = lineno; |
| 116 | } |
| 117 | return tb; |
| 118 | } |
| 119 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 120 | int |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 121 | PyTraceBack_Here(frame) |
| 122 | PyFrameObject *frame; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 123 | { |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 124 | PyThreadState *tstate = frame->f_tstate; |
| 125 | tracebackobject *oldtb = (tracebackobject *) tstate->curexc_traceback; |
| 126 | tracebackobject *tb = newtracebackobject(oldtb, |
| 127 | frame, frame->f_lasti, frame->f_lineno); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 128 | if (tb == NULL) |
| 129 | return -1; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 130 | tstate->curexc_traceback = (PyObject *)tb; |
| 131 | Py_XDECREF(oldtb); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 135 | static int |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 136 | tb_displayline(f, filename, lineno, name) |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 137 | PyObject *f; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 138 | char *filename; |
| 139 | int lineno; |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 140 | char *name; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 141 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 142 | int err = 0; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 143 | FILE *xfp; |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 144 | char linebuf[1000]; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 145 | int i; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 146 | if (filename == NULL || name == NULL) |
| 147 | return -1; |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 148 | #ifdef MPW |
| 149 | /* This is needed by MPW's File and Line commands */ |
| 150 | #define FMT " File \"%.900s\"; line %d # in %s\n" |
| 151 | #else |
| 152 | /* This is needed by Emacs' compile command */ |
| 153 | #define FMT " File \"%.900s\", line %d, in %s\n" |
| 154 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 155 | xfp = fopen(filename, "r"); |
| 156 | if (xfp == NULL) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 157 | /* Search tail of filename in sys.path before giving up */ |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 158 | PyObject *path; |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 159 | char *tail = strrchr(filename, SEP); |
| 160 | if (tail == NULL) |
| 161 | tail = filename; |
| 162 | else |
| 163 | tail++; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 164 | path = PySys_GetObject("path"); |
| 165 | if (path != NULL && PyList_Check(path)) { |
| 166 | int npath = PyList_Size(path); |
Guido van Rossum | bfd5d755 | 1994-09-29 09:38:04 +0000 | [diff] [blame] | 167 | int taillen = strlen(tail); |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 168 | char namebuf[MAXPATHLEN+1]; |
| 169 | for (i = 0; i < npath; i++) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 170 | PyObject *v = PyList_GetItem(path, i); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 171 | if (v == NULL) { |
| 172 | PyErr_Clear(); |
| 173 | break; |
| 174 | } |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 175 | if (PyString_Check(v)) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 176 | int len; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 177 | len = PyString_Size(v); |
Guido van Rossum | bfd5d755 | 1994-09-29 09:38:04 +0000 | [diff] [blame] | 178 | if (len + 1 + taillen >= MAXPATHLEN) |
| 179 | continue; /* Too long */ |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 180 | strcpy(namebuf, PyString_AsString(v)); |
Guido van Rossum | 6bf62da | 1997-04-11 20:37:35 +0000 | [diff] [blame] | 181 | if ((int)strlen(namebuf) != len) |
Guido van Rossum | bfd5d755 | 1994-09-29 09:38:04 +0000 | [diff] [blame] | 182 | continue; /* v contains '\0' */ |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 183 | if (len > 0 && namebuf[len-1] != SEP) |
| 184 | namebuf[len++] = SEP; |
| 185 | strcpy(namebuf+len, tail); |
| 186 | xfp = fopen(namebuf, "r"); |
| 187 | if (xfp != NULL) { |
| 188 | filename = namebuf; |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 194 | } |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 195 | sprintf(linebuf, FMT, filename, lineno, name); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 196 | err = PyFile_WriteString(linebuf, f); |
| 197 | if (xfp == NULL || err != 0) |
| 198 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 199 | for (i = 0; i < lineno; i++) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 200 | if (fgets(linebuf, sizeof linebuf, xfp) == NULL) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | if (i == lineno) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 204 | char *p = linebuf; |
Guido van Rossum | e78c5d0 | 1995-07-07 22:45:41 +0000 | [diff] [blame] | 205 | while (*p == ' ' || *p == '\t' || *p == '\014') |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 206 | p++; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 207 | err = PyFile_WriteString(" ", f); |
| 208 | if (err == 0) { |
| 209 | err = PyFile_WriteString(p, f); |
| 210 | if (err == 0 && strchr(p, '\n') == NULL) |
| 211 | err = PyFile_WriteString("\n", f); |
| 212 | } |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 213 | } |
| 214 | fclose(xfp); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 215 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 218 | static int |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 219 | tb_printinternal(tb, f, limit) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 220 | tracebackobject *tb; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 221 | PyObject *f; |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 222 | int limit; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 223 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 224 | int err = 0; |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 225 | int depth = 0; |
| 226 | tracebackobject *tb1 = tb; |
| 227 | while (tb1 != NULL) { |
| 228 | depth++; |
| 229 | tb1 = tb1->tb_next; |
| 230 | } |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 231 | while (tb != NULL && err == 0) { |
Guido van Rossum | b3f515a | 1997-01-24 04:02:55 +0000 | [diff] [blame] | 232 | if (depth <= limit) { |
Guido van Rossum | 73237c5 | 1997-05-05 20:53:25 +0000 | [diff] [blame] | 233 | if (Py_OptimizeFlag) |
| 234 | tb->tb_lineno = PyCode_Addr2Line( |
| 235 | tb->tb_frame->f_code, tb->tb_lasti); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 236 | err = tb_displayline(f, |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 237 | PyString_AsString( |
| 238 | tb->tb_frame->f_code->co_filename), |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 239 | tb->tb_lineno, |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 240 | PyString_AsString(tb->tb_frame->f_code->co_name)); |
Guido van Rossum | b3f515a | 1997-01-24 04:02:55 +0000 | [diff] [blame] | 241 | } |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 242 | depth--; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 243 | tb = tb->tb_next; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 244 | if (err == 0) |
| 245 | err = PyErr_CheckSignals(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 246 | } |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 247 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | int |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 251 | PyTraceBack_Print(v, f) |
| 252 | PyObject *v; |
| 253 | PyObject *f; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 254 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 255 | int err; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 256 | PyObject *limitv; |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 257 | int limit = 1000; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 258 | if (v == NULL) |
| 259 | return 0; |
| 260 | if (!is_tracebackobject(v)) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 261 | PyErr_BadInternalCall(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 262 | return -1; |
| 263 | } |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 264 | limitv = PySys_GetObject("tracebacklimit"); |
| 265 | if (limitv && PyInt_Check(limitv)) { |
| 266 | limit = PyInt_AsLong(limitv); |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 267 | if (limit <= 0) |
| 268 | return 0; |
| 269 | } |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 270 | err = PyFile_WriteString("Traceback (innermost last):\n", f); |
| 271 | if (!err) |
| 272 | err = tb_printinternal((tracebackobject *)v, f, limit); |
| 273 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 274 | } |