Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 2 | /* Traceback implementation */ |
| 3 | |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 5 | |
| 6 | #include "compile.h" |
| 7 | #include "frameobject.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 8 | #include "structmember.h" |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 9 | #include "osdefs.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 10 | |
| 11 | typedef struct _tracebackobject { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 12 | PyObject_HEAD |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 13 | struct _tracebackobject *tb_next; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 14 | PyFrameObject *tb_frame; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 15 | int tb_lasti; |
| 16 | int tb_lineno; |
| 17 | } tracebackobject; |
| 18 | |
| 19 | #define OFF(x) offsetof(tracebackobject, x) |
| 20 | |
| 21 | static struct memberlist tb_memberlist[] = { |
| 22 | {"tb_next", T_OBJECT, OFF(tb_next)}, |
| 23 | {"tb_frame", T_OBJECT, OFF(tb_frame)}, |
| 24 | {"tb_lasti", T_INT, OFF(tb_lasti)}, |
| 25 | {"tb_lineno", T_INT, OFF(tb_lineno)}, |
| 26 | {NULL} /* Sentinel */ |
| 27 | }; |
| 28 | |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 29 | static PyObject * |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 30 | tb_getattr(tracebackobject *tb, char *name) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 31 | { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 32 | return PyMember_Get((char *)tb, tb_memberlist, name); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 36 | tb_dealloc(tracebackobject *tb) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 37 | { |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 38 | Py_TRASHCAN_SAFE_BEGIN(tb) |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 39 | _PyObject_GC_UNTRACK(tb); |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 40 | Py_XDECREF(tb->tb_next); |
| 41 | Py_XDECREF(tb->tb_frame); |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 42 | PyObject_GC_Del(tb); |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 43 | Py_TRASHCAN_SAFE_END(tb) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 46 | static int |
| 47 | tb_traverse(tracebackobject *tb, visitproc visit, void *arg) |
| 48 | { |
| 49 | int err = 0; |
| 50 | if (tb->tb_next) { |
| 51 | err = visit((PyObject *)tb->tb_next, arg); |
| 52 | if (err) |
| 53 | return err; |
| 54 | } |
| 55 | if (tb->tb_frame) |
| 56 | err = visit((PyObject *)tb->tb_frame, arg); |
| 57 | return err; |
| 58 | } |
| 59 | |
| 60 | static void |
| 61 | tb_clear(tracebackobject *tb) |
| 62 | { |
| 63 | Py_XDECREF(tb->tb_next); |
| 64 | Py_XDECREF(tb->tb_frame); |
| 65 | tb->tb_next = NULL; |
| 66 | tb->tb_frame = NULL; |
| 67 | } |
| 68 | |
Tim Peters | d7c3652 | 2001-10-22 19:34:09 +0000 | [diff] [blame] | 69 | PyTypeObject PyTraceBack_Type = { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 70 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 71 | 0, |
| 72 | "traceback", |
| 73 | sizeof(tracebackobject), |
| 74 | 0, |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 75 | (destructor)tb_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 76 | 0, /*tp_print*/ |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 77 | (getattrfunc)tb_getattr, /*tp_getattr*/ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 78 | 0, /*tp_setattr*/ |
| 79 | 0, /*tp_compare*/ |
| 80 | 0, /*tp_repr*/ |
| 81 | 0, /*tp_as_number*/ |
| 82 | 0, /*tp_as_sequence*/ |
| 83 | 0, /*tp_as_mapping*/ |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 84 | 0, /* tp_hash */ |
| 85 | 0, /* tp_call */ |
| 86 | 0, /* tp_str */ |
| 87 | 0, /* tp_getattro */ |
| 88 | 0, /* tp_setattro */ |
| 89 | 0, /* tp_as_buffer */ |
| 90 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 91 | 0, /* tp_doc */ |
| 92 | (traverseproc)tb_traverse, /* tp_traverse */ |
| 93 | (inquiry)tb_clear, /* tp_clear */ |
| 94 | 0, /* tp_richcompare */ |
| 95 | 0, /* tp_weaklistoffset */ |
| 96 | 0, /* tp_iter */ |
| 97 | 0, /* tp_iternext */ |
| 98 | 0, /* tp_methods */ |
| 99 | 0, /* tp_members */ |
| 100 | 0, /* tp_getset */ |
| 101 | 0, /* tp_base */ |
| 102 | 0, /* tp_dict */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 105 | static tracebackobject * |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 106 | newtracebackobject(tracebackobject *next, PyFrameObject *frame, int lasti, |
| 107 | int lineno) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 108 | { |
| 109 | tracebackobject *tb; |
Tim Peters | d7c3652 | 2001-10-22 19:34:09 +0000 | [diff] [blame] | 110 | if ((next != NULL && !PyTraceBack_Check(next)) || |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 111 | frame == NULL || !PyFrame_Check(frame)) { |
| 112 | PyErr_BadInternalCall(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 113 | return NULL; |
| 114 | } |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 115 | tb = PyObject_GC_New(tracebackobject, &PyTraceBack_Type); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 116 | if (tb != NULL) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 117 | Py_XINCREF(next); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 118 | tb->tb_next = next; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 119 | Py_XINCREF(frame); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 120 | tb->tb_frame = frame; |
| 121 | tb->tb_lasti = lasti; |
| 122 | tb->tb_lineno = lineno; |
Jeremy Hylton | fd14d8e | 2001-10-22 22:17:41 +0000 | [diff] [blame] | 123 | _PyObject_GC_TRACK(tb); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 124 | } |
| 125 | return tb; |
| 126 | } |
| 127 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 128 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 129 | PyTraceBack_Here(PyFrameObject *frame) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 130 | { |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 131 | PyThreadState *tstate = frame->f_tstate; |
| 132 | tracebackobject *oldtb = (tracebackobject *) tstate->curexc_traceback; |
| 133 | tracebackobject *tb = newtracebackobject(oldtb, |
| 134 | frame, frame->f_lasti, frame->f_lineno); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 135 | if (tb == NULL) |
| 136 | return -1; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 137 | tstate->curexc_traceback = (PyObject *)tb; |
| 138 | Py_XDECREF(oldtb); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 142 | static int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 143 | tb_displayline(PyObject *f, char *filename, int lineno, char *name) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 144 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 145 | int err = 0; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 146 | FILE *xfp; |
Tim Peters | 6d20b43 | 2001-11-27 20:30:42 +0000 | [diff] [blame^] | 147 | char linebuf[2000]; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 148 | int i; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 149 | if (filename == NULL || name == NULL) |
| 150 | return -1; |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 151 | #ifdef MPW |
| 152 | /* This is needed by MPW's File and Line commands */ |
Tim Peters | 6d20b43 | 2001-11-27 20:30:42 +0000 | [diff] [blame^] | 153 | #define FMT " File \"%.500s\"; line %d # in %.500s\n" |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 154 | #else |
| 155 | /* This is needed by Emacs' compile command */ |
Tim Peters | 6d20b43 | 2001-11-27 20:30:42 +0000 | [diff] [blame^] | 156 | #define FMT " File \"%.500s\", line %d, in %.500s\n" |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 157 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 158 | xfp = fopen(filename, "r"); |
| 159 | if (xfp == NULL) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 160 | /* Search tail of filename in sys.path before giving up */ |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 161 | PyObject *path; |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 162 | char *tail = strrchr(filename, SEP); |
| 163 | if (tail == NULL) |
| 164 | tail = filename; |
| 165 | else |
| 166 | tail++; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 167 | path = PySys_GetObject("path"); |
| 168 | if (path != NULL && PyList_Check(path)) { |
| 169 | int npath = PyList_Size(path); |
Guido van Rossum | 582acec | 2000-06-28 22:07:35 +0000 | [diff] [blame] | 170 | size_t taillen = strlen(tail); |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 171 | char namebuf[MAXPATHLEN+1]; |
| 172 | for (i = 0; i < npath; i++) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 173 | PyObject *v = PyList_GetItem(path, i); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 174 | if (v == NULL) { |
| 175 | PyErr_Clear(); |
| 176 | break; |
| 177 | } |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 178 | if (PyString_Check(v)) { |
Guido van Rossum | 582acec | 2000-06-28 22:07:35 +0000 | [diff] [blame] | 179 | size_t len; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 180 | len = PyString_Size(v); |
Guido van Rossum | bfd5d755 | 1994-09-29 09:38:04 +0000 | [diff] [blame] | 181 | if (len + 1 + taillen >= MAXPATHLEN) |
| 182 | continue; /* Too long */ |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 183 | strcpy(namebuf, PyString_AsString(v)); |
Guido van Rossum | 582acec | 2000-06-28 22:07:35 +0000 | [diff] [blame] | 184 | if (strlen(namebuf) != len) |
Guido van Rossum | bfd5d755 | 1994-09-29 09:38:04 +0000 | [diff] [blame] | 185 | continue; /* v contains '\0' */ |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 186 | if (len > 0 && namebuf[len-1] != SEP) |
| 187 | namebuf[len++] = SEP; |
| 188 | strcpy(namebuf+len, tail); |
| 189 | xfp = fopen(namebuf, "r"); |
| 190 | if (xfp != NULL) { |
| 191 | filename = namebuf; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 197 | } |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 198 | sprintf(linebuf, FMT, filename, lineno, name); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 199 | err = PyFile_WriteString(linebuf, f); |
| 200 | if (xfp == NULL || err != 0) |
| 201 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 202 | for (i = 0; i < lineno; i++) { |
Guido van Rossum | 3aca653 | 1999-09-18 20:49:39 +0000 | [diff] [blame] | 203 | char* pLastChar = &linebuf[sizeof(linebuf)-2]; |
| 204 | do { |
| 205 | *pLastChar = '\0'; |
| 206 | if (fgets(linebuf, sizeof linebuf, xfp) == NULL) |
| 207 | break; |
| 208 | /* fgets read *something*; if it didn't get as |
| 209 | far as pLastChar, it must have found a newline |
| 210 | or hit the end of the file; if pLastChar is \n, |
| 211 | it obviously found a newline; else we haven't |
| 212 | yet seen a newline, so must continue */ |
| 213 | } while (*pLastChar != '\0' && *pLastChar != '\n'); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 214 | } |
| 215 | if (i == lineno) { |
Guido van Rossum | 7169dbb | 1992-02-26 15:17:59 +0000 | [diff] [blame] | 216 | char *p = linebuf; |
Guido van Rossum | e78c5d0 | 1995-07-07 22:45:41 +0000 | [diff] [blame] | 217 | while (*p == ' ' || *p == '\t' || *p == '\014') |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 218 | p++; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 219 | err = PyFile_WriteString(" ", f); |
| 220 | if (err == 0) { |
| 221 | err = PyFile_WriteString(p, f); |
| 222 | if (err == 0 && strchr(p, '\n') == NULL) |
| 223 | err = PyFile_WriteString("\n", f); |
| 224 | } |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 225 | } |
| 226 | fclose(xfp); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 227 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 230 | static int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 231 | tb_printinternal(tracebackobject *tb, PyObject *f, int limit) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 232 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 233 | int err = 0; |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 234 | int depth = 0; |
| 235 | tracebackobject *tb1 = tb; |
| 236 | while (tb1 != NULL) { |
| 237 | depth++; |
| 238 | tb1 = tb1->tb_next; |
| 239 | } |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 240 | while (tb != NULL && err == 0) { |
Guido van Rossum | b3f515a | 1997-01-24 04:02:55 +0000 | [diff] [blame] | 241 | if (depth <= limit) { |
Guido van Rossum | 73237c5 | 1997-05-05 20:53:25 +0000 | [diff] [blame] | 242 | if (Py_OptimizeFlag) |
| 243 | tb->tb_lineno = PyCode_Addr2Line( |
| 244 | tb->tb_frame->f_code, tb->tb_lasti); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 245 | err = tb_displayline(f, |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 246 | PyString_AsString( |
| 247 | tb->tb_frame->f_code->co_filename), |
Guido van Rossum | 13836d9 | 1994-08-29 12:09:58 +0000 | [diff] [blame] | 248 | tb->tb_lineno, |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 249 | PyString_AsString(tb->tb_frame->f_code->co_name)); |
Guido van Rossum | b3f515a | 1997-01-24 04:02:55 +0000 | [diff] [blame] | 250 | } |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 251 | depth--; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 252 | tb = tb->tb_next; |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 253 | if (err == 0) |
| 254 | err = PyErr_CheckSignals(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 255 | } |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 256 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 260 | PyTraceBack_Print(PyObject *v, PyObject *f) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 261 | { |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 262 | int err; |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 263 | PyObject *limitv; |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 264 | int limit = 1000; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 265 | if (v == NULL) |
| 266 | return 0; |
Tim Peters | d7c3652 | 2001-10-22 19:34:09 +0000 | [diff] [blame] | 267 | if (!PyTraceBack_Check(v)) { |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 268 | PyErr_BadInternalCall(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 269 | return -1; |
| 270 | } |
Guido van Rossum | 65bf9f2 | 1997-04-29 18:33:38 +0000 | [diff] [blame] | 271 | limitv = PySys_GetObject("tracebacklimit"); |
| 272 | if (limitv && PyInt_Check(limitv)) { |
| 273 | limit = PyInt_AsLong(limitv); |
Guido van Rossum | 67a5fdb | 1993-12-17 12:09:14 +0000 | [diff] [blame] | 274 | if (limit <= 0) |
| 275 | return 0; |
| 276 | } |
Guido van Rossum | 6d10887 | 2000-03-31 00:39:23 +0000 | [diff] [blame] | 277 | err = PyFile_WriteString("Traceback (most recent call last):\n", f); |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 278 | if (!err) |
| 279 | err = tb_printinternal((tracebackobject *)v, f, limit); |
| 280 | return err; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 281 | } |