Mercurial > cpython-lru_cache-weakref
annotate Python/traceback.c @ 5180:6bc56259cc4c legacy-trunk
When -O is given, use ".pyo" instead of ".pyc".
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 11 Mar 1997 18:37:35 +0000 |
| parents | 658815230546 |
| children | c72c7e1930b3 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3099
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 86 | 32 /* Traceback implementation */ |
| 33 | |
| 34 #include "allobjects.h" | |
| 35 | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
36 #include "sysmodule.h" |
| 86 | 37 #include "compile.h" |
| 38 #include "frameobject.h" | |
| 39 #include "traceback.h" | |
| 40 #include "structmember.h" | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
41 #include "osdefs.h" |
| 86 | 42 |
| 43 typedef struct _tracebackobject { | |
| 44 OB_HEAD | |
| 45 struct _tracebackobject *tb_next; | |
| 46 frameobject *tb_frame; | |
| 47 int tb_lasti; | |
| 48 int tb_lineno; | |
| 49 } tracebackobject; | |
| 50 | |
| 51 #define OFF(x) offsetof(tracebackobject, x) | |
| 52 | |
| 53 static struct memberlist tb_memberlist[] = { | |
| 54 {"tb_next", T_OBJECT, OFF(tb_next)}, | |
| 55 {"tb_frame", T_OBJECT, OFF(tb_frame)}, | |
| 56 {"tb_lasti", T_INT, OFF(tb_lasti)}, | |
| 57 {"tb_lineno", T_INT, OFF(tb_lineno)}, | |
| 58 {NULL} /* Sentinel */ | |
| 59 }; | |
| 60 | |
| 61 static object * | |
| 62 tb_getattr(tb, name) | |
| 63 tracebackobject *tb; | |
| 64 char *name; | |
| 65 { | |
| 66 return getmember((char *)tb, tb_memberlist, name); | |
| 67 } | |
| 68 | |
| 69 static void | |
| 70 tb_dealloc(tb) | |
| 71 tracebackobject *tb; | |
| 72 { | |
| 73 XDECREF(tb->tb_next); | |
| 74 XDECREF(tb->tb_frame); | |
| 75 DEL(tb); | |
| 76 } | |
| 77 | |
|
3099
d249111d4ccc
spell TraceBack with capital B
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
78 #define Tracebacktype PyTraceBack_Type |
|
d249111d4ccc
spell TraceBack with capital B
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
79 #define is_tracebackobject PyTraceBack_Check |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2811
diff
changeset
|
80 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2811
diff
changeset
|
81 typeobject Tracebacktype = { |
| 86 | 82 OB_HEAD_INIT(&Typetype) |
| 83 0, | |
| 84 "traceback", | |
| 85 sizeof(tracebackobject), | |
| 86 0, | |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
87 (destructor)tb_dealloc, /*tp_dealloc*/ |
| 86 | 88 0, /*tp_print*/ |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
89 (getattrfunc)tb_getattr, /*tp_getattr*/ |
| 86 | 90 0, /*tp_setattr*/ |
| 91 0, /*tp_compare*/ | |
| 92 0, /*tp_repr*/ | |
| 93 0, /*tp_as_number*/ | |
| 94 0, /*tp_as_sequence*/ | |
| 95 0, /*tp_as_mapping*/ | |
| 96 }; | |
| 97 | |
| 98 static tracebackobject * | |
| 99 newtracebackobject(next, frame, lasti, lineno) | |
| 100 tracebackobject *next; | |
| 101 frameobject *frame; | |
| 102 int lasti, lineno; | |
| 103 { | |
| 104 tracebackobject *tb; | |
| 105 if ((next != NULL && !is_tracebackobject(next)) || | |
| 106 frame == NULL || !is_frameobject(frame)) { | |
| 107 err_badcall(); | |
| 108 return NULL; | |
| 109 } | |
| 110 tb = NEWOBJ(tracebackobject, &Tracebacktype); | |
| 111 if (tb != NULL) { | |
| 112 XINCREF(next); | |
| 113 tb->tb_next = next; | |
| 114 XINCREF(frame); | |
| 115 tb->tb_frame = frame; | |
| 116 tb->tb_lasti = lasti; | |
| 117 tb->tb_lineno = lineno; | |
| 118 } | |
| 119 return tb; | |
| 120 } | |
| 121 | |
| 122 static tracebackobject *tb_current = NULL; | |
| 123 | |
| 124 int | |
|
597
800cf4086fb3
tb_here() can now get the lasti and lineno arguments from the frame.
Guido van Rossum <guido@python.org>
parents:
291
diff
changeset
|
125 tb_here(frame) |
| 86 | 126 frameobject *frame; |
| 127 { | |
| 128 tracebackobject *tb; | |
|
597
800cf4086fb3
tb_here() can now get the lasti and lineno arguments from the frame.
Guido van Rossum <guido@python.org>
parents:
291
diff
changeset
|
129 tb = newtracebackobject(tb_current, frame, frame->f_lasti, frame->f_lineno); |
| 86 | 130 if (tb == NULL) |
| 131 return -1; | |
| 132 XDECREF(tb_current); | |
| 133 tb_current = tb; | |
| 134 return 0; | |
| 135 } | |
| 136 | |
| 137 object * | |
| 138 tb_fetch() | |
| 139 { | |
| 140 object *v; | |
| 141 v = (object *)tb_current; | |
| 142 tb_current = NULL; | |
| 143 return v; | |
| 144 } | |
| 145 | |
| 146 int | |
| 147 tb_store(v) | |
| 148 object *v; | |
| 149 { | |
| 150 if (v != NULL && !is_tracebackobject(v)) { | |
| 151 err_badcall(); | |
| 152 return -1; | |
| 153 } | |
| 154 XDECREF(tb_current); | |
| 155 XINCREF(v); | |
| 156 tb_current = (tracebackobject *)v; | |
| 157 return 0; | |
| 158 } | |
| 159 | |
| 160 static void | |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
161 tb_displayline(f, filename, lineno, name) |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
162 object *f; |
| 86 | 163 char *filename; |
| 164 int lineno; | |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
165 char *name; |
| 86 | 166 { |
| 167 FILE *xfp; | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
168 char linebuf[1000]; |
| 86 | 169 int i; |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
170 #ifdef MPW |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
171 /* 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
|
172 #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
|
173 #else |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
174 /* This is needed by Emacs' compile command */ |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
175 #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
|
176 #endif |
| 86 | 177 xfp = fopen(filename, "r"); |
| 178 if (xfp == NULL) { | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
179 /* Search tail of filename in sys.path before giving up */ |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
180 object *path; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
181 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
|
182 if (tail == NULL) |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
183 tail = filename; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
184 else |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
185 tail++; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
186 path = sysget("path"); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
187 if (path != NULL && is_listobject(path)) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
188 int npath = getlistsize(path); |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
189 int taillen = strlen(tail); |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
190 char namebuf[MAXPATHLEN+1]; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
191 for (i = 0; i < npath; i++) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
192 object *v = getlistitem(path, i); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
193 if (is_stringobject(v)) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
194 int len; |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
195 len = getstringsize(v); |
|
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
196 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
|
197 continue; /* Too long */ |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
198 strcpy(namebuf, getstringvalue(v)); |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
199 if (strlen(namebuf) != len) |
|
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
200 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
|
201 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
|
202 namebuf[len++] = SEP; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
203 strcpy(namebuf+len, tail); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
204 xfp = fopen(namebuf, "r"); |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
205 if (xfp != NULL) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
206 filename = namebuf; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
207 break; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
208 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
209 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
210 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
211 } |
| 86 | 212 } |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
213 sprintf(linebuf, FMT, filename, lineno, name); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
214 writestring(linebuf, f); |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
215 if (xfp == NULL) |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
216 return; |
| 86 | 217 for (i = 0; i < lineno; i++) { |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
218 if (fgets(linebuf, sizeof linebuf, xfp) == NULL) |
| 86 | 219 break; |
| 220 } | |
| 221 if (i == lineno) { | |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
222 char *p = linebuf; |
|
2811
07fc4fefb683
ignore control-l (parallelling change to tokenizer.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
223 while (*p == ' ' || *p == '\t' || *p == '\014') |
| 86 | 224 p++; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
225 writestring(" ", f); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
226 writestring(p, f); |
| 86 | 227 if (strchr(p, '\n') == NULL) |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
228 writestring("\n", f); |
| 86 | 229 } |
| 230 fclose(xfp); | |
| 231 } | |
| 232 | |
| 233 static void | |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
234 tb_printinternal(tb, f, limit) |
| 86 | 235 tracebackobject *tb; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
236 object *f; |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
237 int limit; |
| 86 | 238 { |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
239 int depth = 0; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
240 tracebackobject *tb1 = tb; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
241 while (tb1 != NULL) { |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
242 depth++; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
243 tb1 = tb1->tb_next; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
244 } |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
245 while (tb != NULL && !intrcheck()) { |
|
5046
658815230546
Get the line number from PyCode_Addr2Line instead of believing
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
246 if (depth <= limit) { |
|
658815230546
Get the line number from PyCode_Addr2Line instead of believing
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
247 tb->tb_lineno = PyCode_Addr2Line(tb->tb_frame->f_code, |
|
658815230546
Get the line number from PyCode_Addr2Line instead of believing
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
248 tb->tb_lasti); |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
249 tb_displayline(f, |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
250 getstringvalue(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
|
251 tb->tb_lineno, |
|
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
252 getstringvalue(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
|
253 } |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
254 depth--; |
| 86 | 255 tb = tb->tb_next; |
| 256 } | |
| 257 } | |
| 258 | |
| 259 int | |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
260 tb_print(v, f) |
| 86 | 261 object *v; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
262 object *f; |
| 86 | 263 { |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
264 object *limitv; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
265 int limit = 1000; |
| 86 | 266 if (v == NULL) |
| 267 return 0; | |
| 268 if (!is_tracebackobject(v)) { | |
| 269 err_badcall(); | |
| 270 return -1; | |
| 271 } | |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
272 limitv = sysget("tracebacklimit"); |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
273 if (limitv && is_intobject(limitv)) { |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
274 limit = getintvalue(limitv); |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
275 if (limit <= 0) |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
276 return 0; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
277 } |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
278 writestring("Traceback (innermost last):\n", f); |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
279 tb_printinternal((tracebackobject *)v, f, limit); |
| 86 | 280 return 0; |
| 281 } |
