Mercurial > cpython-lru_cache-weakref
annotate Python/traceback.c @ 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
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines
#2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade.
This is a new feature, but Barry authorized adding it in the beta period.
........
r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines
Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified
by various other language standards, including C99, IEEE 754r,
and the IBM Decimal standard.
........
r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines
- Issue #2862: Make int and float freelist management consistent with other
freelists. Changes their CompactFreeList apis into ClearFreeList apis and
calls them via gc.collect().
........
r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3301: Bisect functions behaved badly when lo was negative.
........
r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments.
........
r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line
Wording changes
........
r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line
Add cautionary note on the use of PySequence_Fast_ITEMS.
........
r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines
#3317 in zipfile module, restore the previous names of global variables:
some applications relied on them.
Also remove duplicated lines.
........
r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
........
r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines
Fix for the AttributeError in test_asynchat.
........
r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines
Fixed test for asyncore.
........
r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines
- Fix bashisms in Tools/faqwiz/move-faqwiz.sh
........
r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line
fix various doc typos #3320
........
r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines
Fixed typo.
........
r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line
#1778443 robotparser fixes from Aristotelis Mikropoulos
........
r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line
Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute)
........
r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines
Add turtle into the module index.
........
r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines
Issue #3274: Use a less common identifier for the temporary variable
in Py_CLEAR().
........
r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line
Re-word
........
r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line
Add various items; move ctypes items into a subsection of their own
........
r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fixes
........
r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line
Expand the multiprocessing section
........
r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines
Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child
process rather than both parent and child.
Does anyone actually use fork1()? It appears to be a Solaris thing
but if Python is built with pthreads on Solaris, fork1() and fork()
should be the same.
........
r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line
multiprocessing/connection.py patch to remove fqdn oddness for issue 3270
........
r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line
Add missing NEWS entry for r64962
........
r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line
Revert 3270 patch: self._address is in pretty widespread use, need to revisit
........
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Wed, 16 Jul 2008 12:55:28 +0000 |
| parents | 2ee09afee126 |
| children | 85b67fb5672b |
| rev | line source |
|---|---|
| 145 | 1 |
| 86 | 2 /* Traceback implementation */ |
| 3 | |
| 5372 | 4 #include "Python.h" |
| 86 | 5 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
31739
diff
changeset
|
6 #include "code.h" |
| 86 | 7 #include "frameobject.h" |
| 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" |
| 86 | 11 |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
12 #define OFF(x) offsetof(PyTracebackObject, x) |
| 86 | 13 |
|
42593
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
14 static PyObject * |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
15 tb_dir(PyTracebackObject *self) |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
16 { |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
17 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
|
18 "tb_lasti", "tb_lineno"); |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
19 } |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
20 |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
21 static PyMethodDef tb_methods[] = { |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
22 {"__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
|
23 {NULL, NULL, 0, NULL}, |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
24 }; |
|
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
25 |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
26 static PyMemberDef tb_memberlist[] = { |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
27 {"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
|
28 {"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
|
29 {"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
|
30 {"tb_lineno", T_INT, OFF(tb_lineno), READONLY}, |
| 86 | 31 {NULL} /* Sentinel */ |
| 32 }; | |
| 33 | |
| 34 static void | |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
35 tb_dealloc(PyTracebackObject *tb) |
| 86 | 36 { |
|
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
|
37 PyObject_GC_UnTrack(tb); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11294
diff
changeset
|
38 Py_TRASHCAN_SAFE_BEGIN(tb) |
| 5372 | 39 Py_XDECREF(tb->tb_next); |
| 40 Py_XDECREF(tb->tb_frame); | |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
41 PyObject_GC_Del(tb); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11294
diff
changeset
|
42 Py_TRASHCAN_SAFE_END(tb) |
| 86 | 43 } |
| 44 | |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
45 static int |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
46 tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg) |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
47 { |
|
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
|
48 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
|
49 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
|
50 return 0; |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
51 } |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
52 |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
53 static void |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
54 tb_clear(PyTracebackObject *tb) |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
55 { |
|
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
|
56 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
|
57 Py_CLEAR(tb->tb_frame); |
|
20623
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 |
|
20618
57b51966a4f1
Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
60 PyTypeObject PyTraceBack_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
40737
diff
changeset
|
61 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 86 | 62 "traceback", |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
63 sizeof(PyTracebackObject), |
| 86 | 64 0, |
|
1831
216b755515e6
add function name to traceback info
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
65 (destructor)tb_dealloc, /*tp_dealloc*/ |
| 86 | 66 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
|
67 0, /*tp_getattr*/ |
| 86 | 68 0, /*tp_setattr*/ |
| 69 0, /*tp_compare*/ | |
| 70 0, /*tp_repr*/ | |
| 71 0, /*tp_as_number*/ | |
| 72 0, /*tp_as_sequence*/ | |
| 73 0, /*tp_as_mapping*/ | |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
74 0, /* tp_hash */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
75 0, /* tp_call */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
76 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
|
77 PyObject_GenericGetAttr, /* tp_getattro */ |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
78 0, /* tp_setattro */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
79 0, /* tp_as_buffer */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
80 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
81 0, /* tp_doc */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
82 (traverseproc)tb_traverse, /* tp_traverse */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
83 (inquiry)tb_clear, /* tp_clear */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
84 0, /* tp_richcompare */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
85 0, /* tp_weaklistoffset */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
86 0, /* tp_iter */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
87 0, /* tp_iternext */ |
|
42593
5391b5f8cd7a
Bug #1772489: make dir() work on traceback objects again.
Collin Winter <collinw@gmail.com>
parents:
42591
diff
changeset
|
88 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
|
89 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
|
90 0, /* tp_getset */ |
|
20623
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
91 0, /* tp_base */ |
|
4fb7727e4f47
Make traceback objects collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20618
diff
changeset
|
92 0, /* tp_dict */ |
| 86 | 93 }; |
| 94 | |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
95 static PyTracebackObject * |
|
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
96 newtracebackobject(PyTracebackObject *next, PyFrameObject *frame) |
| 86 | 97 { |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
98 PyTracebackObject *tb; |
|
20618
57b51966a4f1
Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
99 if ((next != NULL && !PyTraceBack_Check(next)) || |
| 5372 | 100 frame == NULL || !PyFrame_Check(frame)) { |
| 101 PyErr_BadInternalCall(); | |
| 86 | 102 return NULL; |
| 103 } | |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
104 tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type); |
| 86 | 105 if (tb != NULL) { |
| 5372 | 106 Py_XINCREF(next); |
| 86 | 107 tb->tb_next = next; |
| 5372 | 108 Py_XINCREF(frame); |
| 86 | 109 tb->tb_frame = frame; |
| 24844 | 110 tb->tb_lasti = frame->f_lasti; |
| 111 tb->tb_lineno = PyCode_Addr2Line(frame->f_code, | |
| 112 frame->f_lasti); | |
|
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
|
113 PyObject_GC_Track(tb); |
| 86 | 114 } |
| 115 return tb; | |
| 116 } | |
| 117 | |
| 118 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
119 PyTraceBack_Here(PyFrameObject *frame) |
| 86 | 120 { |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40626
diff
changeset
|
121 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
|
122 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
|
123 PyTracebackObject *tb = newtracebackobject(oldtb, frame); |
| 86 | 124 if (tb == NULL) |
| 125 return -1; | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
126 tstate->curexc_traceback = (PyObject *)tb; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5404
diff
changeset
|
127 Py_XDECREF(oldtb); |
| 86 | 128 return 0; |
| 129 } | |
| 130 | |
|
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
|
131 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
|
132 _Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent) |
| 86 | 133 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
134 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
|
135 FILE *xfp = NULL; |
|
21057
2c0a9a5086e1
SF bug 485175: buffer overflow in traceback.c.
Tim Peters <tim.peters@gmail.com>
parents:
20623
diff
changeset
|
136 char linebuf[2000]; |
| 86 | 137 int i; |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44157
diff
changeset
|
138 char namebuf[MAXPATHLEN+1]; |
|
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44157
diff
changeset
|
139 |
|
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
|
140 if (filename == NULL) |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
141 return -1; |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22650
diff
changeset
|
142 xfp = fopen(filename, "r" PY_STDIOTEXTMODE); |
| 86 | 143 if (xfp == NULL) { |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
144 /* Search tail of filename in sys.path before giving up */ |
| 5372 | 145 PyObject *path; |
|
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
|
146 const char *tail = strrchr(filename, SEP); |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
147 if (tail == NULL) |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
148 tail = filename; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
149 else |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
150 tail++; |
| 5372 | 151 path = PySys_GetObject("path"); |
| 152 if (path != NULL && PyList_Check(path)) { | |
|
36521
30aef3ce2b26
Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
153 Py_ssize_t _npath = PyList_Size(path); |
|
30aef3ce2b26
Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
154 int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int); |
|
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
|
155 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
|
156 for (i = 0; i < npath; i++) { |
| 5372 | 157 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
|
158 if (v == NULL) { |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
159 PyErr_Clear(); |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
160 break; |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
161 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46664
diff
changeset
|
162 if (PyBytes_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
|
163 size_t len; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46664
diff
changeset
|
164 len = PyBytes_GET_SIZE(v); |
|
1909
0c232194a64f
* Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents:
1831
diff
changeset
|
165 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
|
166 continue; /* Too long */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46664
diff
changeset
|
167 strcpy(namebuf, PyBytes_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
|
168 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
|
169 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
|
170 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
|
171 namebuf[len++] = SEP; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
172 strcpy(namebuf+len, tail); |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22650
diff
changeset
|
173 xfp = fopen(namebuf, "r" PY_STDIOTEXTMODE); |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
174 if (xfp != NULL) { |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
175 filename = namebuf; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
176 break; |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
177 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
178 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
179 } |
|
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
180 } |
| 86 | 181 } |
|
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
|
182 |
|
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
|
183 if (xfp == 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
|
184 return err; |
|
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
|
185 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
|
186 fclose(xfp); |
|
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
|
187 return err; |
|
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
|
188 } |
|
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
|
189 |
| 86 | 190 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
|
191 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
|
192 do { |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
193 *pLastChar = '\0'; |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22650
diff
changeset
|
194 if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, xfp, NULL) == NULL) |
|
11294
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
195 break; |
|
d3696bf08eee
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
196 /* 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 } while (*pLastChar != '\0' && *pLastChar != '\n'); |
| 86 | 202 } |
| 203 if (i == lineno) { | |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
204 char buf[11]; |
|
674
4e2d239dc64c
Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents:
597
diff
changeset
|
205 char *p = linebuf; |
|
2811
07fc4fefb683
ignore control-l (parallelling change to tokenizer.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
206 while (*p == ' ' || *p == '\t' || *p == '\014') |
| 86 | 207 p++; |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
208 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
209 /* Write some spaces before the line */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
210 strcpy(buf, " "); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
211 assert (strlen(buf) == 10); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
212 while (indent > 0) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
213 if(indent < 10) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
214 buf[indent] = '\0'; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
215 err = PyFile_WriteString(buf, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
216 if (err != 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
217 break; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
218 indent -= 10; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
219 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
220 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
221 if (err == 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
222 err = PyFile_WriteString(p, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
223 if (err == 0 && strchr(p, '\n') == NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
224 err = PyFile_WriteString("\n", f); |
| 86 | 225 } |
| 226 fclose(xfp); | |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
227 return err; |
| 86 | 228 } |
| 229 | |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
230 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
|
231 tb_displayline(PyObject *f, const char *filename, int lineno, const char *name) |
| 86 | 232 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
233 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
|
234 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
|
235 |
|
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
|
236 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
|
237 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
|
238 /* 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
|
239 #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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 } |
|
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
|
246 |
|
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
|
247 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
|
248 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
|
249 { |
|
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
|
250 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
|
251 long depth = 0; |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
252 PyTracebackObject *tb1 = tb; |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
253 while (tb1 != NULL) { |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
254 depth++; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
255 tb1 = tb1->tb_next; |
|
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
256 } |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
257 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
|
258 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
|
259 err = tb_displayline(f, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42593
diff
changeset
|
260 PyUnicode_AsString( |
| 5372 | 261 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
|
262 tb->tb_lineno, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42593
diff
changeset
|
263 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
|
264 } |
|
1425
72bddfad351a
* mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
265 depth--; |
| 86 | 266 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
|
267 if (err == 0) |
|
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
268 err = PyErr_CheckSignals(); |
| 86 | 269 } |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
270 return err; |
| 86 | 271 } |
| 272 | |
|
44157
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
273 #define PyTraceBack_LIMIT 1000 |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
274 |
| 86 | 275 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
276 PyTraceBack_Print(PyObject *v, PyObject *f) |
| 86 | 277 { |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
278 int err; |
| 5372 | 279 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
|
280 long limit = PyTraceBack_LIMIT; |
|
44157
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
281 |
| 86 | 282 if (v == NULL) |
| 283 return 0; | |
|
20618
57b51966a4f1
Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
284 if (!PyTraceBack_Check(v)) { |
| 5372 | 285 PyErr_BadInternalCall(); |
| 86 | 286 return -1; |
| 287 } | |
| 5372 | 288 limitv = PySys_GetObject("tracebacklimit"); |
|
44157
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
289 if (limitv) { |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
290 PyObject *exc_type, *exc_value, *exc_tb; |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
291 |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
292 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
|
293 limit = PyLong_AsLong(limitv); |
|
44157
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
294 if (limit == -1 && PyErr_Occurred()) { |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
295 if (PyErr_ExceptionMatches(PyExc_OverflowError)) { |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
296 limit = PyTraceBack_LIMIT; |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
297 } |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
298 else { |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
299 Py_XDECREF(exc_type); |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
300 Py_XDECREF(exc_value); |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
301 Py_XDECREF(exc_tb); |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
302 return 0; |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
303 } |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
304 } |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
305 else if (limit <= 0) { |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
306 limit = PyTraceBack_LIMIT; |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
307 } |
|
565012d1123d
Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
308 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
|
309 } |
|
12137
5b5581af951c
Change traceback error message to "most recent call last" from
Guido van Rossum <guido@python.org>
parents:
11999
diff
changeset
|
310 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
|
311 if (!err) |
|
31739
49ec0d8f08ec
Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents:
30968
diff
changeset
|
312 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
|
313 return err; |
| 86 | 314 } |
