Mercurial > cpython-lru_cache-weakref
annotate Python/traceback.c @ 13930:4eaa463c031a legacy-trunk
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
did the same anyway.
I'm not sure what to do with Tools/compiler/compiler/* -- that isn't part of
distutils, is it ? Should it try to be compatible with old bytecode version ?
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Fri, 11 Aug 2000 22:15:52 +0000 |
| parents | f79434ee41fa |
| children | 6f6f965c5e2d |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
5 All rights reserved. |
| 145 | 6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 145 | 9 ******************************************************************/ |
| 10 | |
| 86 | 11 /* Traceback implementation */ |
| 12 | |
| 5372 | 13 #include "Python.h" |
| 86 | 14 |
| 15 #include "compile.h" | |
| 16 #include "frameobject.h" | |
| 17 #include "structmember.h" | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
18 #include "osdefs.h" |
| 86 | 19 |
| 20 typedef struct _tracebackobject { | |
| 5372 | 21 PyObject_HEAD |
| 86 | 22 struct _tracebackobject *tb_next; |
| 5372 | 23 PyFrameObject *tb_frame; |
| 86 | 24 int tb_lasti; |
| 25 int tb_lineno; | |
| 26 } tracebackobject; | |
| 27 | |
| 28 #define OFF(x) offsetof(tracebackobject, x) | |
| 29 | |
| 30 static struct memberlist tb_memberlist[] = { | |
| 31 {"tb_next", T_OBJECT, OFF(tb_next)}, | |
| 32 {"tb_frame", T_OBJECT, OFF(tb_frame)}, | |
| 33 {"tb_lasti", T_INT, OFF(tb_lasti)}, | |
| 34 {"tb_lineno", T_INT, OFF(tb_lineno)}, | |
| 35 {NULL} /* Sentinel */ | |
| 36 }; | |
| 37 | |
| 5372 | 38 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
39 tb_getattr(tracebackobject *tb, char *name) |
| 86 | 40 { |
| 5372 | 41 return PyMember_Get((char *)tb, tb_memberlist, name); |
| 86 | 42 } |
| 43 | |
| 44 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
45 tb_dealloc(tracebackobject *tb) |
| 86 | 46 { |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11294
diff
changeset
|
47 Py_TRASHCAN_SAFE_BEGIN(tb) |
| 5372 | 48 Py_XDECREF(tb->tb_next); |
| 49 Py_XDECREF(tb->tb_frame); | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12137
diff
changeset
|
50 PyObject_DEL(tb); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11294
diff
changeset
|
51 Py_TRASHCAN_SAFE_END(tb) |
| 86 | 52 } |
| 53 | |
|
3099
d249111d4ccc
spell TraceBack with capital B
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
54 #define Tracebacktype PyTraceBack_Type |
|
d249111d4ccc
spell TraceBack with capital B
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
55 #define is_tracebackobject PyTraceBack_Check |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2811
diff
changeset
|
56 |
| 5372 | 57 PyTypeObject Tracebacktype = { |
| 58 PyObject_HEAD_INIT(&PyType_Type) | |
| 86 | 59 0, |
| 60 "traceback", | |
| 61 sizeof(tracebackobject), | |
| 62 0, | |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
63 (destructor)tb_dealloc, /*tp_dealloc*/ |
| 86 | 64 0, /*tp_print*/ |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
65 (getattrfunc)tb_getattr, /*tp_getattr*/ |
| 86 | 66 0, /*tp_setattr*/ |
| 67 0, /*tp_compare*/ | |
| 68 0, /*tp_repr*/ | |
| 69 0, /*tp_as_number*/ | |
| 70 0, /*tp_as_sequence*/ | |
| 71 0, /*tp_as_mapping*/ | |
| 72 }; | |
| 73 | |
| 74 static tracebackobject * | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
75 newtracebackobject(tracebackobject *next, PyFrameObject *frame, int lasti, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
76 int lineno) |
| 86 | 77 { |
| 78 tracebackobject *tb; | |
| 79 if ((next != NULL && !is_tracebackobject(next)) || | |
| 5372 | 80 frame == NULL || !PyFrame_Check(frame)) { |
| 81 PyErr_BadInternalCall(); | |
| 86 | 82 return NULL; |
| 83 } | |
| 5372 | 84 tb = PyObject_NEW(tracebackobject, &Tracebacktype); |
| 86 | 85 if (tb != NULL) { |
| 5372 | 86 Py_XINCREF(next); |
| 86 | 87 tb->tb_next = next; |
| 5372 | 88 Py_XINCREF(frame); |
| 86 | 89 tb->tb_frame = frame; |
| 90 tb->tb_lasti = lasti; | |
| 91 tb->tb_lineno = lineno; | |
| 92 } | |
| 93 return tb; | |
| 94 } | |
| 95 | |
| 96 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
97 PyTraceBack_Here(PyFrameObject *frame) |
| 86 | 98 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
99 PyThreadState *tstate = frame->f_tstate; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
100 tracebackobject *oldtb = (tracebackobject *) tstate->curexc_traceback; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
101 tracebackobject *tb = newtracebackobject(oldtb, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
102 frame, frame->f_lasti, frame->f_lineno); |
| 86 | 103 if (tb == NULL) |
| 104 return -1; | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
105 tstate->curexc_traceback = (PyObject *)tb; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
106 Py_XDECREF(oldtb); |
| 86 | 107 return 0; |
| 108 } | |
| 109 | |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
110 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
111 tb_displayline(PyObject *f, char *filename, int lineno, char *name) |
| 86 | 112 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
113 int err = 0; |
| 86 | 114 FILE *xfp; |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
115 char linebuf[1000]; |
| 86 | 116 int i; |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
117 if (filename == NULL || name == NULL) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
118 return -1; |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
119 #ifdef MPW |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
120 /* This is needed by MPW's File and Line commands */ |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
121 #define FMT " File \"%.900s\"; line %d # in %s\n" |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
122 #else |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
123 /* This is needed by Emacs' compile command */ |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
124 #define FMT " File \"%.900s\", line %d, in %s\n" |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
125 #endif |
| 86 | 126 xfp = fopen(filename, "r"); |
| 127 if (xfp == NULL) { | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
128 /* Search tail of filename in sys.path before giving up */ |
| 5372 | 129 PyObject *path; |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
130 char *tail = strrchr(filename, SEP); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
131 if (tail == NULL) |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
132 tail = filename; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
133 else |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
134 tail++; |
| 5372 | 135 path = PySys_GetObject("path"); |
| 136 if (path != NULL && PyList_Check(path)) { | |
| 137 int npath = PyList_Size(path); | |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
138 size_t taillen = strlen(tail); |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
139 char namebuf[MAXPATHLEN+1]; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
140 for (i = 0; i < npath; i++) { |
| 5372 | 141 PyObject *v = PyList_GetItem(path, i); |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
142 if (v == NULL) { |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
143 PyErr_Clear(); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
144 break; |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
145 } |
| 5372 | 146 if (PyString_Check(v)) { |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
147 size_t len; |
| 5372 | 148 len = PyString_Size(v); |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
149 if (len + 1 + taillen >= MAXPATHLEN) |
|
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
150 continue; /* Too long */ |
| 5372 | 151 strcpy(namebuf, PyString_AsString(v)); |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
152 if (strlen(namebuf) != len) |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
153 continue; /* v contains '\0' */ |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
154 if (len > 0 && namebuf[len-1] != SEP) |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
155 namebuf[len++] = SEP; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
156 strcpy(namebuf+len, tail); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
157 xfp = fopen(namebuf, "r"); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
158 if (xfp != NULL) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
159 filename = namebuf; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
160 break; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
161 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
162 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
163 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
164 } |
| 86 | 165 } |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
166 sprintf(linebuf, FMT, filename, lineno, name); |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
167 err = PyFile_WriteString(linebuf, f); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
168 if (xfp == NULL || err != 0) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
169 return err; |
| 86 | 170 for (i = 0; i < lineno; i++) { |
|
11294
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
171 char* pLastChar = &linebuf[sizeof(linebuf)-2]; |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
172 do { |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
173 *pLastChar = '\0'; |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
174 if (fgets(linebuf, sizeof linebuf, xfp) == NULL) |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
175 break; |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
176 /* fgets read *something*; if it didn't get as |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
177 far as pLastChar, it must have found a newline |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
178 or hit the end of the file; if pLastChar is \n, |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
179 it obviously found a newline; else we haven't |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
180 yet seen a newline, so must continue */ |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
181 } while (*pLastChar != '\0' && *pLastChar != '\n'); |
| 86 | 182 } |
| 183 if (i == lineno) { | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
184 char *p = linebuf; |
|
2811
07fc4fefb683
ignore control-l (parallelling change to tokenizer.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
185 while (*p == ' ' || *p == '\t' || *p == '\014') |
| 86 | 186 p++; |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
187 err = PyFile_WriteString(" ", f); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
188 if (err == 0) { |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
189 err = PyFile_WriteString(p, f); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
190 if (err == 0 && strchr(p, '\n') == NULL) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
191 err = PyFile_WriteString("\n", f); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
192 } |
| 86 | 193 } |
| 194 fclose(xfp); | |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
195 return err; |
| 86 | 196 } |
| 197 | |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
198 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
199 tb_printinternal(tracebackobject *tb, PyObject *f, int limit) |
| 86 | 200 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
201 int err = 0; |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
202 int depth = 0; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
203 tracebackobject *tb1 = tb; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
204 while (tb1 != NULL) { |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
205 depth++; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
206 tb1 = tb1->tb_next; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
207 } |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
208 while (tb != NULL && err == 0) { |
|
5046
658815230546
Get the line number from PyCode_Addr2Line instead of believing
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
209 if (depth <= limit) { |
|
5404
3780cce14f7d
Only use PyCode_Addr2Line to get tb_lineno when Py_OptimizeFlag is set.
Guido van Rossum <guido@python.org>
parents:
5372
diff
changeset
|
210 if (Py_OptimizeFlag) |
|
3780cce14f7d
Only use PyCode_Addr2Line to get tb_lineno when Py_OptimizeFlag is set.
Guido van Rossum <guido@python.org>
parents:
5372
diff
changeset
|
211 tb->tb_lineno = PyCode_Addr2Line( |
|
3780cce14f7d
Only use PyCode_Addr2Line to get tb_lineno when Py_OptimizeFlag is set.
Guido van Rossum <guido@python.org>
parents:
5372
diff
changeset
|
212 tb->tb_frame->f_code, tb->tb_lasti); |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
213 err = tb_displayline(f, |
| 5372 | 214 PyString_AsString( |
| 215 tb->tb_frame->f_code->co_filename), | |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
216 tb->tb_lineno, |
| 5372 | 217 PyString_AsString(tb->tb_frame->f_code->co_name)); |
|
5046
658815230546
Get the line number from PyCode_Addr2Line instead of believing
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
218 } |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
219 depth--; |
| 86 | 220 tb = tb->tb_next; |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
221 if (err == 0) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
222 err = PyErr_CheckSignals(); |
| 86 | 223 } |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
224 return err; |
| 86 | 225 } |
| 226 | |
| 227 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
228 PyTraceBack_Print(PyObject *v, PyObject *f) |
| 86 | 229 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
230 int err; |
| 5372 | 231 PyObject *limitv; |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
232 int limit = 1000; |
| 86 | 233 if (v == NULL) |
| 234 return 0; | |
| 235 if (!is_tracebackobject(v)) { | |
| 5372 | 236 PyErr_BadInternalCall(); |
| 86 | 237 return -1; |
| 238 } | |
| 5372 | 239 limitv = PySys_GetObject("tracebacklimit"); |
| 240 if (limitv && PyInt_Check(limitv)) { | |
| 241 limit = PyInt_AsLong(limitv); | |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
242 if (limit <= 0) |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
243 return 0; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
244 } |
|
12137
5b5581af951c
Change traceback error message to "most recent call last" from
Guido van Rossum <guido@python.org>
parents:
11999
diff
changeset
|
245 err = PyFile_WriteString("Traceback (most recent call last):\n", f); |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
246 if (!err) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
247 err = tb_printinternal((tracebackobject *)v, f, limit); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
248 return err; |
| 86 | 249 } |
