annotate Python/traceback.c @ 60889:86fadaebcf66

Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute indirectly Python signal handlers anymore because mywrite() ignores exceptions (KeyboardInterrupt).
author Victor Stinner <victor.stinner@haypocalc.com>
date Fri, 23 Apr 2010 12:02:30 +0000
parents 79718ee03986
children cab14be0ada1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Traceback implementation */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
4 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 31739
diff changeset
6 #include "code.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include "frameobject.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include "structmember.h"
674
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
9 #include "osdefs.h"
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
10 #include "traceback.h"
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
11 #ifdef HAVE_FCNTL_H
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
12 #include <fcntl.h>
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
13 #endif
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
15 #define OFF(x) offsetof(PyTracebackObject, x)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
17 /* Method from Parser/tokenizer.c */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
18 extern char * PyTokenizer_FindEncoding(int);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
19
42593
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
20 static PyObject *
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
21 tb_dir(PyTracebackObject *self)
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
22 {
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
23 return Py_BuildValue("[ssss]", "tb_frame", "tb_next",
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
24 "tb_lasti", "tb_lineno");
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
25 }
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
26
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
27 static PyMethodDef tb_methods[] = {
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
28 {"__dir__", (PyCFunction)tb_dir, METH_NOARGS},
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
29 {NULL, NULL, 0, NULL},
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
30 };
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
31
42537
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
32 static PyMemberDef tb_memberlist[] = {
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
33 {"tb_next", T_OBJECT, OFF(tb_next), READONLY},
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
34 {"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
35 {"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
36 {"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 {NULL} /* Sentinel */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 static void
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
41 tb_dealloc(PyTracebackObject *tb)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 {
22650
2288c724fe2b Call PyObject_GC_UnTrack before putting an object on the list of trash.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21077
diff changeset
43 PyObject_GC_UnTrack(tb);
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11294
diff changeset
44 Py_TRASHCAN_SAFE_BEGIN(tb)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
45 Py_XDECREF(tb->tb_next);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
46 Py_XDECREF(tb->tb_frame);
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
47 PyObject_GC_Del(tb);
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11294
diff changeset
48 Py_TRASHCAN_SAFE_END(tb)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
51 static int
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
52 tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
53 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36877
diff changeset
54 Py_VISIT(tb->tb_next);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36877
diff changeset
55 Py_VISIT(tb->tb_frame);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36877
diff changeset
56 return 0;
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
57 }
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
58
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
59 static void
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
60 tb_clear(PyTracebackObject *tb)
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
61 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36877
diff changeset
62 Py_CLEAR(tb->tb_next);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36877
diff changeset
63 Py_CLEAR(tb->tb_frame);
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
64 }
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
65
20618
57b51966a4f1 Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
66 PyTypeObject PyTraceBack_Type = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 40737
diff changeset
67 PyVarObject_HEAD_INIT(&PyType_Type, 0)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 "traceback",
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
69 sizeof(PyTracebackObject),
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 0,
1831
216b755515e6 add function name to traceback info
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
71 (destructor)tb_dealloc, /*tp_dealloc*/
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 0, /*tp_print*/
42591
9b02128521e2 Get rid of traceback.c:tb_getattr in favor of marking the members as READONLY.
Collin Winter <collinw@gmail.com>
parents: 42537
diff changeset
73 0, /*tp_getattr*/
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 0, /*tp_setattr*/
51271
87fbbf22adf3 Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 49924
diff changeset
75 0, /*tp_reserved*/
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 0, /*tp_repr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 0, /*tp_as_number*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 0, /*tp_as_sequence*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 0, /*tp_as_mapping*/
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
80 0, /* tp_hash */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
81 0, /* tp_call */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
82 0, /* tp_str */
42591
9b02128521e2 Get rid of traceback.c:tb_getattr in favor of marking the members as READONLY.
Collin Winter <collinw@gmail.com>
parents: 42537
diff changeset
83 PyObject_GenericGetAttr, /* tp_getattro */
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
84 0, /* tp_setattro */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
85 0, /* tp_as_buffer */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
86 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
87 0, /* tp_doc */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
88 (traverseproc)tb_traverse, /* tp_traverse */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
89 (inquiry)tb_clear, /* tp_clear */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
90 0, /* tp_richcompare */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
91 0, /* tp_weaklistoffset */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
92 0, /* tp_iter */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
93 0, /* tp_iternext */
42593
5391b5f8cd7a Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents: 42591
diff changeset
94 tb_methods, /* tp_methods */
42591
9b02128521e2 Get rid of traceback.c:tb_getattr in favor of marking the members as READONLY.
Collin Winter <collinw@gmail.com>
parents: 42537
diff changeset
95 tb_memberlist, /* tp_members */
42537
74a3c6826683 Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
96 0, /* tp_getset */
20623
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
97 0, /* tp_base */
4fb7727e4f47 Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20618
diff changeset
98 0, /* tp_dict */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
101 static PyTracebackObject *
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
102 newtracebackobject(PyTracebackObject *next, PyFrameObject *frame)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 {
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
104 PyTracebackObject *tb;
20618
57b51966a4f1 Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
105 if ((next != NULL && !PyTraceBack_Check(next)) ||
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
106 frame == NULL || !PyFrame_Check(frame)) {
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
107 PyErr_BadInternalCall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
110 tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if (tb != NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
112 Py_XINCREF(next);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 tb->tb_next = next;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
114 Py_XINCREF(frame);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 tb->tb_frame = frame;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 23029
diff changeset
116 tb->tb_lasti = frame->f_lasti;
55372
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 51271
diff changeset
117 tb->tb_lineno = PyFrame_GetLineNumber(frame);
22650
2288c724fe2b Call PyObject_GC_UnTrack before putting an object on the list of trash.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21077
diff changeset
118 PyObject_GC_Track(tb);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 return tb;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
124 PyTraceBack_Here(PyFrameObject *frame)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 {
40737
6ebad2a6b990 Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40626
diff changeset
126 PyThreadState *tstate = PyThreadState_GET();
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
127 PyTracebackObject *oldtb = (PyTracebackObject *) tstate->curexc_traceback;
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
128 PyTracebackObject *tb = newtracebackobject(oldtb, frame);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 if (tb == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 return -1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5404
diff changeset
131 tstate->curexc_traceback = (PyObject *)tb;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5404
diff changeset
132 Py_XDECREF(oldtb);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
136 static int
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
137 _Py_FindSourceFile(const char* filename, char* namebuf, size_t namelen, int open_flags)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
138 {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
139 int i;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
140 int fd = -1;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
141 PyObject *v;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
142 Py_ssize_t _npath;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
143 int npath;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
144 size_t taillen;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
145 PyObject *syspath;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
146 const char* path;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
147 const char* tail;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
148 Py_ssize_t len;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
149
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
150 /* Search tail of filename in sys.path before giving up */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
151 tail = strrchr(filename, SEP);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
152 if (tail == NULL)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
153 tail = filename;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
154 else
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
155 tail++;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
156 taillen = strlen(tail);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
157
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
158 syspath = PySys_GetObject("path");
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
159 if (syspath == NULL || !PyList_Check(syspath))
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
160 return -1;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
161 _npath = PyList_Size(syspath);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
162 npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
163
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
164 for (i = 0; i < npath; i++) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
165 v = PyList_GetItem(syspath, i);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
166 if (v == NULL) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
167 PyErr_Clear();
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
168 break;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
169 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
170 if (!PyUnicode_Check(v))
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
171 continue;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
172 path = _PyUnicode_AsStringAndSize(v, &len);
49924
d172dd8d9e09 Bug #4495: Fix signed/unsigned warning (both namelen and tailen should be signed, not just namelen).
Raymond Hettinger <python@rcn.com>
parents: 49484
diff changeset
173 if (len + 1 + (Py_ssize_t)taillen >= (Py_ssize_t)namelen - 1)
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
174 continue; /* Too long */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
175 strcpy(namebuf, path);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
176 if (strlen(namebuf) != len)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
177 continue; /* v contains '\0' */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
178 if (len > 0 && namebuf[len-1] != SEP)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
179 namebuf[len++] = SEP;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
180 strcpy(namebuf+len, tail);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
181 Py_BEGIN_ALLOW_THREADS
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
182 fd = open(namebuf, open_flags);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
183 Py_END_ALLOW_THREADS
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
184 if (0 <= fd) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
185 return fd;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
186 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
187 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
188 return -1;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
189 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
190
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
191 int
48499
de0bf60f1245 Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48474
diff changeset
192 _Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
194 int err = 0;
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
195 int fd;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 int i;
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
197 char *found_encoding;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
198 char *encoding;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
199 PyObject *fob = NULL;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
200 PyObject *lineobj = NULL;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
201 #ifdef O_BINARY
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
202 const int open_flags = O_RDONLY | O_BINARY; /* necessary for Windows */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
203 #else
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
204 const int open_flags = O_RDONLY;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
205 #endif
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
206 char buf[MAXPATHLEN+1];
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
207 Py_UNICODE *u, *p;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
208 Py_ssize_t len;
44742
14d4104976fc Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44157
diff changeset
209
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
210 /* open the file */
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
211 if (filename == NULL)
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
212 return 0;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
213 Py_BEGIN_ALLOW_THREADS
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
214 fd = open(filename, open_flags);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
215 Py_END_ALLOW_THREADS
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
216 if (fd < 0) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
217 fd = _Py_FindSourceFile(filename, buf, sizeof(buf), open_flags);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
218 if (fd < 0)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
219 return 0;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
220 filename = buf;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
221 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
222
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
223 /* use the right encoding to decode the file as unicode */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
224 found_encoding = PyTokenizer_FindEncoding(fd);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
225 encoding = (found_encoding != NULL) ? found_encoding :
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
226 (char*)PyUnicode_GetDefaultEncoding();
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
227 lseek(fd, 0, 0); /* Reset position */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
228 fob = PyFile_FromFd(fd, (char*)filename, "r", -1, (char*)encoding,
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
229 NULL, NULL, 1);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
230 PyMem_FREE(found_encoding);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
231 if (fob == NULL) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
232 PyErr_Clear();
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
233 close(fd);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
234 return 0;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
235 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
236
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
237 /* get the line number lineno */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
238 for (i = 0; i < lineno; i++) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
239 Py_XDECREF(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
240 lineobj = PyFile_GetLine(fob, -1);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
241 if (!lineobj) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
242 err = -1;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
243 break;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
244 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
245 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
246 Py_DECREF(fob);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
247 if (!lineobj || !PyUnicode_Check(lineobj)) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
248 Py_XDECREF(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
249 return err;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
250 }
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
251
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
252 /* remove the indentation of the line */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
253 u = PyUnicode_AS_UNICODE(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
254 len = PyUnicode_GET_SIZE(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
255 for (p=u; *p == ' ' || *p == '\t' || *p == '\014'; p++)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
256 len--;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
257 if (u != p) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
258 PyObject *truncated;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
259 truncated = PyUnicode_FromUnicode(p, len);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
260 if (truncated) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
261 Py_DECREF(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
262 lineobj = truncated;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
263 } else {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
264 PyErr_Clear();
674
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
265 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 }
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
267
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
268 /* Write some spaces before the line */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
269 strcpy(buf, " ");
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
270 assert (strlen(buf) == 10);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
271 while (indent > 0) {
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
272 if(indent < 10)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
273 buf[indent] = '\0';
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
274 err = PyFile_WriteString(buf, f);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
275 if (err != 0)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
276 break;
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
277 indent -= 10;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 }
48474
2ee09afee126 implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents: 47301
diff changeset
279
49484
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
280 /* finally display the line */
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
281 if (err == 0)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
282 err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
283 Py_DECREF(lineobj);
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
284 if (err == 0)
0b7e023803fb Issues #2384 and #3975: Tracebacks were not correctly printed when the source file
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48660
diff changeset
285 err = PyFile_WriteString("\n", f);
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
286 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
288
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
289 static int
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
290 tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
292 int err = 0;
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
293 char linebuf[2000];
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
294
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
295 if (filename == NULL || name == NULL)
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
296 return -1;
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
297 /* This is needed by Emacs' compile command */
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
298 #define FMT " File \"%.500s\", line %d, in %.500s\n"
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
299 PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
300 err = PyFile_WriteString(linebuf, f);
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
301 if (err != 0)
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
302 return err;
48499
de0bf60f1245 Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48474
diff changeset
303 return _Py_DisplaySourceLine(f, filename, lineno, 4);
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
304 }
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
305
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
306 static int
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
307 tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
308 {
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
309 int err = 0;
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
310 long depth = 0;
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
311 PyTracebackObject *tb1 = tb;
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
312 while (tb1 != NULL) {
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
313 depth++;
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
314 tb1 = tb1->tb_next;
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
315 }
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
316 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
317 if (depth <= limit) {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
318 err = tb_displayline(f,
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 48499
diff changeset
319 _PyUnicode_AsString(
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
320 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
321 tb->tb_lineno,
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 48499
diff changeset
322 _PyUnicode_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
323 }
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
324 depth--;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 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
326 if (err == 0)
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
327 err = PyErr_CheckSignals();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 }
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
329 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
331
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
332 #define PyTraceBack_LIMIT 1000
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
333
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
335 PyTraceBack_Print(PyObject *v, PyObject *f)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
337 int err;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
338 PyObject *limitv;
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44742
diff changeset
339 long limit = PyTraceBack_LIMIT;
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
340
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 if (v == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 return 0;
20618
57b51966a4f1 Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
343 if (!PyTraceBack_Check(v)) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
344 PyErr_BadInternalCall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
347 limitv = PySys_GetObject("tracebacklimit");
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
348 if (limitv) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
349 PyObject *exc_type, *exc_value, *exc_tb;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
350
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
351 PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43569
diff changeset
352 limit = PyLong_AsLong(limitv);
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
353 if (limit == -1 && PyErr_Occurred()) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
354 if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
355 limit = PyTraceBack_LIMIT;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
356 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
357 else {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
358 Py_XDECREF(exc_type);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
359 Py_XDECREF(exc_value);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
360 Py_XDECREF(exc_tb);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
361 return 0;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
362 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
363 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
364 else if (limit <= 0) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
365 limit = PyTraceBack_LIMIT;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
366 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
367 PyErr_Restore(exc_type, exc_value, exc_tb);
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
368 }
12137
5b5581af951c Change traceback error message to "most recent call last" from
Guido van Rossum <guido@python.org>
parents: 11999
diff changeset
369 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
370 if (!err)
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
371 err = tb_printinternal((PyTracebackObject *)v, f, limit);
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
372 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 }