annotate Python/exceptions.c @ 25085:5fe4d93df429 legacy-trunk

Because MWH changed the bytecode again, moved the magic number *back* to 62011. This should get the snake-farm to throw away its old .pyc files, amongst others.
author Guido van Rossum <guido@python.org>
date Sat, 31 Aug 2002 15:16:14 +0000
parents 31d2860089e6
children 0337dad8403e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1 /* This module provides the suite of standard class-based exceptions for
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
2 * Python's builtin module. This is a complete C implementation of what,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
3 * in Python 1.5.2, was contained in the exceptions.py module. The problem
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
4 * there was that if exceptions.py could not be imported for some reason,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
5 * the entire interpreter would abort.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
6 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
7 * By moving the exceptions into C and statically linking, we can guarantee
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
8 * that the standard exceptions will always be available.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
9 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
10 * history:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
11 * 98-08-19 fl created (for pyexe)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
12 * 00-02-08 fl updated for 1.5.2
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
13 * 26-May-2000 baw vetted for Python 1.6
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
14 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
15 * written by Fredrik Lundh
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
16 * modifications, additions, cleanups, and proofreading by Barry Warsaw
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
17 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
18 * Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
19 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
20
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
21 #include "Python.h"
13996
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
22 #include "osdefs.h"
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
23
13565
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
24 /* Caution: MS Visual C++ 6 errors if a single string literal exceeds
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
25 * 2Kb. So the module docstring has been broken roughly in half, using
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
26 * compile-time literal concatenation.
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
27 */
22629
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
28
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
29 /* NOTE: If the exception class hierarchy changes, don't forget to update
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
30 * Doc/lib/libexcs.tex!
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
31 */
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
32
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
33 PyDoc_STRVAR(module__doc__,
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
34 "Python's standard exception class hierarchy.\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
35 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
36 Before Python 1.5, the standard exceptions were all simple string objects.\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
37 In Python 1.5, the standard exceptions were converted to classes organized\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
38 into a relatively flat hierarchy. String-based standard exceptions were\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
39 optional, or used as a fallback if some problem occurred while importing\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
40 the exception module. With Python 1.6, optional string-based standard\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
41 exceptions were removed (along with the -X command line flag).\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
42 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
43 The class exceptions were implemented in such a way as to be almost\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
44 completely backward compatible. Some tricky uses of IOError could\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
45 potentially have broken, but by Python 1.6, all of these should have\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
46 been fixed. As of Python 1.6, the class-based standard exceptions are\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
47 now implemented in C, and are guaranteed to exist in the Python\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
48 interpreter.\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
49 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
50 Here is a rundown of the class hierarchy. The classes found here are\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
51 inserted into both the exceptions module and the `built-in' module. It is\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
52 recommended that user defined class based exceptions be derived from the\n\
13565
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
53 `Exception' class, although this is currently not enforced.\n"
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
54 /* keep string pieces "small" */
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
55 "\n\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
56 Exception\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
57 |\n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
58 +-- SystemExit\n\
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
59 +-- StopIteration\n\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
60 +-- StandardError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
61 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
62 | +-- KeyboardInterrupt\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
63 | +-- ImportError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
64 | +-- EnvironmentError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
65 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
66 | | +-- IOError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
67 | | +-- OSError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
68 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
69 | | +-- WindowsError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
70 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
71 | +-- EOFError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
72 | +-- RuntimeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
73 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
74 | | +-- NotImplementedError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
75 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
76 | +-- NameError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
77 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
78 | | +-- UnboundLocalError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
79 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
80 | +-- AttributeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
81 | +-- SyntaxError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
82 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
83 | | +-- IndentationError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
84 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
85 | | +-- TabError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
86 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
87 | +-- TypeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
88 | +-- AssertionError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
89 | +-- LookupError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
90 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
91 | | +-- IndexError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
92 | | +-- KeyError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
93 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
94 | +-- ArithmeticError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
95 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
96 | | +-- OverflowError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
97 | | +-- ZeroDivisionError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
98 | | +-- FloatingPointError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
99 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
100 | +-- ValueError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
101 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
102 | | +-- UnicodeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
103 | |\n\
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
104 | +-- ReferenceError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
105 | +-- SystemError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
106 | +-- MemoryError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
107 |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
108 +---Warning\n\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
109 |\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
110 +-- UserWarning\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
111 +-- DeprecationWarning\n\
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
112 +-- PendingDeprecationWarning\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
113 +-- SyntaxWarning\n\
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
114 +-- OverflowWarning\n\
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
115 +-- RuntimeWarning\n\
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
116 +-- FutureWarning"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
117 );
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
118
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
119
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
120 /* Helper function for populating a dictionary with method wrappers. */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
121 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
122 populate_methods(PyObject *klass, PyObject *dict, PyMethodDef *methods)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
123 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
124 if (!methods)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
125 return 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
126
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
127 while (methods->ml_name) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
128 /* get a wrapper for the built-in function */
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
129 PyObject *func = PyCFunction_New(methods, NULL);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
130 PyObject *meth;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
131 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
132
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
133 if (!func)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
134 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
135
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
136 /* turn the function into an unbound method */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
137 if (!(meth = PyMethod_New(func, NULL, klass))) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
138 Py_DECREF(func);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
139 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
140 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
141
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
142 /* add method to dictionary */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
143 status = PyDict_SetItemString(dict, methods->ml_name, meth);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
144 Py_DECREF(meth);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
145 Py_DECREF(func);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
146
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
147 /* stop now if an error occurred, otherwise do the next method */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
148 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
149 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
150
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
151 methods++;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
152 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
153 return 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
154 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
155
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
156
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
157
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
158 /* This function is used to create all subsequent exception classes. */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
159 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
160 make_class(PyObject **klass, PyObject *base,
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
161 char *name, PyMethodDef *methods,
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
162 char *docstr)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
163 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
164 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
165 PyObject *str = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
166 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
167
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
168 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
169 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
170
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
171 /* If an error occurs from here on, goto finally instead of explicitly
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
172 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
173 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
174
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
175 if (docstr) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
176 if (!(str = PyString_FromString(docstr)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
177 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
178 if (PyDict_SetItemString(dict, "__doc__", str))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
179 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
180 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
181
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
182 if (!(*klass = PyErr_NewException(name, base, dict)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
183 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
184
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
185 if (populate_methods(*klass, dict, methods)) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
186 Py_DECREF(*klass);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
187 *klass = NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
188 goto finally;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
189 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
190
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
191 status = 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
192
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
193 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
194 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
195 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
196 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
197 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
198
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
199
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
200 /* Use this for *args signatures, otherwise just use PyArg_ParseTuple() */
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
201 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
202 get_self(PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
203 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
204 PyObject *self = PyTuple_GetItem(args, 0);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
205 if (!self) {
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13576
diff changeset
206 /* Watch out for being called to early in the bootstrapping process */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
207 if (PyExc_TypeError) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
208 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14068
diff changeset
209 "unbound method must be called with instance as first argument");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
210 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
211 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
212 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
213 return self;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
214 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
215
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
216
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
217
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
218 /* Notes on bootstrapping the exception classes.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
219 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
220 * First thing we create is the base class for all exceptions, called
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
221 * appropriately enough: Exception. Creation of this class makes no
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
222 * assumptions about the existence of any other exception class -- except
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
223 * for TypeError, which can conditionally exist.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
224 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
225 * Next, StandardError is created (which is quite simple) followed by
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
226 * TypeError, because the instantiation of other exceptions can potentially
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
227 * throw a TypeError. Once these exceptions are created, all the others
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
228 * can be created in any order. See the static exctable below for the
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
229 * explicit bootstrap order.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
230 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
231 * All classes after Exception can be created using PyErr_NewException().
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
232 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
233
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
234 PyDoc_STRVAR(Exception__doc__, "Common base class for all exceptions.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
235
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
236
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
237 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
238 Exception__init__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
239 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
240 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
241
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
242 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
243 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
244
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
245 /* set args attribute */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
246 /* XXX size is only a hint */
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
247 args = PySequence_GetSlice(args, 1, PySequence_Size(args));
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
248 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
249 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
250 status = PyObject_SetAttrString(self, "args", args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
251 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
252 if (status < 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
253 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
254
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
255 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
256 return Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
257 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
258
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
259
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
260 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
261 Exception__str__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
262 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
263 PyObject *out;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
264
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
265 if (!PyArg_ParseTuple(args, "O:__str__", &self))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
266 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
267
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
268 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
269 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
270 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
271
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
272 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
273 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
274 out = PyString_FromString("");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
275 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
276 case 1:
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
277 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
278 PyObject *tmp = PySequence_GetItem(args, 0);
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
279 if (tmp) {
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
280 out = PyObject_Str(tmp);
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
281 Py_DECREF(tmp);
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
282 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
283 else
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
284 out = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
285 break;
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
286 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
287 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
288 out = PyObject_Str(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
289 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
290 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
291
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
292 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
293 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
294 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
295
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
296
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
297 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
298 Exception__getitem__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
299 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
300 PyObject *out;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
301 PyObject *index;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
302
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
303 if (!PyArg_ParseTuple(args, "OO:__getitem__", &self, &index))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
304 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
305
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
306 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
307 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
308 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
309
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
310 out = PyObject_GetItem(args, index);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
311 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
312 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
313 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
314
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
315
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
316 static PyMethodDef
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
317 Exception_methods[] = {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
318 /* methods for the Exception class */
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
319 { "__getitem__", Exception__getitem__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
320 { "__str__", Exception__str__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
321 { "__init__", Exception__init__, METH_VARARGS},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
322 { NULL, NULL }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
323 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
324
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
325
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
326 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
327 make_Exception(char *modulename)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
328 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
329 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
330 PyObject *str = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
331 PyObject *name = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
332 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
333
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
334 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
335 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
336
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
337 /* If an error occurs from here on, goto finally instead of explicitly
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
338 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
339 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
340
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
341 if (!(str = PyString_FromString(modulename)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
342 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
343 if (PyDict_SetItemString(dict, "__module__", str))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
344 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
345 Py_DECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
346 if (!(str = PyString_FromString(Exception__doc__)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
347 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
348 if (PyDict_SetItemString(dict, "__doc__", str))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
349 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
350
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
351 if (!(name = PyString_FromString("Exception")))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
352 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
353
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
354 if (!(PyExc_Exception = PyClass_New(NULL, dict, name)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
355 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
356
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
357 /* Now populate the dictionary with the method suite */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
358 if (populate_methods(PyExc_Exception, dict, Exception_methods))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
359 /* Don't need to reclaim PyExc_Exception here because that'll
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
360 * happen during interpreter shutdown.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
361 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
362 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
363
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
364 status = 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
365
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
366 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
367 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
368 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
369 Py_XDECREF(name);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
370 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
371 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
372
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
373
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
374
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
375 PyDoc_STRVAR(StandardError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
376 "Base class for all standard Python exceptions.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
377
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
378 PyDoc_STRVAR(TypeError__doc__, "Inappropriate argument type.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
379
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
380 PyDoc_STRVAR(StopIteration__doc__, "Signal the end from iterator.next().");
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
381
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
382
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
383
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
384 PyDoc_STRVAR(SystemExit__doc__, "Request to exit from the interpreter.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
385
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
386
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
387 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
388 SystemExit__init__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
389 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
390 PyObject *code;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
391 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
392
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
393 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
394 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
395
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
396 /* Set args attribute. */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
397 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args))))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
398 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
399
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
400 status = PyObject_SetAttrString(self, "args", args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
401 if (status < 0) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
402 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
403 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
404 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
405
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
406 /* set code attribute */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
407 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
408 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
409 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
410 code = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
411 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
412 case 1:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
413 code = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
414 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
415 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
416 Py_INCREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
417 code = args;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
418 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
419 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
420
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
421 status = PyObject_SetAttrString(self, "code", code);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
422 Py_DECREF(code);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
423 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
424 if (status < 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
425 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
426
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
427 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
428 return Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
429 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
430
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
431
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
432 static PyMethodDef SystemExit_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
433 { "__init__", SystemExit__init__, METH_VARARGS},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
434 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
435 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
436
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
437
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
438
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
439 PyDoc_STRVAR(KeyboardInterrupt__doc__, "Program interrupted by user.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
440
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
441 PyDoc_STRVAR(ImportError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
442 "Import can't find module, or can't find name in module.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
443
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
444
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
445
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
446 PyDoc_STRVAR(EnvironmentError__doc__, "Base class for I/O related errors.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
447
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
448
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
449 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
450 EnvironmentError__init__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
451 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
452 PyObject *item0 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
453 PyObject *item1 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
454 PyObject *item2 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
455 PyObject *subslice = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
456 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
457
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
458 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
459 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
460
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
461 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args))))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
462 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
463
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
464 if (PyObject_SetAttrString(self, "args", args) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
465 PyObject_SetAttrString(self, "errno", Py_None) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
466 PyObject_SetAttrString(self, "strerror", Py_None) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
467 PyObject_SetAttrString(self, "filename", Py_None))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
468 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
469 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
470 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
471
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
472 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
473 case 3:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
474 /* Where a function has a single filename, such as open() or some
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
475 * of the os module functions, PyErr_SetFromErrnoWithFilename() is
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
476 * called, giving a third argument which is the filename. But, so
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
477 * that old code using in-place unpacking doesn't break, e.g.:
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
478 *
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
479 * except IOError, (errno, strerror):
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
480 *
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
481 * we hack args so that it only contains two items. This also
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
482 * means we need our own __str__() which prints out the filename
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
483 * when it was supplied.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
484 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
485 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
486 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
487 item2 = PySequence_GetItem(args, 2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
488 if (!item0 || !item1 || !item2)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
489 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
490
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
491 if (PyObject_SetAttrString(self, "errno", item0) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
492 PyObject_SetAttrString(self, "strerror", item1) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
493 PyObject_SetAttrString(self, "filename", item2))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
494 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
495 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
496 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
497
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
498 subslice = PySequence_GetSlice(args, 0, 2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
499 if (!subslice || PyObject_SetAttrString(self, "args", subslice))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
500 goto finally;
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
501 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
502
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
503 case 2:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
504 /* Used when PyErr_SetFromErrno() is called and no filename
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
505 * argument is given.
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
506 */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
507 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
508 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
509 if (!item0 || !item1)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
510 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
511
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
512 if (PyObject_SetAttrString(self, "errno", item0) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
513 PyObject_SetAttrString(self, "strerror", item1))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
514 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
515 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
516 }
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
517 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
518 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
519
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
520 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
521 rtnval = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
522
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
523 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
524 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
525 Py_XDECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
526 Py_XDECREF(item1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
527 Py_XDECREF(item2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
528 Py_XDECREF(subslice);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
529 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
530 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
531
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
532
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
533 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
534 EnvironmentError__str__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
535 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
536 PyObject *originalself = self;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
537 PyObject *filename;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
538 PyObject *serrno;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
539 PyObject *strerror;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
540 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
541
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
542 if (!PyArg_ParseTuple(args, "O:__str__", &self))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
543 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
544
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
545 filename = PyObject_GetAttrString(self, "filename");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
546 serrno = PyObject_GetAttrString(self, "errno");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
547 strerror = PyObject_GetAttrString(self, "strerror");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
548 if (!filename || !serrno || !strerror)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
549 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
550
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
551 if (filename != Py_None) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
552 PyObject *fmt = PyString_FromString("[Errno %s] %s: %s");
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
553 PyObject *repr = PyObject_Repr(filename);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
554 PyObject *tuple = PyTuple_New(3);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
555
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
556 if (!fmt || !repr || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
557 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
558 Py_XDECREF(repr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
559 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
560 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
561 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
562
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
563 PyTuple_SET_ITEM(tuple, 0, serrno);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
564 PyTuple_SET_ITEM(tuple, 1, strerror);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
565 PyTuple_SET_ITEM(tuple, 2, repr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
566
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
567 rtnval = PyString_Format(fmt, tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
568
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
569 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
570 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
571 /* already freed because tuple owned only reference */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
572 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
573 strerror = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
574 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
575 else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
576 PyObject *fmt = PyString_FromString("[Errno %s] %s");
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
577 PyObject *tuple = PyTuple_New(2);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
578
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
579 if (!fmt || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
580 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
581 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
582 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
583 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
584
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
585 PyTuple_SET_ITEM(tuple, 0, serrno);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
586 PyTuple_SET_ITEM(tuple, 1, strerror);
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
587
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
588 rtnval = PyString_Format(fmt, tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
589
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
590 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
591 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
592 /* already freed because tuple owned only reference */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
593 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
594 strerror = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
595 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
596 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
597 /* The original Python code said:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
598 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
599 * return StandardError.__str__(self)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
600 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
601 * but there is no StandardError__str__() function; we happen to
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
602 * know that's just a pass through to Exception__str__().
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
603 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
604 rtnval = Exception__str__(originalself, args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
605
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
606 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
607 Py_XDECREF(filename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
608 Py_XDECREF(serrno);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
609 Py_XDECREF(strerror);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
610 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
611 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
612
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
613
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
614 static
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
615 PyMethodDef EnvironmentError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
616 {"__init__", EnvironmentError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
617 {"__str__", EnvironmentError__str__, METH_VARARGS},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
618 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
619 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
620
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
621
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
622
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
623
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
624 PyDoc_STRVAR(IOError__doc__, "I/O operation failed.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
625
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
626 PyDoc_STRVAR(OSError__doc__, "OS system call failed.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
627
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
628 #ifdef MS_WINDOWS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
629 PyDoc_STRVAR(WindowsError__doc__, "MS-Windows OS system call failed.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
630 #endif /* MS_WINDOWS */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
631
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
632 PyDoc_STRVAR(EOFError__doc__, "Read beyond end of file.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
633
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
634 PyDoc_STRVAR(RuntimeError__doc__, "Unspecified run-time error.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
635
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
636 PyDoc_STRVAR(NotImplementedError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
637 "Method or function hasn't been implemented yet.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
638
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
639 PyDoc_STRVAR(NameError__doc__, "Name not found globally.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
640
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
641 PyDoc_STRVAR(UnboundLocalError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
642 "Local name referenced but not bound to a value.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
643
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
644 PyDoc_STRVAR(AttributeError__doc__, "Attribute not found.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
645
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
646
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
647
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
648 PyDoc_STRVAR(SyntaxError__doc__, "Invalid syntax.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
649
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
650
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
651 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
652 SyntaxError__classinit__(PyObject *klass)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
653 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
654 int retval = 0;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
655 PyObject *emptystring = PyString_FromString("");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
656
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
657 /* Additional class-creation time initializations */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
658 if (!emptystring ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
659 PyObject_SetAttrString(klass, "msg", emptystring) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
660 PyObject_SetAttrString(klass, "filename", Py_None) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
661 PyObject_SetAttrString(klass, "lineno", Py_None) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
662 PyObject_SetAttrString(klass, "offset", Py_None) ||
22121
d4406fbfcb4e Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents: 21072
diff changeset
663 PyObject_SetAttrString(klass, "text", Py_None) ||
d4406fbfcb4e Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents: 21072
diff changeset
664 PyObject_SetAttrString(klass, "print_file_and_line", Py_None))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
665 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
666 retval = -1;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
667 }
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
668 Py_XDECREF(emptystring);
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
669 return retval;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
670 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
671
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
672
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
673 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
674 SyntaxError__init__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
675 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
676 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
677 int lenargs;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
678
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
679 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
680 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
681
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
682 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args))))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
683 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
684
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
685 if (PyObject_SetAttrString(self, "args", args))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
686 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
687
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
688 lenargs = PySequence_Size(args);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
689 if (lenargs >= 1) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
690 PyObject *item0 = PySequence_GetItem(args, 0);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
691 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
692
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
693 if (!item0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
694 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
695 status = PyObject_SetAttrString(self, "msg", item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
696 Py_DECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
697 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
698 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
699 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
700 if (lenargs == 2) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
701 PyObject *info = PySequence_GetItem(args, 1);
16852
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
702 PyObject *filename = NULL, *lineno = NULL;
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
703 PyObject *offset = NULL, *text = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
704 int status = 1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
705
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
706 if (!info)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
707 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
708
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
709 filename = PySequence_GetItem(info, 0);
16852
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
710 if (filename != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
711 lineno = PySequence_GetItem(info, 1);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
712 if (lineno != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
713 offset = PySequence_GetItem(info, 2);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
714 if (offset != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
715 text = PySequence_GetItem(info, 3);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
716 if (text != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
717 status =
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
718 PyObject_SetAttrString(self, "filename", filename)
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
719 || PyObject_SetAttrString(self, "lineno", lineno)
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
720 || PyObject_SetAttrString(self, "offset", offset)
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
721 || PyObject_SetAttrString(self, "text", text);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
722 Py_DECREF(text);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
723 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
724 Py_DECREF(offset);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
725 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
726 Py_DECREF(lineno);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
727 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
728 Py_DECREF(filename);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
729 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
730 Py_DECREF(info);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
731
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
732 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
733 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
734 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
735 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
736 rtnval = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
737
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
738 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
739 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
740 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
741 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
742
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
743
13996
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
744 /* This is called "my_basename" instead of just "basename" to avoid name
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
745 conflicts with glibc; basename is already prototyped if _GNU_SOURCE is
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
746 defined, and Python does define that. */
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
747 static char *
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
748 my_basename(char *name)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
749 {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
750 char *cp = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
751 char *result = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
752
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
753 if (name == NULL)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
754 return "???";
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
755 while (*cp != '\0') {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
756 if (*cp == SEP)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
757 result = cp + 1;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
758 ++cp;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
759 }
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
760 return result;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
761 }
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
762
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
763
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
764 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
765 SyntaxError__str__(PyObject *self, PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
766 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
767 PyObject *msg;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
768 PyObject *str;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
769 PyObject *filename, *lineno, *result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
770
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
771 if (!PyArg_ParseTuple(args, "O:__str__", &self))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
772 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
773
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
774 if (!(msg = PyObject_GetAttrString(self, "msg")))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
775 return NULL;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
776
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
777 str = PyObject_Str(msg);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
778 Py_DECREF(msg);
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
779 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
780
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
781 /* XXX -- do all the additional formatting with filename and
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
782 lineno here */
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
783
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
784 if (PyString_Check(str)) {
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
785 int have_filename = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
786 int have_lineno = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
787 char *buffer = NULL;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
788
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
789 if ((filename = PyObject_GetAttrString(self, "filename")) != NULL)
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
790 have_filename = PyString_Check(filename);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
791 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
792 PyErr_Clear();
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
793
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
794 if ((lineno = PyObject_GetAttrString(self, "lineno")) != NULL)
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
795 have_lineno = PyInt_Check(lineno);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
796 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
797 PyErr_Clear();
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
798
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
799 if (have_filename || have_lineno) {
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
800 int bufsize = PyString_GET_SIZE(str) + 64;
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
801 if (have_filename)
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
802 bufsize += PyString_GET_SIZE(filename);
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
803
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
804 buffer = PyMem_MALLOC(bufsize);
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
805 if (buffer != NULL) {
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
806 if (have_filename && have_lineno)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
807 PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
808 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
809 my_basename(PyString_AS_STRING(filename)),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
810 PyInt_AsLong(lineno));
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
811 else if (have_filename)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
812 PyOS_snprintf(buffer, bufsize, "%s (%s)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
813 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
814 my_basename(PyString_AS_STRING(filename)));
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
815 else if (have_lineno)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
816 PyOS_snprintf(buffer, bufsize, "%s (line %ld)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
817 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
818 PyInt_AsLong(lineno));
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
819
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
820 result = PyString_FromString(buffer);
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
821 PyMem_FREE(buffer);
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
822
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
823 if (result == NULL)
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
824 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
825 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
826 Py_DECREF(str);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
827 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
828 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
829 Py_XDECREF(filename);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
830 Py_XDECREF(lineno);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
831 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
832 return result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
833 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
834
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
835
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
836 static PyMethodDef SyntaxError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
837 {"__init__", SyntaxError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
838 {"__str__", SyntaxError__str__, METH_VARARGS},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
839 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
840 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
841
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
842
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
843
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
844 /* Exception doc strings */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
845
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
846 PyDoc_STRVAR(AssertionError__doc__, "Assertion failed.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
847
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
848 PyDoc_STRVAR(LookupError__doc__, "Base class for lookup errors.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
849
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
850 PyDoc_STRVAR(IndexError__doc__, "Sequence index out of range.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
851
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
852 PyDoc_STRVAR(KeyError__doc__, "Mapping key not found.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
853
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
854 PyDoc_STRVAR(ArithmeticError__doc__, "Base class for arithmetic errors.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
855
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
856 PyDoc_STRVAR(OverflowError__doc__, "Result too large to be represented.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
857
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
858 PyDoc_STRVAR(ZeroDivisionError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
859 "Second argument to a division or modulo operation was zero.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
860
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
861 PyDoc_STRVAR(FloatingPointError__doc__, "Floating point operation failed.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
862
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
863 PyDoc_STRVAR(ValueError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
864 "Inappropriate argument value (of correct type).");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
865
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
866 PyDoc_STRVAR(UnicodeError__doc__, "Unicode related error.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
867
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
868 PyDoc_STRVAR(SystemError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
869 "Internal error in the Python interpreter.\n\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
870 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
871 Please report this to the Python maintainer, along with the traceback,\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
872 the Python version, and the hardware/OS platform and version.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
873
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
874 PyDoc_STRVAR(ReferenceError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
875 "Weak ref proxy used after referent went away.");
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
876
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
877 PyDoc_STRVAR(MemoryError__doc__, "Out of memory.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
878
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
879 PyDoc_STRVAR(IndentationError__doc__, "Improper indentation.");
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
880
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
881 PyDoc_STRVAR(TabError__doc__, "Improper mixture of spaces and tabs.");
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
882
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
883 /* Warning category docstrings */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
884
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
885 PyDoc_STRVAR(Warning__doc__, "Base class for warning categories.");
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
886
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
887 PyDoc_STRVAR(UserWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
888 "Base class for warnings generated by user code.");
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
889
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
890 PyDoc_STRVAR(DeprecationWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
891 "Base class for warnings about deprecated features.");
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
892
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
893 PyDoc_STRVAR(PendingDeprecationWarning__doc__,
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
894 "Base class for warnings about features which will be deprecated "
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
895 "in the future.");
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
896
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
897 PyDoc_STRVAR(SyntaxWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
898 "Base class for warnings about dubious syntax.");
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
899
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
900 PyDoc_STRVAR(OverflowWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
901 "Base class for warnings about numeric overflow.");
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
902
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
903 PyDoc_STRVAR(RuntimeWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
904 "Base class for warnings about dubious runtime behavior.");
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
905
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
906 PyDoc_STRVAR(FutureWarning__doc__,
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
907 "Base class for warnings about constructs that will change semantically "
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
908 "in the future.");
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
909
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
910
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
911
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
912 /* module global functions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
913 static PyMethodDef functions[] = {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
914 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
915 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
916 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
917
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
918
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
919
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
920 /* Global C API defined exceptions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
921
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
922 PyObject *PyExc_Exception;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
923 PyObject *PyExc_StopIteration;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
924 PyObject *PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
925 PyObject *PyExc_ArithmeticError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
926 PyObject *PyExc_LookupError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
927
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
928 PyObject *PyExc_AssertionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
929 PyObject *PyExc_AttributeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
930 PyObject *PyExc_EOFError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
931 PyObject *PyExc_FloatingPointError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
932 PyObject *PyExc_EnvironmentError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
933 PyObject *PyExc_IOError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
934 PyObject *PyExc_OSError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
935 PyObject *PyExc_ImportError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
936 PyObject *PyExc_IndexError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
937 PyObject *PyExc_KeyError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
938 PyObject *PyExc_KeyboardInterrupt;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
939 PyObject *PyExc_MemoryError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
940 PyObject *PyExc_NameError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
941 PyObject *PyExc_OverflowError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
942 PyObject *PyExc_RuntimeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
943 PyObject *PyExc_NotImplementedError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
944 PyObject *PyExc_SyntaxError;
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
945 PyObject *PyExc_IndentationError;
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
946 PyObject *PyExc_TabError;
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
947 PyObject *PyExc_ReferenceError;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
948 PyObject *PyExc_SystemError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
949 PyObject *PyExc_SystemExit;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
950 PyObject *PyExc_UnboundLocalError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
951 PyObject *PyExc_UnicodeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
952 PyObject *PyExc_TypeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
953 PyObject *PyExc_ValueError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
954 PyObject *PyExc_ZeroDivisionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
955 #ifdef MS_WINDOWS
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
956 PyObject *PyExc_WindowsError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
957 #endif
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
958
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
959 /* Pre-computed MemoryError instance. Best to create this as early as
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
960 * possibly and not wait until a MemoryError is actually raised!
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
961 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
962 PyObject *PyExc_MemoryErrorInst;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
963
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
964 /* Predefined warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
965 PyObject *PyExc_Warning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
966 PyObject *PyExc_UserWarning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
967 PyObject *PyExc_DeprecationWarning;
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
968 PyObject *PyExc_PendingDeprecationWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
969 PyObject *PyExc_SyntaxWarning;
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
970 PyObject *PyExc_OverflowWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
971 PyObject *PyExc_RuntimeWarning;
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
972 PyObject *PyExc_FutureWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
973
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
974
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
975
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
976 /* mapping between exception names and their PyObject ** */
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
977 static struct {
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
978 char *name;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
979 PyObject **exc;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
980 PyObject **base; /* NULL == PyExc_StandardError */
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
981 char *docstr;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
982 PyMethodDef *methods;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
983 int (*classinit)(PyObject *);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
984 } exctable[] = {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
985 /*
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
986 * The first three classes MUST appear in exactly this order
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
987 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
988 {"Exception", &PyExc_Exception},
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
989 {"StopIteration", &PyExc_StopIteration, &PyExc_Exception,
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
990 StopIteration__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
991 {"StandardError", &PyExc_StandardError, &PyExc_Exception,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
992 StandardError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
993 {"TypeError", &PyExc_TypeError, 0, TypeError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
994 /*
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
995 * The rest appear in depth-first order of the hierarchy
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
996 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
997 {"SystemExit", &PyExc_SystemExit, &PyExc_Exception, SystemExit__doc__,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
998 SystemExit_methods},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
999 {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, 0, KeyboardInterrupt__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1000 {"ImportError", &PyExc_ImportError, 0, ImportError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1001 {"EnvironmentError", &PyExc_EnvironmentError, 0, EnvironmentError__doc__,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1002 EnvironmentError_methods},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1003 {"IOError", &PyExc_IOError, &PyExc_EnvironmentError, IOError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1004 {"OSError", &PyExc_OSError, &PyExc_EnvironmentError, OSError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1005 #ifdef MS_WINDOWS
13973
4e28ca345cfe Fix the parent of WindowsError - both the comments in this source file, and the previous exceptions.py have WindowsError as a sub-class of OSError.
Mark Hammond <mhammond@skippinet.com.au>
parents: 13657
diff changeset
1006 {"WindowsError", &PyExc_WindowsError, &PyExc_OSError,
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1007 WindowsError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1008 #endif /* MS_WINDOWS */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1009 {"EOFError", &PyExc_EOFError, 0, EOFError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1010 {"RuntimeError", &PyExc_RuntimeError, 0, RuntimeError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1011 {"NotImplementedError", &PyExc_NotImplementedError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1012 &PyExc_RuntimeError, NotImplementedError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1013 {"NameError", &PyExc_NameError, 0, NameError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1014 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1015 UnboundLocalError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1016 {"AttributeError", &PyExc_AttributeError, 0, AttributeError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1017 {"SyntaxError", &PyExc_SyntaxError, 0, SyntaxError__doc__,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1018 SyntaxError_methods, SyntaxError__classinit__},
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1019 {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1020 IndentationError__doc__},
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1021 {"TabError", &PyExc_TabError, &PyExc_IndentationError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1022 TabError__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1023 {"AssertionError", &PyExc_AssertionError, 0, AssertionError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1024 {"LookupError", &PyExc_LookupError, 0, LookupError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1025 {"IndexError", &PyExc_IndexError, &PyExc_LookupError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1026 IndexError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1027 {"KeyError", &PyExc_KeyError, &PyExc_LookupError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1028 KeyError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1029 {"ArithmeticError", &PyExc_ArithmeticError, 0, ArithmeticError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1030 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1031 OverflowError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1032 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1033 ZeroDivisionError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1034 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1035 FloatingPointError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1036 {"ValueError", &PyExc_ValueError, 0, ValueError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1037 {"UnicodeError", &PyExc_UnicodeError, &PyExc_ValueError, UnicodeError__doc__},
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
1038 {"ReferenceError", &PyExc_ReferenceError, 0, ReferenceError__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1039 {"SystemError", &PyExc_SystemError, 0, SystemError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1040 {"MemoryError", &PyExc_MemoryError, 0, MemoryError__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1041 /* Warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1042 {"Warning", &PyExc_Warning, &PyExc_Exception, Warning__doc__},
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1043 {"UserWarning", &PyExc_UserWarning, &PyExc_Warning, UserWarning__doc__},
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1044 {"DeprecationWarning", &PyExc_DeprecationWarning, &PyExc_Warning,
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1045 DeprecationWarning__doc__},
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
1046 {"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning,
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
1047 PendingDeprecationWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1048 {"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__},
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1049 {"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning,
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1050 OverflowWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1051 {"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning,
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1052 RuntimeWarning__doc__},
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1053 {"FutureWarning", &PyExc_FutureWarning, &PyExc_Warning,
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1054 FutureWarning__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1055 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1056 {NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1057 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1058
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1059
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1060
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1061 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1062 _PyExc_Init(void)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1063 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1064 char *modulename = "exceptions";
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1065 int modnamesz = strlen(modulename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1066 int i;
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1067 PyObject *me, *mydict, *bltinmod, *bdict, *doc, *args;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1068
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1069 me = Py_InitModule(modulename, functions);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1070 if (me == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1071 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1072 mydict = PyModule_GetDict(me);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1073 if (mydict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1074 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1075 bltinmod = PyImport_ImportModule("__builtin__");
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1076 if (bltinmod == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1077 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1078 bdict = PyModule_GetDict(bltinmod);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1079 if (bdict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1080 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1081 doc = PyString_FromString(module__doc__);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1082 if (doc == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1083 goto err;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1084
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1085 i = PyDict_SetItemString(mydict, "__doc__", doc);
13283
3e07a7315af5 init_exceptions(): Decref `doc' so it doesn't leak.
Barry Warsaw <barry@python.org>
parents: 13182
diff changeset
1086 Py_DECREF(doc);
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1087 if (i < 0) {
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1088 err:
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1089 Py_FatalError("exceptions bootstrapping error.");
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1090 return;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1091 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1092
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1093 /* This is the base class of all exceptions, so make it first. */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1094 if (make_Exception(modulename) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1095 PyDict_SetItemString(mydict, "Exception", PyExc_Exception) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1096 PyDict_SetItemString(bdict, "Exception", PyExc_Exception))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1097 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1098 Py_FatalError("Base class `Exception' could not be created.");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1099 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1100
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1101 /* Now we can programmatically create all the remaining exceptions.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1102 * Remember to start the loop at 1 to skip Exceptions.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1103 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1104 for (i=1; exctable[i].name; i++) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1105 int status;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1106 char *cname = PyMem_NEW(char, modnamesz+strlen(exctable[i].name)+2);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1107 PyObject *base;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1108
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1109 (void)strcpy(cname, modulename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1110 (void)strcat(cname, ".");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1111 (void)strcat(cname, exctable[i].name);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1112
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1113 if (exctable[i].base == 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1114 base = PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1115 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1116 base = *exctable[i].base;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1117
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1118 status = make_class(exctable[i].exc, base, cname,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1119 exctable[i].methods,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1120 exctable[i].docstr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1121
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1122 PyMem_DEL(cname);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1123
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1124 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1125 Py_FatalError("Standard exception classes could not be created.");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1126
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1127 if (exctable[i].classinit) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1128 status = (*exctable[i].classinit)(*exctable[i].exc);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1129 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1130 Py_FatalError("An exception class could not be initialized.");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1131 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1132
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1133 /* Now insert the class into both this module and the __builtin__
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1134 * module.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1135 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1136 if (PyDict_SetItemString(mydict, exctable[i].name, *exctable[i].exc) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1137 PyDict_SetItemString(bdict, exctable[i].name, *exctable[i].exc))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1138 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1139 Py_FatalError("Module dictionary insertion problem.");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1140 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1141 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1142
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1143 /* Now we need to pre-allocate a MemoryError instance */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1144 args = Py_BuildValue("()");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1145 if (!args ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1146 !(PyExc_MemoryErrorInst = PyEval_CallObject(PyExc_MemoryError, args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1147 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1148 Py_FatalError("Cannot pre-allocate MemoryError instance\n");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1149 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1150 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1151
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1152 /* We're done with __builtin__ */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1153 Py_DECREF(bltinmod);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1154 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1155
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1156
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1157 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1158 _PyExc_Fini(void)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1159 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1160 int i;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1161
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1162 Py_XDECREF(PyExc_MemoryErrorInst);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1163 PyExc_MemoryErrorInst = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1164
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1165 for (i=0; exctable[i].name; i++) {
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1166 /* clear the class's dictionary, freeing up circular references
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1167 * between the class and its methods.
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1168 */
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1169 PyObject* cdict = PyObject_GetAttrString(*exctable[i].exc, "__dict__");
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1170 PyDict_Clear(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1171 Py_DECREF(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1172
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1173 /* Now decref the exception class */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1174 Py_XDECREF(*exctable[i].exc);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1175 *exctable[i].exc = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1176 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1177 }