annotate Python/traceback.c @ 45852:30c4e1ca8421

Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line Clarified documentation on use of shutdown(). ........ r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines Added a footnote to each pointing out that for XML output if an encoding string is given it should conform to the appropriate XML standards---for example, "UTF-8" is okay, but "UTF8" is not. ........ r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines Issue 2264: empty float presentation type needs to have at least one digit past the decimal point. Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type. Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning. Modified format.__float__ to use the new "Z" format as the default. Added test cases. ........ r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines Reformated lines > 79 chars. Deleted unused macro ISXDIGIT. ........ r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines Allow Gnu gcc's to build python on OSX by removing -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd from configure. * r22183 added -no-cpp-precomp, which http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been needed since gcc-3.1. * r25607 added -Wno-long-double to avoid a warning in Include/objimpl.h (issue 525481). The long double is still there, but OSX 10.4's gcc no longer warns about it. * r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd, which changed the sign of some float 0s. Tim Peters said it wasn't a real issue anyway, and it no longer causes test failures. Fixes issue #1779871. ........ r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines Add Trent Nelson. ........ r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line Add necessary headers to back-port new buffer protocol to Python 2.6 ........ r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms regardless of the native sizeof(long) used in the integer object. This somewhat odd behavior of returning a signed is maintained in 2.x for compatibility reasons of always returning an integer rather than a long object. Fixes Issue1202 for Python 2.6 ........ r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines Use a buffer large enough to ensure we don't overrun, even if the value is outside the range we expect. ........ r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line Document unicode.isnumeric() and unicode.isdecimal() (issue2326) ........ r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines Issue 2321: reduce memory usage (increase the memory that is returned to the system) by using pymalloc for the data of unicode objects. Will backport. ........ r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines Add David Wolever. ........ r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines Fix the IOError message text when opening a file with an invalid filename. Error reported by Ilan Schnell. ........ r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines Convert test_strftime, test_getargs, and test_pep247 to use unittest. ........ r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster. ........ r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines Convert test_dummy_threading and test_dbm to unittest. ........ r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines Move test_extcall to doctest. ........ r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines test_errno was a no-op test; now it actually tests things and uses unittest. ........ r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines Remove our implementation of memmove() and strerror(); both are in the C89 standard library. ........ r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines The output directory for tests that compare against stdout is now gone! ........ r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines Block the "socket.ssl() is deprecated" warning from test_socket_ssl. ........ r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We still sleep at all to make it likely that all threads are active at the same time. ........ r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines Speed up test_dict by about 10x by only checking selected dict literal sizes, instead of every integer from 0 to 400. Exhaustive testing wastes time without providing enough more assurance that the code is correct. ........ r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line Try increasing the timeout to reduce the flakiness of this test. ........ r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines Improve the error message for a test that failed on the S-390 Debian buildbot. ........ r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with their times. ........ r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line Add some info to the failure messages ........ r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH. ........ r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either: a) no sound card entirely b) legacy beep driver has been disabled c) the legacy beep driver has been uninstalled Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots. ........ r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines norwitz-amd64 (gentoo) has EREMOTEIO. ........ r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines Add more Linux error codes. ........ r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines Add WSA errors. ........ r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines Note that the stderr output of the test is intentional. ........
author Christian Heimes <christian@cheimes.de>
date Tue, 18 Mar 2008 15:15:01 +0000
parents 14d4104976fc
children 47d9bbe10897
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"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 {NULL} /* Sentinel */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
39 Py_XDECREF(tb->tb_next);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 0, /*tp_setattr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 0, /*tp_compare*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 0, /*tp_repr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 0, /*tp_as_number*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 0, /*tp_as_sequence*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
100 frame == NULL || !PyFrame_Check(frame)) {
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
101 PyErr_BadInternalCall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 return NULL;
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 tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 if (tb != NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
106 Py_XINCREF(next);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 tb->tb_next = next;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
108 Py_XINCREF(frame);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 tb->tb_frame = frame;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 23029
diff changeset
110 tb->tb_lasti = frame->f_lasti;
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 23029
diff changeset
111 tb->tb_lineno = PyCode_Addr2Line(frame->f_code,
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 23029
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 return tb;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 if (tb == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
131 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
132 tb_displayline(PyObject *f, char *filename, int lineno, char *name)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 FILE *xfp;
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
140 if (filename == NULL || name == NULL)
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
141 return -1;
1831
216b755515e6 add function name to traceback info
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
142 /* This is needed by Emacs' compile command */
21057
2c0a9a5086e1 SF bug 485175: buffer overflow in traceback.c.
Tim Peters <tim.peters@gmail.com>
parents: 20623
diff changeset
143 #define FMT " File \"%.500s\", line %d, in %.500s\n"
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22650
diff changeset
144 xfp = fopen(filename, "r" PY_STDIOTEXTMODE);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 if (xfp == NULL) {
674
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
146 /* Search tail of filename in sys.path before giving up */
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
147 PyObject *path;
674
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
148 char *tail = strrchr(filename, SEP);
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
149 if (tail == NULL)
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
150 tail = filename;
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
151 else
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
152 tail++;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
153 path = PySys_GetObject("path");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
154 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
155 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
156 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
157 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
158 for (i = 0; i < npath; i++) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
159 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
160 if (v == NULL) {
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
161 PyErr_Clear();
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
162 break;
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
163 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
164 if (PyString_Check(v)) {
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
165 size_t len;
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
166 len = PyString_GET_SIZE(v);
1909
0c232194a64f * Python/traceback.c: security fix -- check for buffer oveflow
Guido van Rossum <guido@python.org>
parents: 1831
diff changeset
167 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
168 continue; /* Too long */
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
169 strcpy(namebuf, PyString_AsString(v));
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
170 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
171 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
172 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
173 namebuf[len++] = SEP;
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
174 strcpy(namebuf+len, tail);
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22650
diff changeset
175 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
176 if (xfp != NULL) {
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
177 filename = namebuf;
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
178 break;
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 }
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
181 }
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
182 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21057
diff changeset
184 PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
185 err = PyFile_WriteString(linebuf, f);
36877
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36521
diff changeset
186 if (xfp == NULL)
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
187 return err;
36877
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36521
diff changeset
188 else if (err != 0) {
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36521
diff changeset
189 fclose(xfp);
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36521
diff changeset
190 return err;
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36521
diff changeset
191 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 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
193 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
194 do {
d3696bf08eee Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents: 5608
diff changeset
195 *pLastChar = '\0';
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22650
diff changeset
196 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
197 break;
d3696bf08eee Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Guido van Rossum <guido@python.org>
parents: 5608
diff changeset
198 /* 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
199 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
200 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
201 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
202 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
203 } while (*pLastChar != '\0' && *pLastChar != '\n');
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if (i == lineno) {
674
4e2d239dc64c Move printing of filename and lineno to tb_displayline.
Guido van Rossum <guido@python.org>
parents: 597
diff changeset
206 char *p = linebuf;
2811
07fc4fefb683 ignore control-l (parallelling change to tokenizer.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
207 while (*p == ' ' || *p == '\t' || *p == '\014')
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 p++;
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
209 err = PyFile_WriteString(" ", f);
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
210 if (err == 0) {
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
211 err = PyFile_WriteString(p, f);
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
212 if (err == 0 && strchr(p, '\n') == NULL)
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
213 err = PyFile_WriteString("\n", f);
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
214 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 fclose(xfp);
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
217 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
220 static int
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
221 tb_printinternal(PyTracebackObject *tb, PyObject *f, int limit)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
223 int err = 0;
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
224 int depth = 0;
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
225 PyTracebackObject *tb1 = tb;
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
226 while (tb1 != NULL) {
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
227 depth++;
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
228 tb1 = tb1->tb_next;
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
229 }
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
230 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
231 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
232 err = tb_displayline(f,
43569
19319e70fc3e Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents: 42593
diff changeset
233 PyUnicode_AsString(
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
234 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
235 tb->tb_lineno,
43569
19319e70fc3e Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents: 42593
diff changeset
236 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
237 }
1425
72bddfad351a * mpzmodule.c: cast some methods to the proper type.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
238 depth--;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 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
240 if (err == 0)
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
241 err = PyErr_CheckSignals();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 }
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
243 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
246 #define PyTraceBack_LIMIT 1000
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
247
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
249 PyTraceBack_Print(PyObject *v, PyObject *f)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 {
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
251 int err;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
252 PyObject *limitv;
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
253 int limit = PyTraceBack_LIMIT;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
254
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 if (v == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 return 0;
20618
57b51966a4f1 Removed two pointless and obfuscating macros.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
257 if (!PyTraceBack_Check(v)) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
258 PyErr_BadInternalCall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
261 limitv = PySys_GetObject("tracebacklimit");
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
262 if (limitv) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
263 PyObject *exc_type, *exc_value, *exc_tb;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
264
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
265 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
266 limit = PyLong_AsLong(limitv);
44157
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
267 if (limit == -1 && PyErr_Occurred()) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
268 if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
269 limit = PyTraceBack_LIMIT;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
270 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
271 else {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
272 Py_XDECREF(exc_type);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
273 Py_XDECREF(exc_value);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
274 Py_XDECREF(exc_tb);
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
275 return 0;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
276 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
277 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
278 else if (limit <= 0) {
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
279 limit = PyTraceBack_LIMIT;
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
280 }
565012d1123d Removed another occurrence of PyInt_ExactCheck()
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
281 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
282 }
12137
5b5581af951c Change traceback error message to "most recent call last" from
Guido van Rossum <guido@python.org>
parents: 11999
diff changeset
283 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
284 if (!err)
31739
49ec0d8f08ec Moved tracebackobject to traceback.h, Closes SF Bug #497067
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30968
diff changeset
285 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
286 return err;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 }