annotate Objects/exceptions.c @ 73798:6cde416ef03b

Credit Per Øyvind Karlsen for the initial implementation of the lzma module (issue #6715).
author Nadeem Vawda <nadeem.vawda@gmail.com>
date Thu, 01 Dec 2011 01:18:27 +0200
parents 2e37fc70e2dd
children d22c99e77768
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1 /*
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
2 * New exceptions.c written in Iceland by Richard Jones and Georg Brandl.
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
3 *
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
4 * Thanks go to Tim Peters and Michael Hudson for debugging.
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
5 */
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
6
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
7 #define PY_SSIZE_T_CLEAN
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
8 #include <Python.h>
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
9 #include "structmember.h"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
10 #include "osdefs.h"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
13 /* Compatibility aliases */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
14 PyObject *PyExc_EnvironmentError = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
15 PyObject *PyExc_IOError = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
16 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
17 PyObject *PyExc_WindowsError = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
18 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
19 #ifdef __VMS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
20 PyObject *PyExc_VMSError = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
21 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
22
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
23 /* The dict map from errno codes to OSError subclasses */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
24 static PyObject *errnomap = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
25
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
26
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
27 /* NOTE: If the exception class hierarchy changes, don't forget to update
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
28 * Lib/test/exception_hierarchy.txt
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
29 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
30
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
31 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
32 * BaseException
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
34 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
35 BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
36 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
37 PyBaseExceptionObject *self;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 self = (PyBaseExceptionObject *)type->tp_alloc(type, 0);
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
40 if (!self)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
41 return NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 /* the dict is created on the fly in PyObject_GenericSetAttr */
41749
b085eb66b7f6 Merged revisions 55342-55406 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
43 self->dict = NULL;
43188
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
44 self->traceback = self->cause = self->context = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
45
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
46 self->args = PyTuple_New(0);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
47 if (!self->args) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
48 Py_DECREF(self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
49 return NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
50 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
51
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
52 return (PyObject *)self;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
53 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
54
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
55 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
56 BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
57 {
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
58 if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
59 return -1;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
60
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
61 Py_DECREF(self->args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
62 self->args = args;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
63 Py_INCREF(self->args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
64
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
65 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
66 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
67
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
68 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
69 BaseException_clear(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
70 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
71 Py_CLEAR(self->dict);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
72 Py_CLEAR(self->args);
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
73 Py_CLEAR(self->traceback);
43188
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
74 Py_CLEAR(self->cause);
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
75 Py_CLEAR(self->context);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
76 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
77 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
78
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
79 static void
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
80 BaseException_dealloc(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
81 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
82 _PyObject_GC_UNTRACK(self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
83 BaseException_clear(self);
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
84 Py_TYPE(self)->tp_free((PyObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
85 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
86
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
87 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
88 BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
89 {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
90 Py_VISIT(self->dict);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
91 Py_VISIT(self->args);
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
92 Py_VISIT(self->traceback);
43188
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
93 Py_VISIT(self->cause);
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
94 Py_VISIT(self->context);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
95 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
96 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
97
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
98 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
99 BaseException_str(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
100 {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
101 switch (PyTuple_GET_SIZE(self->args)) {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
102 case 0:
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
103 return PyUnicode_FromString("");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
104 case 1:
43866
8ed0280c2ab6 Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents: 43777
diff changeset
105 return PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
106 default:
43866
8ed0280c2ab6 Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents: 43777
diff changeset
107 return PyObject_Str(self->args);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
108 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
109 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
110
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
111 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
112 BaseException_repr(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
113 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
114 char *name;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
115 char *dot;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
116
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
117 name = (char *)Py_TYPE(self)->tp_name;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
118 dot = strrchr(name, '.');
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
119 if (dot != NULL) name = dot+1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
120
41782
bee8d01ef42c Add a format specifier %R to PyUnicode_FromFormat(), which embeds
Walter Dörwald <walter@livinglogic.de>
parents: 41769
diff changeset
121 return PyUnicode_FromFormat("%s%R", name, self->args);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
122 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
123
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
124 /* Pickling support */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
125 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
126 BaseException_reduce(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
127 {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
128 if (self->args && self->dict)
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
129 return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
130 else
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
131 return PyTuple_Pack(2, Py_TYPE(self), self->args);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
132 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
133
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
134 /*
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
135 * Needed for backward compatibility, since exceptions used to store
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
136 * all their attributes in the __dict__. Code is taken from cPickle's
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
137 * load_build function.
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
138 */
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
139 static PyObject *
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
140 BaseException_setstate(PyObject *self, PyObject *state)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
141 {
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
142 PyObject *d_key, *d_value;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
143 Py_ssize_t i = 0;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
144
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
145 if (state != Py_None) {
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
146 if (!PyDict_Check(state)) {
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
147 PyErr_SetString(PyExc_TypeError, "state is not a dictionary");
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
148 return NULL;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
149 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
150 while (PyDict_Next(state, &i, &d_key, &d_value)) {
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
151 if (PyObject_SetAttr(self, d_key, d_value) < 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
152 return NULL;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
153 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
154 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
155 Py_RETURN_NONE;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
156 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
157
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
158 static PyObject *
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
159 BaseException_with_traceback(PyObject *self, PyObject *tb) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
160 if (PyException_SetTraceback(self, tb))
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
161 return NULL;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
162
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
163 Py_INCREF(self);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
164 return self;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
165 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
166
46682
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
167 PyDoc_STRVAR(with_traceback_doc,
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
168 "Exception.with_traceback(tb) --\n\
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
169 set self.__traceback__ to tb and return self.");
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
170
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
171
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
172 static PyMethodDef BaseException_methods[] = {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
173 {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS },
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
174 {"__setstate__", (PyCFunction)BaseException_setstate, METH_O },
46682
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
175 {"with_traceback", (PyCFunction)BaseException_with_traceback, METH_O,
91d5f0841700 Give with_traceback a docstring.
Georg Brandl <georg@python.org>
parents: 44351
diff changeset
176 with_traceback_doc},
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
177 {NULL, NULL, 0, NULL},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
178 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
179
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
180
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
181 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
182 BaseException_get_dict(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
183 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
184 if (self->dict == NULL) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
185 self->dict = PyDict_New();
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
186 if (!self->dict)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
187 return NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
188 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
189 Py_INCREF(self->dict);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
190 return self->dict;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
191 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
192
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
193 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
194 BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
195 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
196 if (val == NULL) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
197 PyErr_SetString(PyExc_TypeError, "__dict__ may not be deleted");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
198 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
199 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
200 if (!PyDict_Check(val)) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
201 PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
202 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
203 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
204 Py_CLEAR(self->dict);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
205 Py_INCREF(val);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
206 self->dict = val;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
207 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
208 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
209
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
210 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
211 BaseException_get_args(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
212 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
213 if (self->args == NULL) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
214 Py_INCREF(Py_None);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
215 return Py_None;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
216 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
217 Py_INCREF(self->args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
218 return self->args;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
219 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
220
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
221 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
222 BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
223 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
224 PyObject *seq;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
225 if (val == NULL) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
226 PyErr_SetString(PyExc_TypeError, "args may not be deleted");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
227 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
228 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
229 seq = PySequence_Tuple(val);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
230 if (!seq) return -1;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
231 Py_CLEAR(self->args);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
232 self->args = seq;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
233 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
234 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
235
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
236 static PyObject *
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
237 BaseException_get_tb(PyBaseExceptionObject *self)
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
238 {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
239 if (self->traceback == NULL) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
240 Py_INCREF(Py_None);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
241 return Py_None;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
242 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
243 Py_INCREF(self->traceback);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
244 return self->traceback;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
245 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
246
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
247 static int
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
248 BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb)
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
249 {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
250 if (tb == NULL) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
251 PyErr_SetString(PyExc_TypeError, "__traceback__ may not be deleted");
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
252 return -1;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
253 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
254 else if (!(tb == Py_None || PyTraceBack_Check(tb))) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
255 PyErr_SetString(PyExc_TypeError,
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
256 "__traceback__ must be a traceback or None");
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
257 return -1;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
258 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
259
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
260 Py_XINCREF(tb);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
261 Py_XDECREF(self->traceback);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
262 self->traceback = tb;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
263 return 0;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
264 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
265
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
266 static PyObject *
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
267 BaseException_get_context(PyObject *self) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
268 PyObject *res = PyException_GetContext(self);
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
269 if (res) return res; /* new reference already returned above */
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
270 Py_RETURN_NONE;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
271 }
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
272
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
273 static int
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
274 BaseException_set_context(PyObject *self, PyObject *arg) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
275 if (arg == NULL) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
276 PyErr_SetString(PyExc_TypeError, "__context__ may not be deleted");
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
277 return -1;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
278 } else if (arg == Py_None) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
279 arg = NULL;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
280 } else if (!PyExceptionInstance_Check(arg)) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
281 PyErr_SetString(PyExc_TypeError, "exception context must be None "
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
282 "or derive from BaseException");
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
283 return -1;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
284 } else {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
285 /* PyException_SetContext steals this reference */
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
286 Py_INCREF(arg);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
287 }
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
288 PyException_SetContext(self, arg);
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
289 return 0;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
290 }
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
291
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
292 static PyObject *
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
293 BaseException_get_cause(PyObject *self) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
294 PyObject *res = PyException_GetCause(self);
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
295 if (res) return res; /* new reference already returned above */
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
296 Py_RETURN_NONE;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
297 }
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
298
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
299 static int
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
300 BaseException_set_cause(PyObject *self, PyObject *arg) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
301 if (arg == NULL) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
302 PyErr_SetString(PyExc_TypeError, "__cause__ may not be deleted");
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
303 return -1;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
304 } else if (arg == Py_None) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
305 arg = NULL;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
306 } else if (!PyExceptionInstance_Check(arg)) {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
307 PyErr_SetString(PyExc_TypeError, "exception cause must be None "
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
308 "or derive from BaseException");
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
309 return -1;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
310 } else {
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
311 /* PyException_SetCause steals this reference */
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
312 Py_INCREF(arg);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
313 }
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
314 PyException_SetCause(self, arg);
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
315 return 0;
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
316 }
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
317
41716
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41611
diff changeset
318
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
319 static PyGetSetDef BaseException_getset[] = {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
320 {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
321 {"args", (getter)BaseException_get_args, (setter)BaseException_set_args},
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
322 {"__traceback__", (getter)BaseException_get_tb, (setter)BaseException_set_tb},
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
323 {"__context__", (getter)BaseException_get_context,
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
324 (setter)BaseException_set_context, PyDoc_STR("exception context")},
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
325 {"__cause__", (getter)BaseException_get_cause,
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
326 (setter)BaseException_set_cause, PyDoc_STR("exception cause")},
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
327 {NULL},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
328 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
329
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
330
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
331 PyObject *
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
332 PyException_GetTraceback(PyObject *self) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
333 PyBaseExceptionObject *base_self = (PyBaseExceptionObject *)self;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
334 Py_XINCREF(base_self->traceback);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
335 return base_self->traceback;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
336 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
337
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
338
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
339 int
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
340 PyException_SetTraceback(PyObject *self, PyObject *tb) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
341 return BaseException_set_tb((PyBaseExceptionObject *)self, tb);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
342 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
343
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
344 PyObject *
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
345 PyException_GetCause(PyObject *self) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
346 PyObject *cause = ((PyBaseExceptionObject *)self)->cause;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
347 Py_XINCREF(cause);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
348 return cause;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
349 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
350
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
351 /* Steals a reference to cause */
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
352 void
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
353 PyException_SetCause(PyObject *self, PyObject *cause) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
354 PyObject *old_cause = ((PyBaseExceptionObject *)self)->cause;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
355 ((PyBaseExceptionObject *)self)->cause = cause;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
356 Py_XDECREF(old_cause);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
357 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
358
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
359 PyObject *
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
360 PyException_GetContext(PyObject *self) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
361 PyObject *context = ((PyBaseExceptionObject *)self)->context;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
362 Py_XINCREF(context);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
363 return context;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
364 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
365
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
366 /* Steals a reference to context */
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
367 void
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
368 PyException_SetContext(PyObject *self, PyObject *context) {
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
369 PyObject *old_context = ((PyBaseExceptionObject *)self)->context;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
370 ((PyBaseExceptionObject *)self)->context = context;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
371 Py_XDECREF(old_context);
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
372 }
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
373
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 42855
diff changeset
374
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
375 static PyTypeObject _PyExc_BaseException = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
376 PyVarObject_HEAD_INIT(NULL, 0)
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
377 "BaseException", /*tp_name*/
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
378 sizeof(PyBaseExceptionObject), /*tp_basicsize*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
379 0, /*tp_itemsize*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
380 (destructor)BaseException_dealloc, /*tp_dealloc*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
381 0, /*tp_print*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
382 0, /*tp_getattr*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
383 0, /*tp_setattr*/
51271
87fbbf22adf3 Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50886
diff changeset
384 0, /* tp_reserved; */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
385 (reprfunc)BaseException_repr, /*tp_repr*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
386 0, /*tp_as_number*/
40959
0ea52558bdfe Remove the ability to slice/index on exceptions per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents: 40949
diff changeset
387 0, /*tp_as_sequence*/
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
388 0, /*tp_as_mapping*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
389 0, /*tp_hash */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
390 0, /*tp_call*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
391 (reprfunc)BaseException_str, /*tp_str*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
392 PyObject_GenericGetAttr, /*tp_getattro*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
393 PyObject_GenericSetAttr, /*tp_setattro*/
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
394 0, /*tp_as_buffer*/
40909
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40626
diff changeset
395 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
396 Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
397 PyDoc_STR("Common base class for all exceptions"), /* tp_doc */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
398 (traverseproc)BaseException_traverse, /* tp_traverse */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
399 (inquiry)BaseException_clear, /* tp_clear */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
400 0, /* tp_richcompare */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
401 0, /* tp_weaklistoffset */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
402 0, /* tp_iter */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
403 0, /* tp_iternext */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
404 BaseException_methods, /* tp_methods */
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51579
diff changeset
405 0, /* tp_members */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
406 BaseException_getset, /* tp_getset */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
407 0, /* tp_base */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
408 0, /* tp_dict */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
409 0, /* tp_descr_get */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
410 0, /* tp_descr_set */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
411 offsetof(PyBaseExceptionObject, dict), /* tp_dictoffset */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
412 (initproc)BaseException_init, /* tp_init */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
413 0, /* tp_alloc */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
414 BaseException_new, /* tp_new */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
415 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
416 /* the CPython API expects exceptions to be (PyObject *) - both a hold-over
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
417 from the previous implmentation and also allowing Python objects to be used
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
418 in the API */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
419 PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
420
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
421 /* note these macros omit the last semicolon so the macro invocation may
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
422 * include it and not look strange.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
423 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
424 #define SimpleExtendsException(EXCBASE, EXCNAME, EXCDOC) \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
425 static PyTypeObject _PyExc_ ## EXCNAME = { \
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
426 PyVarObject_HEAD_INIT(NULL, 0) \
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
427 # EXCNAME, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
428 sizeof(PyBaseExceptionObject), \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
429 0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
430 0, 0, 0, 0, 0, 0, 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
431 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
432 PyDoc_STR(EXCDOC), (traverseproc)BaseException_traverse, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
433 (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
434 0, 0, 0, offsetof(PyBaseExceptionObject, dict), \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
435 (initproc)BaseException_init, 0, BaseException_new,\
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
436 }; \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
437 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
438
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
439 #define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
440 static PyTypeObject _PyExc_ ## EXCNAME = { \
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
441 PyVarObject_HEAD_INIT(NULL, 0) \
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
442 # EXCNAME, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
443 sizeof(Py ## EXCSTORE ## Object), \
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
444 0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
445 0, 0, 0, 0, 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
446 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
447 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
448 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
449 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
450 (initproc)EXCSTORE ## _init, 0, 0, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
451 }; \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
452 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
453
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
454 #define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCNEW, \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
455 EXCMETHODS, EXCMEMBERS, EXCGETSET, \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
456 EXCSTR, EXCDOC) \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
457 static PyTypeObject _PyExc_ ## EXCNAME = { \
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
458 PyVarObject_HEAD_INIT(NULL, 0) \
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
459 # EXCNAME, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
460 sizeof(Py ## EXCSTORE ## Object), 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
461 (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
462 (reprfunc)EXCSTR, 0, 0, 0, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
463 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
464 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
465 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
466 EXCMEMBERS, EXCGETSET, &_ ## EXCBASE, \
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
467 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
468 (initproc)EXCSTORE ## _init, 0, EXCNEW,\
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
469 }; \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
470 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
471
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
472
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
473 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
474 * Exception extends BaseException
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
475 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
476 SimpleExtendsException(PyExc_BaseException, Exception,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
477 "Common base class for all non-exit exceptions.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
478
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
479
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
480 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
481 * TypeError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
482 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
483 SimpleExtendsException(PyExc_Exception, TypeError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
484 "Inappropriate argument type.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
485
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
486
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
487 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
488 * StopIteration extends Exception
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
489 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
490 SimpleExtendsException(PyExc_Exception, StopIteration,
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40959
diff changeset
491 "Signal the end from iterator.__next__().");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
492
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
493
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
494 /*
44129
b637349336fd Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44125
diff changeset
495 * GeneratorExit extends BaseException
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
496 */
44129
b637349336fd Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44125
diff changeset
497 SimpleExtendsException(PyExc_BaseException, GeneratorExit,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
498 "Request that a generator exit.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
499
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
500
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
501 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
502 * SystemExit extends BaseException
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
503 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
504
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
505 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
506 SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
507 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
508 Py_ssize_t size = PyTuple_GET_SIZE(args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
509
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
510 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
511 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
512
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
513 if (size == 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
514 return 0;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
515 Py_CLEAR(self->code);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
516 if (size == 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
517 self->code = PyTuple_GET_ITEM(args, 0);
70403
772d9825f154 SystemExit_init(): avoid an useless test
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
518 else /* size > 1 */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
519 self->code = args;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
520 Py_INCREF(self->code);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
521 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
522 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
523
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
524 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
525 SystemExit_clear(PySystemExitObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
526 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
527 Py_CLEAR(self->code);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
528 return BaseException_clear((PyBaseExceptionObject *)self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
529 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
530
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
531 static void
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
532 SystemExit_dealloc(PySystemExitObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
533 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
534 _PyObject_GC_UNTRACK(self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
535 SystemExit_clear(self);
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
536 Py_TYPE(self)->tp_free((PyObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
537 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
538
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
539 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
540 SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
541 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
542 Py_VISIT(self->code);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
543 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
544 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
545
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
546 static PyMemberDef SystemExit_members[] = {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
547 {"code", T_OBJECT, offsetof(PySystemExitObject, code), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
548 PyDoc_STR("exception code")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
549 {NULL} /* Sentinel */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
550 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
551
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
552 ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit,
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
553 0, 0, SystemExit_members, 0, 0,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
554 "Request to exit from the interpreter.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
555
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
556 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
557 * KeyboardInterrupt extends BaseException
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
558 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
559 SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
560 "Program interrupted by user.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
561
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
562
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
563 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
564 * ImportError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
565 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
566 SimpleExtendsException(PyExc_Exception, ImportError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
567 "Import can't find module, or can't find name in module.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
568
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
569
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
570 /*
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
571 * OSError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
572 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
573
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
574 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
575 #include "errmap.h"
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
576 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
577
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
578 /* Where a function has a single filename, such as open() or some
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
579 * of the os module functions, PyErr_SetFromErrnoWithFilename() is
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
580 * called, giving a third argument which is the filename. But, so
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
581 * that old code using in-place unpacking doesn't break, e.g.:
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
582 *
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
583 * except OSError, (errno, strerror):
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
584 *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
585 * we hack args so that it only contains two items. This also
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
586 * means we need our own __str__() which prints out the filename
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
587 * when it was supplied.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
588 */
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
589
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
590 static PyObject *
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
591 OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
592 {
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
593 PyOSErrorObject *self = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
594 Py_ssize_t nargs;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
595
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
596 PyObject *myerrno = NULL, *strerror = NULL, *filename = NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
597 PyObject *subslice = NULL;
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
598 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
599 PyObject *winerror = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
600 long winerrcode = 0;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
601 #endif
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
602
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
603 if (!_PyArg_NoKeywords(type->tp_name, kwds))
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
604 return NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
605 Py_INCREF(args);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
606 nargs = PyTuple_GET_SIZE(args);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
607
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
608 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
609 if (nargs >= 2 && nargs <= 4) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
610 if (!PyArg_UnpackTuple(args, "OSError", 2, 4,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
611 &myerrno, &strerror, &filename, &winerror))
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
612 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
613 if (winerror && PyLong_Check(winerror)) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
614 long errcode;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
615 PyObject *newargs;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
616 Py_ssize_t i;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
617
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
618 winerrcode = PyLong_AsLong(winerror);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
619 if (winerrcode == -1 && PyErr_Occurred())
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
620 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
621 /* Set errno to the corresponding POSIX errno (overriding
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
622 first argument). Windows Socket error codes (>= 10000)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
623 have the same value as their POSIX counterparts.
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
624 */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
625 if (winerrcode < 10000)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
626 errcode = winerror_to_errno(winerrcode);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
627 else
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
628 errcode = winerrcode;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
629 myerrno = PyLong_FromLong(errcode);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
630 if (!myerrno)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
631 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
632 newargs = PyTuple_New(nargs);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
633 if (!newargs)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
634 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
635 PyTuple_SET_ITEM(newargs, 0, myerrno);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
636 for (i = 1; i < nargs; i++) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
637 PyObject *val = PyTuple_GET_ITEM(args, i);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
638 Py_INCREF(val);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
639 PyTuple_SET_ITEM(newargs, i, val);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
640 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
641 Py_DECREF(args);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
642 args = newargs;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
643 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
644 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
645 #else
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
646 if (nargs >= 2 && nargs <= 3) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
647 if (!PyArg_UnpackTuple(args, "OSError", 2, 3,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
648 &myerrno, &strerror, &filename))
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
649 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
650 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
651 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
652 if (myerrno && PyLong_Check(myerrno) &&
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
653 errnomap && (PyObject *) type == PyExc_OSError) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
654 PyObject *newtype;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
655 newtype = PyDict_GetItem(errnomap, myerrno);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
656 if (newtype) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
657 assert(PyType_Check(newtype));
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
658 type = (PyTypeObject *) newtype;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
659 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
660 else if (PyErr_Occurred())
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
661 goto error;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
662 }
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
663
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
664 self = (PyOSErrorObject *) type->tp_alloc(type, 0);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
665 if (!self)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
666 goto error;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
667
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
668 self->dict = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
669 self->traceback = self->cause = self->context = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
670 self->written = -1;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
671
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
672 /* self->filename will remain Py_None otherwise */
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
673 if (filename && filename != Py_None) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
674 if ((PyObject *) type == PyExc_BlockingIOError &&
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
675 PyNumber_Check(filename)) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
676 /* BlockingIOError's 3rd argument can be the number of
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
677 * characters written.
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
678 */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
679 self->written = PyNumber_AsSsize_t(filename, PyExc_ValueError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
680 if (self->written == -1 && PyErr_Occurred())
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
681 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
682 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
683 else {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
684 Py_INCREF(filename);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
685 self->filename = filename;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
686
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
687 if (nargs >= 2 && nargs <= 3) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
688 /* filename is removed from the args tuple (for compatibility
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
689 purposes, see test_exceptions.py) */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
690 subslice = PyTuple_GetSlice(args, 0, 2);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
691 if (!subslice)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
692 goto error;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
693
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
694 Py_DECREF(args); /* replacing args */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
695 args = subslice;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
696 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
697 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
698 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
699
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
700 /* Steals the reference to args */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
701 self->args = args;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
702 args = NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
703
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
704 Py_XINCREF(myerrno);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
705 self->myerrno = myerrno;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
706
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
707 Py_XINCREF(strerror);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
708 self->strerror = strerror;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
709
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
710 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
711 Py_XINCREF(winerror);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
712 self->winerror = winerror;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
713 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
714
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
715 return (PyObject *) self;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
716
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
717 error:
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
718 Py_XDECREF(args);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
719 Py_XDECREF(self);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
720 return NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
721 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
722
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
723 static int
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
724 OSError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
725 {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
726 /* Everything already done in OSError_new */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
727 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
728 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
729
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
730 static int
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
731 OSError_clear(PyOSErrorObject *self)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
732 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
733 Py_CLEAR(self->myerrno);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
734 Py_CLEAR(self->strerror);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
735 Py_CLEAR(self->filename);
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
736 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
737 Py_CLEAR(self->winerror);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
738 #endif
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
739 return BaseException_clear((PyBaseExceptionObject *)self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
740 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
741
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
742 static void
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
743 OSError_dealloc(PyOSErrorObject *self)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
744 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
745 _PyObject_GC_UNTRACK(self);
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
746 OSError_clear(self);
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
747 Py_TYPE(self)->tp_free((PyObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
748 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
749
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
750 static int
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
751 OSError_traverse(PyOSErrorObject *self, visitproc visit,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
752 void *arg)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
753 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
754 Py_VISIT(self->myerrno);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
755 Py_VISIT(self->strerror);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
756 Py_VISIT(self->filename);
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
757 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
758 Py_VISIT(self->winerror);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
759 #endif
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
760 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
761 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
762
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
763 static PyObject *
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
764 OSError_str(PyOSErrorObject *self)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
765 {
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
766 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
767 /* If available, winerror has the priority over myerrno */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
768 if (self->winerror && self->filename)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
769 return PyUnicode_FromFormat("[Error %S] %S: %R",
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
770 self->winerror ? self->winerror: Py_None,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
771 self->strerror ? self->strerror: Py_None,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
772 self->filename);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
773 if (self->winerror && self->strerror)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
774 return PyUnicode_FromFormat("[Error %S] %S",
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
775 self->winerror ? self->winerror: Py_None,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
776 self->strerror ? self->strerror: Py_None);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
777 #endif
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
778 if (self->filename)
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
779 return PyUnicode_FromFormat("[Errno %S] %S: %R",
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
780 self->myerrno ? self->myerrno: Py_None,
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
781 self->strerror ? self->strerror: Py_None,
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
782 self->filename);
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
783 if (self->myerrno && self->strerror)
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
784 return PyUnicode_FromFormat("[Errno %S] %S",
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
785 self->myerrno ? self->myerrno: Py_None,
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
786 self->strerror ? self->strerror: Py_None);
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
787 return BaseException_str((PyBaseExceptionObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
788 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
789
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
790 static PyObject *
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
791 OSError_reduce(PyOSErrorObject *self)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
792 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
793 PyObject *args = self->args;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
794 PyObject *res = NULL, *tmp;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
795
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
796 /* self->args is only the first two real arguments if there was a
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
797 * file name given to OSError. */
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
798 if (PyTuple_GET_SIZE(args) == 2 && self->filename) {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
799 args = PyTuple_New(3);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
800 if (!args) return NULL;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
801
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
802 tmp = PyTuple_GET_ITEM(self->args, 0);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
803 Py_INCREF(tmp);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
804 PyTuple_SET_ITEM(args, 0, tmp);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
805
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
806 tmp = PyTuple_GET_ITEM(self->args, 1);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
807 Py_INCREF(tmp);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
808 PyTuple_SET_ITEM(args, 1, tmp);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
809
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
810 Py_INCREF(self->filename);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
811 PyTuple_SET_ITEM(args, 2, self->filename);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
812 } else
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
813 Py_INCREF(args);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
814
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
815 if (self->dict)
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
816 res = PyTuple_Pack(3, Py_TYPE(self), args, self->dict);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
817 else
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
818 res = PyTuple_Pack(2, Py_TYPE(self), args);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
819 Py_DECREF(args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
820 return res;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
821 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
822
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
823 static PyObject *
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
824 OSError_written_get(PyOSErrorObject *self, void *context)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
825 {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
826 if (self->written == -1) {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
827 PyErr_SetString(PyExc_AttributeError, "characters_written");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
828 return NULL;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
829 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
830 return PyLong_FromSsize_t(self->written);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
831 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
832
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
833 static int
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
834 OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
835 {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
836 Py_ssize_t n;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
837 n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
838 if (n == -1 && PyErr_Occurred())
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
839 return -1;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
840 self->written = n;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
841 return 0;
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
842 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
843
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
844 static PyMemberDef OSError_members[] = {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
845 {"errno", T_OBJECT, offsetof(PyOSErrorObject, myerrno), 0,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
846 PyDoc_STR("POSIX exception code")},
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
847 {"strerror", T_OBJECT, offsetof(PyOSErrorObject, strerror), 0,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
848 PyDoc_STR("exception strerror")},
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
849 {"filename", T_OBJECT, offsetof(PyOSErrorObject, filename), 0,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
850 PyDoc_STR("exception filename")},
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
851 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
852 {"winerror", T_OBJECT, offsetof(PyOSErrorObject, winerror), 0,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
853 PyDoc_STR("Win32 exception code")},
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
854 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
855 {NULL} /* Sentinel */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
856 };
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
857
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
858 static PyMethodDef OSError_methods[] = {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
859 {"__reduce__", (PyCFunction)OSError_reduce, METH_NOARGS},
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
860 {NULL}
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
861 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
862
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
863 static PyGetSetDef OSError_getset[] = {
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
864 {"characters_written", (getter) OSError_written_get,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
865 (setter) OSError_written_set, NULL},
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
866 {NULL}
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
867 };
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
868
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
869
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
870 ComplexExtendsException(PyExc_Exception, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
871 OSError, OSError_new,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
872 OSError_methods, OSError_members, OSError_getset,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
873 OSError_str,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
874 "Base class for I/O related errors.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
875
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
876
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
877 /*
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
878 * Various OSError subclasses
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
879 */
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
880 MiddlingExtendsException(PyExc_OSError, BlockingIOError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
881 "I/O operation would block.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
882 MiddlingExtendsException(PyExc_OSError, ConnectionError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
883 "Connection error.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
884 MiddlingExtendsException(PyExc_OSError, ChildProcessError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
885 "Child process error.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
886 MiddlingExtendsException(PyExc_ConnectionError, BrokenPipeError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
887 "Broken pipe.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
888 MiddlingExtendsException(PyExc_ConnectionError, ConnectionAbortedError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
889 "Connection aborted.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
890 MiddlingExtendsException(PyExc_ConnectionError, ConnectionRefusedError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
891 "Connection refused.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
892 MiddlingExtendsException(PyExc_ConnectionError, ConnectionResetError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
893 "Connection reset.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
894 MiddlingExtendsException(PyExc_OSError, FileExistsError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
895 "File already exists.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
896 MiddlingExtendsException(PyExc_OSError, FileNotFoundError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
897 "File not found.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
898 MiddlingExtendsException(PyExc_OSError, IsADirectoryError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
899 "Operation doesn't work on directories.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
900 MiddlingExtendsException(PyExc_OSError, NotADirectoryError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
901 "Operation only works on directories.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
902 MiddlingExtendsException(PyExc_OSError, InterruptedError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
903 "Interrupted by signal.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
904 MiddlingExtendsException(PyExc_OSError, PermissionError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
905 "Not enough permissions.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
906 MiddlingExtendsException(PyExc_OSError, ProcessLookupError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
907 "Process not found.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
908 MiddlingExtendsException(PyExc_OSError, TimeoutError, OSError,
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
909 "Timeout expired.");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
910
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
911 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
912 * EOFError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
913 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
914 SimpleExtendsException(PyExc_Exception, EOFError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
915 "Read beyond end of file.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
916
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
917
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
918 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
919 * RuntimeError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
920 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
921 SimpleExtendsException(PyExc_Exception, RuntimeError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
922 "Unspecified run-time error.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
923
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
924
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
925 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
926 * NotImplementedError extends RuntimeError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
927 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
928 SimpleExtendsException(PyExc_RuntimeError, NotImplementedError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
929 "Method or function hasn't been implemented yet.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
930
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
931 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
932 * NameError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
933 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
934 SimpleExtendsException(PyExc_Exception, NameError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
935 "Name not found globally.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
936
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
937 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
938 * UnboundLocalError extends NameError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
939 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
940 SimpleExtendsException(PyExc_NameError, UnboundLocalError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
941 "Local name referenced but not bound to a value.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
942
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
943 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
944 * AttributeError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
945 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
946 SimpleExtendsException(PyExc_Exception, AttributeError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
947 "Attribute not found.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
948
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
949
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
950 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
951 * SyntaxError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
952 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
953
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
954 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
955 SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
956 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
957 PyObject *info = NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
958 Py_ssize_t lenargs = PyTuple_GET_SIZE(args);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
959
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
960 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
961 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
962
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
963 if (lenargs >= 1) {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
964 Py_CLEAR(self->msg);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
965 self->msg = PyTuple_GET_ITEM(args, 0);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
966 Py_INCREF(self->msg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
967 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
968 if (lenargs == 2) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
969 info = PyTuple_GET_ITEM(args, 1);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
970 info = PySequence_Tuple(info);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
971 if (!info) return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
972
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
973 if (PyTuple_GET_SIZE(info) != 4) {
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
974 /* not a very good error message, but it's what Python 2.4 gives */
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
975 PyErr_SetString(PyExc_IndexError, "tuple index out of range");
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
976 Py_DECREF(info);
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
977 return -1;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
978 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
979
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
980 Py_CLEAR(self->filename);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
981 self->filename = PyTuple_GET_ITEM(info, 0);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
982 Py_INCREF(self->filename);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
983
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
984 Py_CLEAR(self->lineno);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
985 self->lineno = PyTuple_GET_ITEM(info, 1);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
986 Py_INCREF(self->lineno);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
987
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
988 Py_CLEAR(self->offset);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
989 self->offset = PyTuple_GET_ITEM(info, 2);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
990 Py_INCREF(self->offset);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
991
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
992 Py_CLEAR(self->text);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
993 self->text = PyTuple_GET_ITEM(info, 3);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
994 Py_INCREF(self->text);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
995
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
996 Py_DECREF(info);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
997 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
998 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
999 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1000
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1001 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1002 SyntaxError_clear(PySyntaxErrorObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1003 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1004 Py_CLEAR(self->msg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1005 Py_CLEAR(self->filename);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1006 Py_CLEAR(self->lineno);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1007 Py_CLEAR(self->offset);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1008 Py_CLEAR(self->text);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1009 Py_CLEAR(self->print_file_and_line);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1010 return BaseException_clear((PyBaseExceptionObject *)self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1011 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1012
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1013 static void
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1014 SyntaxError_dealloc(PySyntaxErrorObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1015 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1016 _PyObject_GC_UNTRACK(self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1017 SyntaxError_clear(self);
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
1018 Py_TYPE(self)->tp_free((PyObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1019 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1020
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1021 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1022 SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1023 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1024 Py_VISIT(self->msg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1025 Py_VISIT(self->filename);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1026 Py_VISIT(self->lineno);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1027 Py_VISIT(self->offset);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1028 Py_VISIT(self->text);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1029 Py_VISIT(self->print_file_and_line);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1030 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1031 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1032
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1033 /* This is called "my_basename" instead of just "basename" to avoid name
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1034 conflicts with glibc; basename is already prototyped if _GNU_SOURCE is
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1035 defined, and Python does define that. */
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1036 static PyObject*
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1037 my_basename(PyObject *name)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1038 {
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1039 Py_ssize_t i, size, offset;
72703
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1040 int kind;
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1041 void *data;
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1042
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1043 if (PyUnicode_READY(name))
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1044 return NULL;
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1045 kind = PyUnicode_KIND(name);
eb2821cc3edf Fix my_basename(): make the string ready
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72475
diff changeset
1046 data = PyUnicode_DATA(name);
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1047 size = PyUnicode_GET_LENGTH(name);
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1048 offset = 0;
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1049 for(i=0; i < size; i++) {
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1050 if (PyUnicode_READ(kind, data, i) == SEP)
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1051 offset = i + 1;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1052 }
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1053 if (offset != 0)
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1054 return PyUnicode_Substring(name, offset, size);
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1055 else {
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1056 Py_INCREF(name);
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1057 return name;
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1058 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1059 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1060
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1061
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1062 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1063 SyntaxError_str(PySyntaxErrorObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1064 {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1065 int have_lineno = 0;
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1066 PyObject *filename;
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1067 PyObject *result;
44158
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1068 /* Below, we always ignore overflow errors, just printing -1.
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1069 Still, we cannot allow an OverflowError to be raised, so
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1070 we need to call PyLong_AsLongAndOverflow. */
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1071 int overflow;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1072
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1073 /* XXX -- do all the additional formatting with filename and
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1074 lineno here */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1075
42855
d5b52d56beba Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents: 42669
diff changeset
1076 if (self->filename && PyUnicode_Check(self->filename)) {
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1077 filename = my_basename(self->filename);
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1078 if (filename == NULL)
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1079 return NULL;
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1080 } else {
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1081 filename = NULL;
42305
d0719406b2c6 Change Py_BuildValue to generate Unicode objects for
Martin v. Löwis <martin@v.loewis.de>
parents: 42118
diff changeset
1082 }
44158
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1083 have_lineno = (self->lineno != NULL) && PyLong_CheckExact(self->lineno);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1084
42305
d0719406b2c6 Change Py_BuildValue to generate Unicode objects for
Martin v. Löwis <martin@v.loewis.de>
parents: 42118
diff changeset
1085 if (!filename && !have_lineno)
43866
8ed0280c2ab6 Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents: 43777
diff changeset
1086 return PyObject_Str(self->msg ? self->msg : Py_None);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1087
42305
d0719406b2c6 Change Py_BuildValue to generate Unicode objects for
Martin v. Löwis <martin@v.loewis.de>
parents: 42118
diff changeset
1088 if (filename && have_lineno)
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1089 result = PyUnicode_FromFormat("%S (%U, line %ld)",
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
1090 self->msg ? self->msg : Py_None,
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1091 filename,
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
1092 PyLong_AsLongAndOverflow(self->lineno, &overflow));
42305
d0719406b2c6 Change Py_BuildValue to generate Unicode objects for
Martin v. Löwis <martin@v.loewis.de>
parents: 42118
diff changeset
1093 else if (filename)
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1094 result = PyUnicode_FromFormat("%S (%U)",
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
1095 self->msg ? self->msg : Py_None,
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1096 filename);
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1097 else /* only have_lineno */
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1098 result = PyUnicode_FromFormat("%S (line %ld)",
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
1099 self->msg ? self->msg : Py_None,
44158
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44129
diff changeset
1100 PyLong_AsLongAndOverflow(self->lineno, &overflow));
61058
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1101 Py_XDECREF(filename);
04a18e59cc2c Don't decode/recode the unicode filename in SyntaxError_str()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59127
diff changeset
1102 return result;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1103 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1104
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1105 static PyMemberDef SyntaxError_members[] = {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1106 {"msg", T_OBJECT, offsetof(PySyntaxErrorObject, msg), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1107 PyDoc_STR("exception msg")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1108 {"filename", T_OBJECT, offsetof(PySyntaxErrorObject, filename), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1109 PyDoc_STR("exception filename")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1110 {"lineno", T_OBJECT, offsetof(PySyntaxErrorObject, lineno), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1111 PyDoc_STR("exception lineno")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1112 {"offset", T_OBJECT, offsetof(PySyntaxErrorObject, offset), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1113 PyDoc_STR("exception offset")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1114 {"text", T_OBJECT, offsetof(PySyntaxErrorObject, text), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1115 PyDoc_STR("exception text")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1116 {"print_file_and_line", T_OBJECT,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1117 offsetof(PySyntaxErrorObject, print_file_and_line), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1118 PyDoc_STR("exception print_file_and_line")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1119 {NULL} /* Sentinel */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1120 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1121
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1122 ComplexExtendsException(PyExc_Exception, SyntaxError, SyntaxError,
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
1123 0, 0, SyntaxError_members, 0,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1124 SyntaxError_str, "Invalid syntax.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1125
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1126
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1127 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1128 * IndentationError extends SyntaxError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1129 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1130 MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1131 "Improper indentation.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1132
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1133
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1134 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1135 * TabError extends IndentationError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1136 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1137 MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1138 "Improper mixture of spaces and tabs.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1139
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1140
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1141 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1142 * LookupError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1143 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1144 SimpleExtendsException(PyExc_Exception, LookupError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1145 "Base class for lookup errors.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1146
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1147
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1148 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1149 * IndexError extends LookupError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1150 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1151 SimpleExtendsException(PyExc_LookupError, IndexError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1152 "Sequence index out of range.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1153
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1154
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1155 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1156 * KeyError extends LookupError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1157 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1158 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1159 KeyError_str(PyBaseExceptionObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1160 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1161 /* If args is a tuple of exactly one item, apply repr to args[0].
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1162 This is done so that e.g. the exception raised by {}[''] prints
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1163 KeyError: ''
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1164 rather than the confusing
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1165 KeyError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1166 alone. The downside is that if KeyError is raised with an explanatory
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1167 string, that string will be displayed in quotes. Too bad.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1168 If args is anything else, use the default BaseException__str__().
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1169 */
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1170 if (PyTuple_GET_SIZE(self->args) == 1) {
41882
1056530616ac Change tp_str implementations of exception classes
Walter Dörwald <walter@livinglogic.de>
parents: 41782
diff changeset
1171 return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0));
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1172 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1173 return BaseException_str(self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1174 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1175
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1176 ComplexExtendsException(PyExc_LookupError, KeyError, BaseException,
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
1177 0, 0, 0, 0, KeyError_str, "Mapping key not found.");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1178
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1179
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1180 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1181 * ValueError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1182 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1183 SimpleExtendsException(PyExc_Exception, ValueError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1184 "Inappropriate argument value (of correct type).");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1185
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1186 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1187 * UnicodeError extends ValueError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1188 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1189
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1190 SimpleExtendsException(PyExc_ValueError, UnicodeError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1191 "Unicode related error.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1192
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1193 static PyObject *
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1194 get_string(PyObject *attr, const char *name)
41611
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1195 {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1196 if (!attr) {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1197 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1198 return NULL;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1199 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1200
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1201 if (!PyBytes_Check(attr)) {
41611
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1202 PyErr_Format(PyExc_TypeError, "%.200s attribute must be bytes", name);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1203 return NULL;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1204 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1205 Py_INCREF(attr);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1206 return attr;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1207 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1208
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
1209 static PyObject *
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1210 get_unicode(PyObject *attr, const char *name)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1211 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1212 if (!attr) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1213 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1214 return NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1215 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1216
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1217 if (!PyUnicode_Check(attr)) {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1218 PyErr_Format(PyExc_TypeError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1219 "%.200s attribute must be unicode", name);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1220 return NULL;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1221 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1222 Py_INCREF(attr);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1223 return attr;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1224 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1225
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1226 static int
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1227 set_unicodefromstring(PyObject **attr, const char *value)
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1228 {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1229 PyObject *obj = PyUnicode_FromString(value);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1230 if (!obj)
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1231 return -1;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1232 Py_CLEAR(*attr);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1233 *attr = obj;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1234 return 0;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1235 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1236
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1237 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1238 PyUnicodeEncodeError_GetEncoding(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1239 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1240 return get_unicode(((PyUnicodeErrorObject *)exc)->encoding, "encoding");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1241 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1242
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1243 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1244 PyUnicodeDecodeError_GetEncoding(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1245 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1246 return get_unicode(((PyUnicodeErrorObject *)exc)->encoding, "encoding");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1247 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1248
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1249 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1250 PyUnicodeEncodeError_GetObject(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1251 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1252 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1253 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1254
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1255 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1256 PyUnicodeDecodeError_GetObject(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1257 {
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1258 return get_string(((PyUnicodeErrorObject *)exc)->object, "object");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1259 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1260
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1261 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1262 PyUnicodeTranslateError_GetObject(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1263 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1264 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1265 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1266
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1267 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1268 PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1269 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1270 Py_ssize_t size;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1271 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1272 "object");
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1273 if (!obj)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1274 return -1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1275 *start = ((PyUnicodeErrorObject *)exc)->start;
73655
2e37fc70e2dd Fix misuse of PyUnicode_GET_SIZE() => PyUnicode_GET_LENGTH()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73649
diff changeset
1276 size = PyUnicode_GET_LENGTH(obj);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1277 if (*start<0)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1278 *start = 0; /*XXX check for values <0*/
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1279 if (*start>=size)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1280 *start = size-1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1281 Py_DECREF(obj);
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1282 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1283 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1284
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1285
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1286 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1287 PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1288 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1289 Py_ssize_t size;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1290 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, "object");
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1291 if (!obj)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1292 return -1;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1293 size = PyBytes_GET_SIZE(obj);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1294 *start = ((PyUnicodeErrorObject *)exc)->start;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1295 if (*start<0)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1296 *start = 0;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1297 if (*start>=size)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1298 *start = size-1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1299 Py_DECREF(obj);
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1300 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1301 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1302
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1303
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1304 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1305 PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1306 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1307 return PyUnicodeEncodeError_GetStart(exc, start);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1308 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1309
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1310
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1311 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1312 PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1313 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1314 ((PyUnicodeErrorObject *)exc)->start = start;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1315 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1316 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1317
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1318
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1319 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1320 PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1321 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1322 ((PyUnicodeErrorObject *)exc)->start = start;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1323 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1324 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1325
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1326
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1327 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1328 PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1329 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1330 ((PyUnicodeErrorObject *)exc)->start = start;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1331 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1332 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1333
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1334
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1335 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1336 PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1337 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1338 Py_ssize_t size;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1339 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1340 "object");
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1341 if (!obj)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1342 return -1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1343 *end = ((PyUnicodeErrorObject *)exc)->end;
73655
2e37fc70e2dd Fix misuse of PyUnicode_GET_SIZE() => PyUnicode_GET_LENGTH()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73649
diff changeset
1344 size = PyUnicode_GET_LENGTH(obj);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1345 if (*end<1)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1346 *end = 1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1347 if (*end>size)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1348 *end = size;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1349 Py_DECREF(obj);
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1350 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1351 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1352
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1353
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1354 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1355 PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1356 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1357 Py_ssize_t size;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1358 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, "object");
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1359 if (!obj)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1360 return -1;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1361 size = PyBytes_GET_SIZE(obj);
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1362 *end = ((PyUnicodeErrorObject *)exc)->end;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1363 if (*end<1)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1364 *end = 1;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1365 if (*end>size)
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1366 *end = size;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1367 Py_DECREF(obj);
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1368 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1369 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1370
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1371
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1372 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1373 PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1374 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1375 return PyUnicodeEncodeError_GetEnd(exc, start);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1376 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1377
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1378
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1379 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1380 PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1381 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1382 ((PyUnicodeErrorObject *)exc)->end = end;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1383 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1384 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1385
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1386
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1387 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1388 PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1389 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1390 ((PyUnicodeErrorObject *)exc)->end = end;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1391 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1392 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1393
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1394
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1395 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1396 PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1397 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1398 ((PyUnicodeErrorObject *)exc)->end = end;
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1399 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1400 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1401
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1402 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1403 PyUnicodeEncodeError_GetReason(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1404 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1405 return get_unicode(((PyUnicodeErrorObject *)exc)->reason, "reason");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1406 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1407
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1408
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1409 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1410 PyUnicodeDecodeError_GetReason(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1411 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1412 return get_unicode(((PyUnicodeErrorObject *)exc)->reason, "reason");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1413 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1414
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1415
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1416 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1417 PyUnicodeTranslateError_GetReason(PyObject *exc)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1418 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1419 return get_unicode(((PyUnicodeErrorObject *)exc)->reason, "reason");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1420 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1421
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1422
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1423 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1424 PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1425 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1426 return set_unicodefromstring(&((PyUnicodeErrorObject *)exc)->reason,
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1427 reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1428 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1429
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1430
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1431 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1432 PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1433 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1434 return set_unicodefromstring(&((PyUnicodeErrorObject *)exc)->reason,
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1435 reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1436 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1437
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1438
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1439 int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1440 PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1441 {
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1442 return set_unicodefromstring(&((PyUnicodeErrorObject *)exc)->reason,
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1443 reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1444 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1445
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1446
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1447 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1448 UnicodeError_clear(PyUnicodeErrorObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1449 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1450 Py_CLEAR(self->encoding);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1451 Py_CLEAR(self->object);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1452 Py_CLEAR(self->reason);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1453 return BaseException_clear((PyBaseExceptionObject *)self);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1454 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1455
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1456 static void
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1457 UnicodeError_dealloc(PyUnicodeErrorObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1458 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1459 _PyObject_GC_UNTRACK(self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1460 UnicodeError_clear(self);
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
1461 Py_TYPE(self)->tp_free((PyObject *)self);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1462 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1463
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1464 static int
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1465 UnicodeError_traverse(PyUnicodeErrorObject *self, visitproc visit, void *arg)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1466 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1467 Py_VISIT(self->encoding);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1468 Py_VISIT(self->object);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1469 Py_VISIT(self->reason);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1470 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1471 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1472
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1473 static PyMemberDef UnicodeError_members[] = {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1474 {"encoding", T_OBJECT, offsetof(PyUnicodeErrorObject, encoding), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1475 PyDoc_STR("exception encoding")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1476 {"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1477 PyDoc_STR("exception object")},
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1478 {"start", T_PYSSIZET, offsetof(PyUnicodeErrorObject, start), 0,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1479 PyDoc_STR("exception start")},
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1480 {"end", T_PYSSIZET, offsetof(PyUnicodeErrorObject, end), 0,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1481 PyDoc_STR("exception end")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1482 {"reason", T_OBJECT, offsetof(PyUnicodeErrorObject, reason), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1483 PyDoc_STR("exception reason")},
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1484 {NULL} /* Sentinel */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1485 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1486
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1487
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1488 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1489 * UnicodeEncodeError extends UnicodeError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1490 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1491
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1492 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1493 UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1494 {
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1495 PyUnicodeErrorObject *err;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1496
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1497 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1498 return -1;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1499
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1500 err = (PyUnicodeErrorObject *)self;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1501
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1502 Py_CLEAR(err->encoding);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1503 Py_CLEAR(err->object);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1504 Py_CLEAR(err->reason);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1505
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1506 if (!PyArg_ParseTuple(args, "O!O!nnO!",
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1507 &PyUnicode_Type, &err->encoding,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1508 &PyUnicode_Type, &err->object,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1509 &err->start,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1510 &err->end,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1511 &PyUnicode_Type, &err->reason)) {
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1512 err->encoding = err->object = err->reason = NULL;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1513 return -1;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1514 }
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1515
73350
0883d6a103a0 Port error handlers from Py_UNICODE indexing to code point indexing.
Martin v. Löwis <martin@v.loewis.de>
parents: 72879
diff changeset
1516 if (PyUnicode_READY(err->object) < -1) {
0883d6a103a0 Port error handlers from Py_UNICODE indexing to code point indexing.
Martin v. Löwis <martin@v.loewis.de>
parents: 72879
diff changeset
1517 err->encoding = NULL;
0883d6a103a0 Port error handlers from Py_UNICODE indexing to code point indexing.
Martin v. Löwis <martin@v.loewis.de>
parents: 72879
diff changeset
1518 return -1;
0883d6a103a0 Port error handlers from Py_UNICODE indexing to code point indexing.
Martin v. Löwis <martin@v.loewis.de>
parents: 72879
diff changeset
1519 }
0883d6a103a0 Port error handlers from Py_UNICODE indexing to code point indexing.
Martin v. Löwis <martin@v.loewis.de>
parents: 72879
diff changeset
1520
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1521 Py_INCREF(err->encoding);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1522 Py_INCREF(err->object);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1523 Py_INCREF(err->reason);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1524
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1525 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1526 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1527
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1528 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1529 UnicodeEncodeError_str(PyObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1530 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1531 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self;
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1532 PyObject *result = NULL;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1533 PyObject *reason_str = NULL;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1534 PyObject *encoding_str = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1535
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1536 /* Get reason and encoding as strings, which they might not be if
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1537 they've been modified after we were contructed. */
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1538 reason_str = PyObject_Str(uself->reason);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1539 if (reason_str == NULL)
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1540 goto done;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1541 encoding_str = PyObject_Str(uself->encoding);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1542 if (encoding_str == NULL)
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1543 goto done;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1544
73644
5b426bf9260c UnicodeEncodeError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73350
diff changeset
1545 if (uself->start < PyUnicode_GET_LENGTH(uself->object) && uself->end == uself->start+1) {
5b426bf9260c UnicodeEncodeError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73350
diff changeset
1546 Py_UCS4 badchar = PyUnicode_ReadChar(uself->object, uself->start);
41940
5014f8daa57f PyUnicode_FromFormat() does support %02x, so use it
Walter Dörwald <walter@livinglogic.de>
parents: 41882
diff changeset
1547 const char *fmt;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1548 if (badchar <= 0xff)
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1549 fmt = "'%U' codec can't encode character '\\x%02x' in position %zd: %U";
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1550 else if (badchar <= 0xffff)
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1551 fmt = "'%U' codec can't encode character '\\u%04x' in position %zd: %U";
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1552 else
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1553 fmt = "'%U' codec can't encode character '\\U%08x' in position %zd: %U";
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1554 result = PyUnicode_FromFormat(
41940
5014f8daa57f PyUnicode_FromFormat() does support %02x, so use it
Walter Dörwald <walter@livinglogic.de>
parents: 41882
diff changeset
1555 fmt,
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1556 encoding_str,
73644
5b426bf9260c UnicodeEncodeError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73350
diff changeset
1557 (int)badchar,
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1558 uself->start,
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1559 reason_str);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1560 }
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1561 else {
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1562 result = PyUnicode_FromFormat(
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1563 "'%U' codec can't encode characters in position %zd-%zd: %U",
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1564 encoding_str,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1565 uself->start,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1566 uself->end-1,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1567 reason_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1568 }
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1569 done:
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1570 Py_XDECREF(reason_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1571 Py_XDECREF(encoding_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1572 return result;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1573 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1574
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1575 static PyTypeObject _PyExc_UnicodeEncodeError = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
1576 PyVarObject_HEAD_INIT(NULL, 0)
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
1577 "UnicodeEncodeError",
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1578 sizeof(PyUnicodeErrorObject), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1579 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1580 (reprfunc)UnicodeEncodeError_str, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1581 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1582 PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse,
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1583 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1584 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1585 (initproc)UnicodeEncodeError_init, 0, BaseException_new,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1586 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1587 PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1588
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1589 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1590 PyUnicodeEncodeError_Create(
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1591 const char *encoding, const Py_UNICODE *object, Py_ssize_t length,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1592 Py_ssize_t start, Py_ssize_t end, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1593 {
62155
600c23127207 Issue #8848: U / U# formats of Py_BuildValue() are just alias to s / s#
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1594 return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1595 encoding, object, length, start, end, reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1596 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1597
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1598
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1599 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1600 * UnicodeDecodeError extends UnicodeError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1601 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1602
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1603 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1604 UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1605 {
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1606 PyUnicodeErrorObject *ude;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1607 const char *data;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1608 Py_ssize_t size;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1609
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1610 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1611 return -1;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1612
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1613 ude = (PyUnicodeErrorObject *)self;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1614
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1615 Py_CLEAR(ude->encoding);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1616 Py_CLEAR(ude->object);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1617 Py_CLEAR(ude->reason);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1618
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1619 if (!PyArg_ParseTuple(args, "O!OnnO!",
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1620 &PyUnicode_Type, &ude->encoding,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1621 &ude->object,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1622 &ude->start,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1623 &ude->end,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1624 &PyUnicode_Type, &ude->reason)) {
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1625 ude->encoding = ude->object = ude->reason = NULL;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1626 return -1;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1627 }
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1628
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1629 if (!PyBytes_Check(ude->object)) {
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1630 if (PyObject_AsReadBuffer(ude->object, (const void **)&data, &size)) {
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1631 ude->encoding = ude->object = ude->reason = NULL;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1632 return -1;
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1633 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1634 ude->object = PyBytes_FromStringAndSize(data, size);
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1635 }
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1636 else {
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1637 Py_INCREF(ude->object);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1638 }
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1639
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1640 Py_INCREF(ude->encoding);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1641 Py_INCREF(ude->reason);
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1642
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
1643 return 0;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1644 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1645
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1646 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1647 UnicodeDecodeError_str(PyObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1648 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1649 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self;
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1650 PyObject *result = NULL;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1651 PyObject *reason_str = NULL;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1652 PyObject *encoding_str = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1653
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1654 /* Get reason and encoding as strings, which they might not be if
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1655 they've been modified after we were contructed. */
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1656 reason_str = PyObject_Str(uself->reason);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1657 if (reason_str == NULL)
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1658 goto done;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1659 encoding_str = PyObject_Str(uself->encoding);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1660 if (encoding_str == NULL)
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1661 goto done;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1662
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1663 if (uself->start < PyBytes_GET_SIZE(uself->object) && uself->end == uself->start+1) {
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 46682
diff changeset
1664 int byte = (int)(PyBytes_AS_STRING(((PyUnicodeErrorObject *)self)->object)[uself->start]&0xff);
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1665 result = PyUnicode_FromFormat(
41940
5014f8daa57f PyUnicode_FromFormat() does support %02x, so use it
Walter Dörwald <walter@livinglogic.de>
parents: 41882
diff changeset
1666 "'%U' codec can't decode byte 0x%02x in position %zd: %U",
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1667 encoding_str,
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1668 byte,
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1669 uself->start,
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1670 reason_str);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1671 }
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1672 else {
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1673 result = PyUnicode_FromFormat(
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1674 "'%U' codec can't decode bytes in position %zd-%zd: %U",
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1675 encoding_str,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1676 uself->start,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1677 uself->end-1,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1678 reason_str
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1679 );
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1680 }
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1681 done:
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1682 Py_XDECREF(reason_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1683 Py_XDECREF(encoding_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1684 return result;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1685 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1686
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1687 static PyTypeObject _PyExc_UnicodeDecodeError = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
1688 PyVarObject_HEAD_INIT(NULL, 0)
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
1689 "UnicodeDecodeError",
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1690 sizeof(PyUnicodeErrorObject), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1691 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1692 (reprfunc)UnicodeDecodeError_str, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1693 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1694 PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse,
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1695 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1696 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1697 (initproc)UnicodeDecodeError_init, 0, BaseException_new,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1698 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1699 PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1700
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1701 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1702 PyUnicodeDecodeError_Create(
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1703 const char *encoding, const char *object, Py_ssize_t length,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1704 Py_ssize_t start, Py_ssize_t end, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1705 {
62155
600c23127207 Issue #8848: U / U# formats of Py_BuildValue() are just alias to s / s#
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1706 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "sy#nns",
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1707 encoding, object, length, start, end, reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1708 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1709
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1710
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1711 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1712 * UnicodeTranslateError extends UnicodeError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1713 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1714
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1715 static int
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1716 UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1717 PyObject *kwds)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1718 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1719 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1720 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1721
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1722 Py_CLEAR(self->object);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1723 Py_CLEAR(self->reason);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1724
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1725 if (!PyArg_ParseTuple(args, "O!nnO!",
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1726 &PyUnicode_Type, &self->object,
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1727 &self->start,
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1728 &self->end,
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41749
diff changeset
1729 &PyUnicode_Type, &self->reason)) {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1730 self->object = self->reason = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1731 return -1;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1732 }
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1733
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1734 Py_INCREF(self->object);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1735 Py_INCREF(self->reason);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1736
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1737 return 0;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1738 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1739
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1740
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1741 static PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1742 UnicodeTranslateError_str(PyObject *self)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1743 {
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1744 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self;
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1745 PyObject *result = NULL;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1746 PyObject *reason_str = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1747
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1748 /* Get reason as a string, which it might not be if it's been
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1749 modified after we were contructed. */
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1750 reason_str = PyObject_Str(uself->reason);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1751 if (reason_str == NULL)
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1752 goto done;
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1753
73649
244d9159aa38 UnicodeTranslateError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73644
diff changeset
1754 if (uself->start < PyUnicode_GET_LENGTH(uself->object) && uself->end == uself->start+1) {
244d9159aa38 UnicodeTranslateError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73644
diff changeset
1755 Py_UCS4 badchar = PyUnicode_ReadChar(uself->object, uself->start);
41940
5014f8daa57f PyUnicode_FromFormat() does support %02x, so use it
Walter Dörwald <walter@livinglogic.de>
parents: 41882
diff changeset
1756 const char *fmt;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1757 if (badchar <= 0xff)
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1758 fmt = "can't translate character '\\x%02x' in position %zd: %U";
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1759 else if (badchar <= 0xffff)
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1760 fmt = "can't translate character '\\u%04x' in position %zd: %U";
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1761 else
42118
70a0831feda6 Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents: 42110
diff changeset
1762 fmt = "can't translate character '\\U%08x' in position %zd: %U";
59128
f5ea1264b7ae Merged revisions 78437 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 59111
diff changeset
1763 result = PyUnicode_FromFormat(
41940
5014f8daa57f PyUnicode_FromFormat() does support %02x, so use it
Walter Dörwald <walter@livinglogic.de>
parents: 41882
diff changeset
1764 fmt,
73649
244d9159aa38 UnicodeTranslateError uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73644
diff changeset
1765 (int)badchar,
42110
e4f649c4f457 Merged revisions 55962-56019 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
1766 uself->start,
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1767 reason_str
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1768 );
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1769 } else {
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1770 result = PyUnicode_FromFormat(
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1771 "can't translate characters in position %zd-%zd: %U",
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1772 uself->start,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1773 uself->end-1,
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1774 reason_str
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1775 );
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1776 }
59111
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1777 done:
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1778 Py_XDECREF(reason_str);
c8ef906b11b8 Merged revisions 78420 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 54770
diff changeset
1779 return result;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1780 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1781
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1782 static PyTypeObject _PyExc_UnicodeTranslateError = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42305
diff changeset
1783 PyVarObject_HEAD_INIT(NULL, 0)
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
1784 "UnicodeTranslateError",
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1785 sizeof(PyUnicodeErrorObject), 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1786 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1787 (reprfunc)UnicodeTranslateError_str, 0, 0, 0,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1788 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1789 PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1790 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1791 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1792 (initproc)UnicodeTranslateError_init, 0, BaseException_new,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1793 };
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1794 PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1795
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1796 /* Deprecated. */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1797 PyObject *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1798 PyUnicodeTranslateError_Create(
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1799 const Py_UNICODE *object, Py_ssize_t length,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1800 Py_ssize_t start, Py_ssize_t end, const char *reason)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1801 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1802 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns",
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1803 object, length, start, end, reason);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1804 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1805
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1806 PyObject *
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1807 _PyUnicodeTranslateError_Create(
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1808 PyObject *object,
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1809 Py_ssize_t start, Py_ssize_t end, const char *reason)
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1810 {
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1811 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "Ons",
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1812 object, start, end, reason);
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 70403
diff changeset
1813 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1814
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1815 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1816 * AssertionError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1817 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1818 SimpleExtendsException(PyExc_Exception, AssertionError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1819 "Assertion failed.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1820
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1821
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1822 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1823 * ArithmeticError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1824 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1825 SimpleExtendsException(PyExc_Exception, ArithmeticError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1826 "Base class for arithmetic errors.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1827
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1828
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1829 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1830 * FloatingPointError extends ArithmeticError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1831 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1832 SimpleExtendsException(PyExc_ArithmeticError, FloatingPointError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1833 "Floating point operation failed.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1834
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1835
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1836 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1837 * OverflowError extends ArithmeticError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1838 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1839 SimpleExtendsException(PyExc_ArithmeticError, OverflowError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1840 "Result too large to be represented.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1841
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1842
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1843 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1844 * ZeroDivisionError extends ArithmeticError
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1845 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1846 SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1847 "Second argument to a division or modulo operation was zero.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1848
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1849
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1850 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1851 * SystemError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1852 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1853 SimpleExtendsException(PyExc_Exception, SystemError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1854 "Internal error in the Python interpreter.\n"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1855 "\n"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1856 "Please report this to the Python maintainer, along with the traceback,\n"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1857 "the Python version, and the hardware/OS platform and version.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1858
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1859
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1860 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1861 * ReferenceError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1862 */
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1863 SimpleExtendsException(PyExc_Exception, ReferenceError,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1864 "Weak ref proxy used after referent went away.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1865
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1866
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1867 /*
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41940
diff changeset
1868 * MemoryError extends Exception
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1869 */
65690
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1870
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1871 #define MEMERRORS_SAVE 16
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1872 static PyBaseExceptionObject *memerrors_freelist = NULL;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1873 static int memerrors_numfree = 0;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1874
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1875 static PyObject *
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1876 MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1877 {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1878 PyBaseExceptionObject *self;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1879
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1880 if (type != (PyTypeObject *) PyExc_MemoryError)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1881 return BaseException_new(type, args, kwds);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1882 if (memerrors_freelist == NULL)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1883 return BaseException_new(type, args, kwds);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1884 /* Fetch object from freelist and revive it */
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1885 self = memerrors_freelist;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1886 self->args = PyTuple_New(0);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1887 /* This shouldn't happen since the empty tuple is persistent */
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1888 if (self->args == NULL)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1889 return NULL;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1890 memerrors_freelist = (PyBaseExceptionObject *) self->dict;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1891 memerrors_numfree--;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1892 self->dict = NULL;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1893 _Py_NewReference((PyObject *)self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1894 _PyObject_GC_TRACK(self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1895 return (PyObject *)self;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1896 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1897
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1898 static void
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1899 MemoryError_dealloc(PyBaseExceptionObject *self)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1900 {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1901 _PyObject_GC_UNTRACK(self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1902 BaseException_clear(self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1903 if (memerrors_numfree >= MEMERRORS_SAVE)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1904 Py_TYPE(self)->tp_free((PyObject *)self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1905 else {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1906 self->dict = (PyObject *) memerrors_freelist;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1907 memerrors_freelist = self;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1908 memerrors_numfree++;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1909 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1910 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1911
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1912 static void
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1913 preallocate_memerrors(void)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1914 {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1915 /* We create enough MemoryErrors and then decref them, which will fill
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1916 up the freelist. */
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1917 int i;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1918 PyObject *errors[MEMERRORS_SAVE];
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1919 for (i = 0; i < MEMERRORS_SAVE; i++) {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1920 errors[i] = MemoryError_new((PyTypeObject *) PyExc_MemoryError,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1921 NULL, NULL);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1922 if (!errors[i])
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1923 Py_FatalError("Could not preallocate MemoryError object");
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1924 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1925 for (i = 0; i < MEMERRORS_SAVE; i++) {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1926 Py_DECREF(errors[i]);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1927 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1928 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1929
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1930 static void
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1931 free_preallocated_memerrors(void)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1932 {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1933 while (memerrors_freelist != NULL) {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1934 PyObject *self = (PyObject *) memerrors_freelist;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1935 memerrors_freelist = (PyBaseExceptionObject *) memerrors_freelist->dict;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1936 Py_TYPE(self)->tp_free((PyObject *)self);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1937 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1938 }
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1939
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1940
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1941 static PyTypeObject _PyExc_MemoryError = {
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1942 PyVarObject_HEAD_INIT(NULL, 0)
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1943 "MemoryError",
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1944 sizeof(PyBaseExceptionObject),
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1945 0, (destructor)MemoryError_dealloc, 0, 0, 0, 0, 0, 0, 0,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1946 0, 0, 0, 0, 0, 0, 0,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1947 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1948 PyDoc_STR("Out of memory."), (traverseproc)BaseException_traverse,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1949 (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_PyExc_Exception,
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1950 0, 0, 0, offsetof(PyBaseExceptionObject, dict),
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1951 (initproc)BaseException_init, 0, MemoryError_new
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1952 };
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1953 PyObject *PyExc_MemoryError = (PyObject *) &_PyExc_MemoryError;
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
1954
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1955
42665
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42334
diff changeset
1956 /*
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42334
diff changeset
1957 * BufferError extends Exception
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42334
diff changeset
1958 */
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42334
diff changeset
1959 SimpleExtendsException(PyExc_Exception, BufferError, "Buffer error.");
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42334
diff changeset
1960
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1961
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1962 /* Warning category docstrings */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1963
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1964 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1965 * Warning extends Exception
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1966 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1967 SimpleExtendsException(PyExc_Exception, Warning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1968 "Base class for warning categories.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1969
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1970
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1971 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1972 * UserWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1973 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1974 SimpleExtendsException(PyExc_Warning, UserWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1975 "Base class for warnings generated by user code.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1976
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1977
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1978 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1979 * DeprecationWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1980 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1981 SimpleExtendsException(PyExc_Warning, DeprecationWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1982 "Base class for warnings about deprecated features.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1983
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1984
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1985 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1986 * PendingDeprecationWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1987 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1988 SimpleExtendsException(PyExc_Warning, PendingDeprecationWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1989 "Base class for warnings about features which will be deprecated\n"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1990 "in the future.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1991
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1992
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1993 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1994 * SyntaxWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1995 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1996 SimpleExtendsException(PyExc_Warning, SyntaxWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1997 "Base class for warnings about dubious syntax.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1998
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1999
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2000 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2001 * RuntimeWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2002 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2003 SimpleExtendsException(PyExc_Warning, RuntimeWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2004 "Base class for warnings about dubious runtime behavior.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2005
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2006
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2007 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2008 * FutureWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2009 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2010 SimpleExtendsException(PyExc_Warning, FutureWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2011 "Base class for warnings about constructs that will change semantically\n"
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2012 "in the future.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2013
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2014
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2015 /*
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2016 * ImportWarning extends Warning
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2017 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2018 SimpleExtendsException(PyExc_Warning, ImportWarning,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2019 "Base class for warnings about probable mistakes in module imports");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2020
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2021
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2022 /*
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2023 * UnicodeWarning extends Warning
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2024 */
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2025 SimpleExtendsException(PyExc_Warning, UnicodeWarning,
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2026 "Base class for warnings about Unicode related problems, mostly\n"
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2027 "related to conversion problems.");
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2028
65624
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2029
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2030 /*
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2031 * BytesWarning extends Warning
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2032 */
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2033 SimpleExtendsException(PyExc_Warning, BytesWarning,
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2034 "Base class for warnings about bytes and buffer related problems, mostly\n"
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2035 "related to conversion from str or comparing to str.");
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2036
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2037
65624
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2038 /*
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2039 * ResourceWarning extends Warning
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2040 */
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2041 SimpleExtendsException(PyExc_Warning, ResourceWarning,
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2042 "Base class for warnings about resource usage.");
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2043
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2044
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2045
43292
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2046 /* Pre-computed RuntimeError instance for when recursion depth is reached.
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2047 Meant to be used when normalizing the exception for exceeding the recursion
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2048 depth will cause its own infinite recursion.
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2049 */
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2050 PyObject *PyExc_RecursionErrorInst = NULL;
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2051
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2052 #define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2053 Py_FatalError("exceptions bootstrapping error.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2054
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2055 #define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2056 if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2057 Py_FatalError("Module dictionary insertion problem.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2058
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2059 #define INIT_ALIAS(NAME, TYPE) Py_INCREF(PyExc_ ## TYPE); \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2060 PyExc_ ## NAME = PyExc_ ## TYPE; \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2061 if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2062 Py_FatalError("Module dictionary insertion problem.");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2063
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2064 #define ADD_ERRNO(TYPE, CODE) { \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2065 PyObject *_code = PyLong_FromLong(CODE); \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2066 assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2067 if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2068 Py_FatalError("errmap insertion problem."); \
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2069 }
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2070
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2071 #ifdef MS_WINDOWS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2072 #include <Winsock2.h>
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2073 #if defined(WSAEALREADY) && !defined(EALREADY)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2074 #define EALREADY WSAEALREADY
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2075 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2076 #if defined(WSAECONNABORTED) && !defined(ECONNABORTED)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2077 #define ECONNABORTED WSAECONNABORTED
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2078 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2079 #if defined(WSAECONNREFUSED) && !defined(ECONNREFUSED)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2080 #define ECONNREFUSED WSAECONNREFUSED
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2081 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2082 #if defined(WSAECONNRESET) && !defined(ECONNRESET)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2083 #define ECONNRESET WSAECONNRESET
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2084 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2085 #if defined(WSAEINPROGRESS) && !defined(EINPROGRESS)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2086 #define EINPROGRESS WSAEINPROGRESS
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2087 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2088 #if defined(WSAESHUTDOWN) && !defined(ESHUTDOWN)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2089 #define ESHUTDOWN WSAESHUTDOWN
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2090 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2091 #if defined(WSAETIMEDOUT) && !defined(ETIMEDOUT)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2092 #define ETIMEDOUT WSAETIMEDOUT
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2093 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2094 #if defined(WSAEWOULDBLOCK) && !defined(EWOULDBLOCK)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2095 #define EWOULDBLOCK WSAEWOULDBLOCK
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2096 #endif
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2097 #endif /* MS_WINDOWS */
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2098
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
2099 void
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
2100 _PyExc_Init(void)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2101 {
40949
e759fd8d95ae Remove the exceptions builtin module, all the exceptions are already builtin.
Neal Norwitz <nnorwitz@gmail.com>
parents: 40909
diff changeset
2102 PyObject *bltinmod, *bdict;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2103
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2104 PRE_INIT(BaseException)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2105 PRE_INIT(Exception)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2106 PRE_INIT(TypeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2107 PRE_INIT(StopIteration)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2108 PRE_INIT(GeneratorExit)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2109 PRE_INIT(SystemExit)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2110 PRE_INIT(KeyboardInterrupt)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2111 PRE_INIT(ImportError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2112 PRE_INIT(OSError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2113 PRE_INIT(EOFError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2114 PRE_INIT(RuntimeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2115 PRE_INIT(NotImplementedError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2116 PRE_INIT(NameError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2117 PRE_INIT(UnboundLocalError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2118 PRE_INIT(AttributeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2119 PRE_INIT(SyntaxError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2120 PRE_INIT(IndentationError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2121 PRE_INIT(TabError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2122 PRE_INIT(LookupError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2123 PRE_INIT(IndexError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2124 PRE_INIT(KeyError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2125 PRE_INIT(ValueError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2126 PRE_INIT(UnicodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2127 PRE_INIT(UnicodeEncodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2128 PRE_INIT(UnicodeDecodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2129 PRE_INIT(UnicodeTranslateError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2130 PRE_INIT(AssertionError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2131 PRE_INIT(ArithmeticError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2132 PRE_INIT(FloatingPointError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2133 PRE_INIT(OverflowError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2134 PRE_INIT(ZeroDivisionError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2135 PRE_INIT(SystemError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2136 PRE_INIT(ReferenceError)
42669
2c51be9904de Code review of the new buffer protocol. Mostly add questions that should
Neal Norwitz <nnorwitz@gmail.com>
parents: 42665
diff changeset
2137 PRE_INIT(BufferError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2138 PRE_INIT(MemoryError)
48437
fa34088380f9 #3295 actually define PyExc_BufferError
Benjamin Peterson <benjamin@python.org>
parents: 47580
diff changeset
2139 PRE_INIT(BufferError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2140 PRE_INIT(Warning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2141 PRE_INIT(UserWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2142 PRE_INIT(DeprecationWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2143 PRE_INIT(PendingDeprecationWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2144 PRE_INIT(SyntaxWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2145 PRE_INIT(RuntimeWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2146 PRE_INIT(FutureWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2147 PRE_INIT(ImportWarning)
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2148 PRE_INIT(UnicodeWarning)
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2149 PRE_INIT(BytesWarning)
65624
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2150 PRE_INIT(ResourceWarning)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2151
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2152 /* OSError subclasses */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2153 PRE_INIT(ConnectionError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2154
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2155 PRE_INIT(BlockingIOError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2156 PRE_INIT(BrokenPipeError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2157 PRE_INIT(ChildProcessError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2158 PRE_INIT(ConnectionAbortedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2159 PRE_INIT(ConnectionRefusedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2160 PRE_INIT(ConnectionResetError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2161 PRE_INIT(FileExistsError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2162 PRE_INIT(FileNotFoundError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2163 PRE_INIT(IsADirectoryError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2164 PRE_INIT(NotADirectoryError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2165 PRE_INIT(InterruptedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2166 PRE_INIT(PermissionError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2167 PRE_INIT(ProcessLookupError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2168 PRE_INIT(TimeoutError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2169
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 43866
diff changeset
2170 bltinmod = PyImport_ImportModule("builtins");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2171 if (bltinmod == NULL)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2172 Py_FatalError("exceptions bootstrapping error.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2173 bdict = PyModule_GetDict(bltinmod);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2174 if (bdict == NULL)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2175 Py_FatalError("exceptions bootstrapping error.");
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2176
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2177 POST_INIT(BaseException)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2178 POST_INIT(Exception)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2179 POST_INIT(TypeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2180 POST_INIT(StopIteration)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2181 POST_INIT(GeneratorExit)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2182 POST_INIT(SystemExit)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2183 POST_INIT(KeyboardInterrupt)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2184 POST_INIT(ImportError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2185 POST_INIT(OSError)
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2186 INIT_ALIAS(EnvironmentError, OSError)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2187 INIT_ALIAS(IOError, OSError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2188 #ifdef MS_WINDOWS
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2189 INIT_ALIAS(WindowsError, OSError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2190 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2191 #ifdef __VMS
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2192 INIT_ALIAS(VMSError, OSError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2193 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2194 POST_INIT(EOFError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2195 POST_INIT(RuntimeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2196 POST_INIT(NotImplementedError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2197 POST_INIT(NameError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2198 POST_INIT(UnboundLocalError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2199 POST_INIT(AttributeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2200 POST_INIT(SyntaxError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2201 POST_INIT(IndentationError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2202 POST_INIT(TabError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2203 POST_INIT(LookupError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2204 POST_INIT(IndexError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2205 POST_INIT(KeyError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2206 POST_INIT(ValueError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2207 POST_INIT(UnicodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2208 POST_INIT(UnicodeEncodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2209 POST_INIT(UnicodeDecodeError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2210 POST_INIT(UnicodeTranslateError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2211 POST_INIT(AssertionError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2212 POST_INIT(ArithmeticError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2213 POST_INIT(FloatingPointError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2214 POST_INIT(OverflowError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2215 POST_INIT(ZeroDivisionError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2216 POST_INIT(SystemError)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2217 POST_INIT(ReferenceError)
42669
2c51be9904de Code review of the new buffer protocol. Mostly add questions that should
Neal Norwitz <nnorwitz@gmail.com>
parents: 42665
diff changeset
2218 POST_INIT(BufferError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2219 POST_INIT(MemoryError)
48437
fa34088380f9 #3295 actually define PyExc_BufferError
Benjamin Peterson <benjamin@python.org>
parents: 47580
diff changeset
2220 POST_INIT(BufferError)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2221 POST_INIT(Warning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2222 POST_INIT(UserWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2223 POST_INIT(DeprecationWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2224 POST_INIT(PendingDeprecationWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2225 POST_INIT(SyntaxWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2226 POST_INIT(RuntimeWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2227 POST_INIT(FutureWarning)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2228 POST_INIT(ImportWarning)
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2229 POST_INIT(UnicodeWarning)
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43696
diff changeset
2230 POST_INIT(BytesWarning)
65624
39b9e9de372b Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
Georg Brandl <georg@python.org>
parents: 62443
diff changeset
2231 POST_INIT(ResourceWarning)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2232
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2233 errnomap = PyDict_New();
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2234 if (!errnomap)
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2235 Py_FatalError("Cannot allocate map from errnos to OSError subclasses");
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2236
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2237 /* OSError subclasses */
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2238 POST_INIT(ConnectionError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2239
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2240 POST_INIT(BlockingIOError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2241 ADD_ERRNO(BlockingIOError, EAGAIN);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2242 ADD_ERRNO(BlockingIOError, EALREADY);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2243 ADD_ERRNO(BlockingIOError, EINPROGRESS);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2244 ADD_ERRNO(BlockingIOError, EWOULDBLOCK);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2245 POST_INIT(BrokenPipeError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2246 ADD_ERRNO(BrokenPipeError, EPIPE);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2247 ADD_ERRNO(BrokenPipeError, ESHUTDOWN);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2248 POST_INIT(ChildProcessError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2249 ADD_ERRNO(ChildProcessError, ECHILD);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2250 POST_INIT(ConnectionAbortedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2251 ADD_ERRNO(ConnectionAbortedError, ECONNABORTED);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2252 POST_INIT(ConnectionRefusedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2253 ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2254 POST_INIT(ConnectionResetError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2255 ADD_ERRNO(ConnectionResetError, ECONNRESET);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2256 POST_INIT(FileExistsError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2257 ADD_ERRNO(FileExistsError, EEXIST);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2258 POST_INIT(FileNotFoundError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2259 ADD_ERRNO(FileNotFoundError, ENOENT);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2260 POST_INIT(IsADirectoryError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2261 ADD_ERRNO(IsADirectoryError, EISDIR);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2262 POST_INIT(NotADirectoryError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2263 ADD_ERRNO(NotADirectoryError, ENOTDIR);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2264 POST_INIT(InterruptedError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2265 ADD_ERRNO(InterruptedError, EINTR);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2266 POST_INIT(PermissionError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2267 ADD_ERRNO(PermissionError, EACCES);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2268 ADD_ERRNO(PermissionError, EPERM);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2269 POST_INIT(ProcessLookupError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2270 ADD_ERRNO(ProcessLookupError, ESRCH);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2271 POST_INIT(TimeoutError);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2272 ADD_ERRNO(TimeoutError, ETIMEDOUT);
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2273
65690
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
2274 preallocate_memerrors();
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2275
43292
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2276 PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2277 if (!PyExc_RecursionErrorInst)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2278 Py_FatalError("Cannot pre-allocate RuntimeError instance for "
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2279 "recursion errors");
43292
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2280 else {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2281 PyBaseExceptionObject *err_inst =
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2282 (PyBaseExceptionObject *)PyExc_RecursionErrorInst;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2283 PyObject *args_tuple;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2284 PyObject *exc_message;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2285 exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2286 if (!exc_message)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2287 Py_FatalError("cannot allocate argument for RuntimeError "
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2288 "pre-allocation");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2289 args_tuple = PyTuple_Pack(1, exc_message);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2290 if (!args_tuple)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2291 Py_FatalError("cannot allocate tuple for RuntimeError "
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2292 "pre-allocation");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2293 Py_DECREF(exc_message);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2294 if (BaseException_init(err_inst, args_tuple, NULL))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2295 Py_FatalError("init of pre-allocated RuntimeError failed");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 59128
diff changeset
2296 Py_DECREF(args_tuple);
43292
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2297 }
876b7ef4775d Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2298
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2299 Py_DECREF(bltinmod);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2300 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2301
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2302 void
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2303 _PyExc_Fini(void)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2304 {
65690
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
2305 Py_CLEAR(PyExc_RecursionErrorInst);
c6d86439aa91 Merged revisions 85896 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 62448
diff changeset
2306 free_preallocated_memerrors();
72879
41a1de81ef2b PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72703
diff changeset
2307 Py_CLEAR(errnomap);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2308 }