Mercurial > cpython-lru_cache-weakref
annotate Objects/exceptions.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 86387b8b9af8 |
| children | 2b82b16a6375 |
| rev | line source |
|---|---|
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1 /* |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
2 * New exceptions.c written in Iceland by Richard Jones and Georg Brandl. |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
3 * |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
4 * Thanks go to Tim Peters and Michael Hudson for debugging. |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
5 */ |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
6 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
7 #define PY_SSIZE_T_CLEAN |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
8 #include <Python.h> |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
9 #include "structmember.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
10 #include "osdefs.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
11 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
12 #define EXC_MODULE_NAME "exceptions." |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
13 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
14 /* NOTE: If the exception class hierarchy changes, don't forget to update |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
15 * Lib/test/exception_hierarchy.txt |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
16 */ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
17 |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
18 PyDoc_STRVAR(exceptions_doc, "Python's standard exception class hierarchy.\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
19 \n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
20 Exceptions found here are defined both in the exceptions module and the\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
21 built-in namespace. It is recommended that user-defined exceptions\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
22 inherit from Exception. See the documentation for the exception\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
23 inheritance hierarchy.\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
24 "); |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
25 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
26 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
27 * BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
28 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
29 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
30 BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
31 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
32 PyBaseExceptionObject *self; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
33 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
34 self = (PyBaseExceptionObject *)type->tp_alloc(type, 0); |
|
41435
46d0f4057705
Add some missing NULL checks which trigger crashes on low-memory conditions.
Georg Brandl <georg@python.org>
parents:
40908
diff
changeset
|
35 if (!self) |
|
46d0f4057705
Add some missing NULL checks which trigger crashes on low-memory conditions.
Georg Brandl <georg@python.org>
parents:
40908
diff
changeset
|
36 return NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
37 /* the dict is created on the fly in PyObject_GenericSetAttr */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
38 self->message = self->dict = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
39 |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
40 self->args = PyTuple_New(0); |
|
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
41 if (!self->args) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
42 Py_DECREF(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
43 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
44 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
45 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
46 self->message = PyString_FromString(""); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
47 if (!self->message) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
48 Py_DECREF(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
49 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
50 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
51 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
52 return (PyObject *)self; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
53 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
54 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
55 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
56 BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
57 { |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
58 if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) |
|
38510
13fedd0d0f26
Do the check for no keyword arguments in __init__ so that
Georg Brandl <georg@python.org>
parents:
38508
diff
changeset
|
59 return -1; |
|
13fedd0d0f26
Do the check for no keyword arguments in __init__ so that
Georg Brandl <georg@python.org>
parents:
38508
diff
changeset
|
60 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
61 Py_DECREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
62 self->args = args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
63 Py_INCREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
64 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
65 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
66 Py_CLEAR(self->message); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
67 self->message = PyTuple_GET_ITEM(self->args, 0); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
68 Py_INCREF(self->message); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
69 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
70 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
71 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
72 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
73 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
74 BaseException_clear(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
75 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
76 Py_CLEAR(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
77 Py_CLEAR(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
78 Py_CLEAR(self->message); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
79 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
80 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
81 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
82 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
83 BaseException_dealloc(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
84 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
85 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
86 BaseException_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
87 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
88 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
89 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
90 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
91 BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
92 { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
93 Py_VISIT(self->dict); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
94 Py_VISIT(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
95 Py_VISIT(self->message); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
96 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
97 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
98 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
99 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
100 BaseException_str(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
101 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
102 PyObject *out; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
103 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
104 switch (PyTuple_GET_SIZE(self->args)) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
105 case 0: |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
106 out = PyString_FromString(""); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
107 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
108 case 1: |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
109 out = PyObject_Str(PyTuple_GET_ITEM(self->args, 0)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
110 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
111 default: |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
112 out = PyObject_Str(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
113 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
114 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
115 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
116 return out; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
117 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
118 |
|
47914
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
119 #ifdef Py_USING_UNICODE |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
120 static PyObject * |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
121 BaseException_unicode(PyBaseExceptionObject *self) |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
122 { |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
123 PyObject *out; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
124 |
|
57927
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
125 /* issue6108: if __str__ has been overridden in the subclass, unicode() |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
126 should return the message returned by __str__ as used to happen |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
127 before this method was implemented. */ |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
128 if (Py_TYPE(self)->tp_str != (reprfunc)BaseException_str) { |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
129 PyObject *str; |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
130 /* Unlike PyObject_Str, tp_str can return unicode (i.e. return the |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
131 equivalent of unicode(e.__str__()) instead of unicode(str(e))). */ |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
132 str = Py_TYPE(self)->tp_str((PyObject*)self); |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
133 if (str == NULL) |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
134 return NULL; |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
135 out = PyObject_Unicode(str); |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
136 Py_DECREF(str); |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
137 return out; |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
138 } |
|
86387b8b9af8
#6108: unicode(exception) and str(exception) should return the same message
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56011
diff
changeset
|
139 |
|
47914
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
140 switch (PyTuple_GET_SIZE(self->args)) { |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
141 case 0: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
142 out = PyUnicode_FromString(""); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
143 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
144 case 1: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
145 out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0)); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
146 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
147 default: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
148 out = PyObject_Unicode(self->args); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
149 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
150 } |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
151 |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
152 return out; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
153 } |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
154 #endif |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
155 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
156 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
157 BaseException_repr(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
158 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
159 PyObject *repr_suffix; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
160 PyObject *repr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
161 char *name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
162 char *dot; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
163 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
164 repr_suffix = PyObject_Repr(self->args); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
165 if (!repr_suffix) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
166 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
167 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
168 name = (char *)Py_TYPE(self)->tp_name; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
169 dot = strrchr(name, '.'); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
170 if (dot != NULL) name = dot+1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
171 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
172 repr = PyString_FromString(name); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
173 if (!repr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
174 Py_DECREF(repr_suffix); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
175 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
176 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
177 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
178 PyString_ConcatAndDel(&repr, repr_suffix); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
179 return repr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
180 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
181 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
182 /* Pickling support */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
183 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
184 BaseException_reduce(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
185 { |
|
38505
4f8586946c8f
Restore exception pickle support. #1497319.
Georg Brandl <georg@python.org>
parents:
38476
diff
changeset
|
186 if (self->args && self->dict) |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
187 return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
188 else |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
189 return PyTuple_Pack(2, Py_TYPE(self), self->args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
190 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
191 |
|
38532
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
192 /* |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
193 * Needed for backward compatibility, since exceptions used to store |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
194 * all their attributes in the __dict__. Code is taken from cPickle's |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
195 * load_build function. |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
196 */ |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
197 static PyObject * |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
198 BaseException_setstate(PyObject *self, PyObject *state) |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
199 { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
200 PyObject *d_key, *d_value; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
201 Py_ssize_t i = 0; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
202 |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
203 if (state != Py_None) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
204 if (!PyDict_Check(state)) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
205 PyErr_SetString(PyExc_TypeError, "state is not a dictionary"); |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
206 return NULL; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
207 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
208 while (PyDict_Next(state, &i, &d_key, &d_value)) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
209 if (PyObject_SetAttr(self, d_key, d_value) < 0) |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
210 return NULL; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
211 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
212 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
213 Py_RETURN_NONE; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
214 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
215 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
216 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
217 static PyMethodDef BaseException_methods[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
218 {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS }, |
|
38532
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
219 {"__setstate__", (PyCFunction)BaseException_setstate, METH_O }, |
|
47914
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
220 #ifdef Py_USING_UNICODE |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
221 {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS }, |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
222 #endif |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
223 {NULL, NULL, 0, NULL}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
224 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
225 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
226 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
227 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
228 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
229 BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
230 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
231 if (PyErr_WarnPy3k("__getitem__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
232 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
233 return NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
234 return PySequence_GetItem(self->args, index); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
235 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
236 |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
237 static PyObject * |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
238 BaseException_getslice(PyBaseExceptionObject *self, |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
239 Py_ssize_t start, Py_ssize_t stop) |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
240 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
241 if (PyErr_WarnPy3k("__getslice__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
242 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
243 return NULL; |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
244 return PySequence_GetSlice(self->args, start, stop); |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
245 } |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
246 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
247 static PySequenceMethods BaseException_as_sequence = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
248 0, /* sq_length; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
249 0, /* sq_concat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
250 0, /* sq_repeat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
251 (ssizeargfunc)BaseException_getitem, /* sq_item; */ |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
252 (ssizessizeargfunc)BaseException_getslice, /* sq_slice; */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
253 0, /* sq_ass_item; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
254 0, /* sq_ass_slice; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
255 0, /* sq_contains; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
256 0, /* sq_inplace_concat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
257 0 /* sq_inplace_repeat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
258 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
259 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
260 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
261 BaseException_get_dict(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
262 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
263 if (self->dict == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
264 self->dict = PyDict_New(); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
265 if (!self->dict) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
266 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
267 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
268 Py_INCREF(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
269 return self->dict; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
270 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
271 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
272 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
273 BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
274 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
275 if (val == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
276 PyErr_SetString(PyExc_TypeError, "__dict__ may not be deleted"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
277 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
278 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
279 if (!PyDict_Check(val)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
280 PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
281 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
282 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
283 Py_CLEAR(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
284 Py_INCREF(val); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
285 self->dict = val; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
286 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
287 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
288 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
289 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
290 BaseException_get_args(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
291 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
292 if (self->args == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
293 Py_INCREF(Py_None); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
294 return Py_None; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
295 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
296 Py_INCREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
297 return self->args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
298 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
299 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
300 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
301 BaseException_set_args(PyBaseExceptionObject *self, PyObject *val) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
302 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
303 PyObject *seq; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
304 if (val == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
305 PyErr_SetString(PyExc_TypeError, "args may not be deleted"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
306 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
307 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
308 seq = PySequence_Tuple(val); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
309 if (!seq) return -1; |
|
38476
d3383063491f
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Georg Brandl <georg@python.org>
parents:
38469
diff
changeset
|
310 Py_CLEAR(self->args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
311 self->args = seq; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
312 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
313 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
314 |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
315 static PyObject * |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
316 BaseException_get_message(PyBaseExceptionObject *self) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
317 { |
|
56011
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
318 PyObject *msg; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
319 |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
320 /* if "message" is in self->dict, accessing a user-set message attribute */ |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
321 if (self->dict && |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
322 (msg = PyDict_GetItemString(self->dict, "message"))) { |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
323 Py_INCREF(msg); |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
324 return msg; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
325 } |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
326 |
|
56011
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
327 if (self->message == NULL) { |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
328 PyErr_SetString(PyExc_AttributeError, "message attribute was deleted"); |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
329 return NULL; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
330 } |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
331 |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
332 /* accessing the deprecated "builtin" message attribute of Exception */ |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
333 if (PyErr_WarnEx(PyExc_DeprecationWarning, |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
334 "BaseException.message has been deprecated as " |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
335 "of Python 2.6", 1) < 0) |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
336 return NULL; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
337 |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
338 Py_INCREF(self->message); |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
339 return self->message; |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
340 } |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
341 |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
342 static int |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
343 BaseException_set_message(PyBaseExceptionObject *self, PyObject *val) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
344 { |
|
56011
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
345 /* if val is NULL, delete the message attribute */ |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
346 if (val == NULL) { |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
347 if (self->dict && PyDict_GetItemString(self->dict, "message")) { |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
348 if (PyDict_DelItemString(self->dict, "message") < 0) |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
349 return -1; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
350 } |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
351 Py_XDECREF(self->message); |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
352 self->message = NULL; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
353 return 0; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
354 } |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
355 |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
356 /* else set it in __dict__, but may need to create the dict first */ |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
357 if (self->dict == NULL) { |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
358 self->dict = PyDict_New(); |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
359 if (!self->dict) |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
360 return -1; |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
361 } |
|
0f09d38f852e
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
Georg Brandl <georg@python.org>
parents:
54768
diff
changeset
|
362 return PyDict_SetItemString(self->dict, "message", val); |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
363 } |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
364 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
365 static PyGetSetDef BaseException_getset[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
366 {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
367 {"args", (getter)BaseException_get_args, (setter)BaseException_set_args}, |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
368 {"message", (getter)BaseException_get_message, |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
369 (setter)BaseException_set_message}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
370 {NULL}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
371 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
372 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
373 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
374 static PyTypeObject _PyExc_BaseException = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
375 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
376 0, /*ob_size*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
377 EXC_MODULE_NAME "BaseException", /*tp_name*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
378 sizeof(PyBaseExceptionObject), /*tp_basicsize*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
379 0, /*tp_itemsize*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
380 (destructor)BaseException_dealloc, /*tp_dealloc*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
381 0, /*tp_print*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
382 0, /*tp_getattr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
383 0, /*tp_setattr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
384 0, /* tp_compare; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
385 (reprfunc)BaseException_repr, /*tp_repr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
386 0, /*tp_as_number*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
387 &BaseException_as_sequence, /*tp_as_sequence*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
388 0, /*tp_as_mapping*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
389 0, /*tp_hash */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
390 0, /*tp_call*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
391 (reprfunc)BaseException_str, /*tp_str*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
392 PyObject_GenericGetAttr, /*tp_getattro*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
393 PyObject_GenericSetAttr, /*tp_setattro*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
394 0, /*tp_as_buffer*/ |
|
40908
d01bd37bf5ce
Variation of patch # 1624059 to speed up checking if an object is a subclass
Neal Norwitz <nnorwitz@gmail.com>
parents:
40209
diff
changeset
|
395 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | |
|
d01bd37bf5ce
Variation of patch # 1624059 to speed up checking if an object is a subclass
Neal Norwitz <nnorwitz@gmail.com>
parents:
40209
diff
changeset
|
396 Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
397 PyDoc_STR("Common base class for all exceptions"), /* tp_doc */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
398 (traverseproc)BaseException_traverse, /* tp_traverse */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
399 (inquiry)BaseException_clear, /* tp_clear */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
400 0, /* tp_richcompare */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
401 0, /* tp_weaklistoffset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
402 0, /* tp_iter */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
403 0, /* tp_iternext */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
404 BaseException_methods, /* tp_methods */ |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
405 0, /* tp_members */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
406 BaseException_getset, /* tp_getset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
407 0, /* tp_base */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
408 0, /* tp_dict */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
409 0, /* tp_descr_get */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
410 0, /* tp_descr_set */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
411 offsetof(PyBaseExceptionObject, dict), /* tp_dictoffset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
412 (initproc)BaseException_init, /* tp_init */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
413 0, /* tp_alloc */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
414 BaseException_new, /* tp_new */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
415 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
416 /* the CPython API expects exceptions to be (PyObject *) - both a hold-over |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
417 from the previous implmentation and also allowing Python objects to be used |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
418 in the API */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
419 PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
420 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
421 /* note these macros omit the last semicolon so the macro invocation may |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
422 * include it and not look strange. |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
423 */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
424 #define SimpleExtendsException(EXCBASE, EXCNAME, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
425 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
426 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
427 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
428 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
429 sizeof(PyBaseExceptionObject), \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
430 0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
431 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
432 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
433 PyDoc_STR(EXCDOC), (traverseproc)BaseException_traverse, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
434 (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
435 0, 0, 0, offsetof(PyBaseExceptionObject, dict), \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
436 (initproc)BaseException_init, 0, BaseException_new,\ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
437 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
438 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
439 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
440 #define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
441 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
442 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
443 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
444 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
445 sizeof(Py ## EXCSTORE ## Object), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
446 0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
447 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
448 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
449 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
450 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
451 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
452 (initproc)EXCSTORE ## _init, 0, BaseException_new,\ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
453 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
454 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
455 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
456 #define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDEALLOC, EXCMETHODS, EXCMEMBERS, EXCSTR, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
457 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
458 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
459 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
460 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
461 sizeof(Py ## EXCSTORE ## Object), 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
462 (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
463 (reprfunc)EXCSTR, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
464 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
465 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
466 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
467 EXCMEMBERS, 0, &_ ## EXCBASE, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
468 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
469 (initproc)EXCSTORE ## _init, 0, BaseException_new,\ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
470 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
471 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
472 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
473 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
474 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
475 * Exception extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
476 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
477 SimpleExtendsException(PyExc_BaseException, Exception, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
478 "Common base class for all non-exit exceptions."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
479 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
480 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
481 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
482 * StandardError extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
483 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
484 SimpleExtendsException(PyExc_Exception, StandardError, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
485 "Base class for all standard Python exceptions that do not represent\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
486 "interpreter exiting."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
487 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
488 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
489 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
490 * TypeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
491 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
492 SimpleExtendsException(PyExc_StandardError, TypeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
493 "Inappropriate argument type."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
494 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
495 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
496 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
497 * StopIteration extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
498 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
499 SimpleExtendsException(PyExc_Exception, StopIteration, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
500 "Signal the end from iterator.next()."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
501 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
502 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
503 /* |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
504 * GeneratorExit extends BaseException |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
505 */ |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
506 SimpleExtendsException(PyExc_BaseException, GeneratorExit, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
507 "Request that a generator exit."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
508 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
509 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
510 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
511 * SystemExit extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
512 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
513 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
514 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
515 SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
516 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
517 Py_ssize_t size = PyTuple_GET_SIZE(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
518 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
519 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
520 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
521 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
522 if (size == 0) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
523 return 0; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
524 Py_CLEAR(self->code); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
525 if (size == 1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
526 self->code = PyTuple_GET_ITEM(args, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
527 else if (size > 1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
528 self->code = args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
529 Py_INCREF(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
530 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
531 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
532 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
533 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
534 SystemExit_clear(PySystemExitObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
535 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
536 Py_CLEAR(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
537 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
538 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
539 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
540 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
541 SystemExit_dealloc(PySystemExitObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
542 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
543 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
544 SystemExit_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
545 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
546 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
547 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
548 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
549 SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
550 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
551 Py_VISIT(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
552 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
553 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
554 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
555 static PyMemberDef SystemExit_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
556 {"code", T_OBJECT, offsetof(PySystemExitObject, code), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
557 PyDoc_STR("exception code")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
558 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
559 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
560 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
561 ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
562 SystemExit_dealloc, 0, SystemExit_members, 0, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
563 "Request to exit from the interpreter."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
564 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
565 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
566 * KeyboardInterrupt extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
567 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
568 SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
569 "Program interrupted by user."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
570 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
571 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
572 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
573 * ImportError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
574 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
575 SimpleExtendsException(PyExc_StandardError, ImportError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
576 "Import can't find module, or can't find name in module."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
577 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
578 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
579 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
580 * EnvironmentError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
581 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
582 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
583 /* Where a function has a single filename, such as open() or some |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
584 * of the os module functions, PyErr_SetFromErrnoWithFilename() is |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
585 * called, giving a third argument which is the filename. But, so |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
586 * that old code using in-place unpacking doesn't break, e.g.: |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
587 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
588 * except IOError, (errno, strerror): |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
589 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
590 * we hack args so that it only contains two items. This also |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
591 * means we need our own __str__() which prints out the filename |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
592 * when it was supplied. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
593 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
594 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
595 EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
596 PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
597 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
598 PyObject *myerrno = NULL, *strerror = NULL, *filename = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
599 PyObject *subslice = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
600 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
601 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
602 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
603 |
|
39924
e1ab4653ebc0
Bug #1566800: make sure that EnvironmentError can be called with any
Georg Brandl <georg@python.org>
parents:
39863
diff
changeset
|
604 if (PyTuple_GET_SIZE(args) <= 1 || PyTuple_GET_SIZE(args) > 3) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
605 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
606 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
607 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
608 if (!PyArg_UnpackTuple(args, "EnvironmentError", 2, 3, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
609 &myerrno, &strerror, &filename)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
610 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
611 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
612 Py_CLEAR(self->myerrno); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
613 self->myerrno = myerrno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
614 Py_INCREF(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
615 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
616 Py_CLEAR(self->strerror); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
617 self->strerror = strerror; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
618 Py_INCREF(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
619 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
620 /* self->filename will remain Py_None otherwise */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
621 if (filename != NULL) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
622 Py_CLEAR(self->filename); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
623 self->filename = filename; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
624 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
625 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
626 subslice = PyTuple_GetSlice(args, 0, 2); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
627 if (!subslice) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
628 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
629 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
630 Py_DECREF(self->args); /* replacing args */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
631 self->args = subslice; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
632 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
633 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
634 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
635 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
636 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
637 EnvironmentError_clear(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
638 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
639 Py_CLEAR(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
640 Py_CLEAR(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
641 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
642 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
643 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
644 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
645 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
646 EnvironmentError_dealloc(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
647 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
648 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
649 EnvironmentError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
650 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
651 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
652 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
653 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
654 EnvironmentError_traverse(PyEnvironmentErrorObject *self, visitproc visit, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
655 void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
656 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
657 Py_VISIT(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
658 Py_VISIT(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
659 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
660 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
661 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
662 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
663 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
664 EnvironmentError_str(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
665 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
666 PyObject *rtnval = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
667 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
668 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
669 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
670 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
671 PyObject *tuple; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
672 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
673 fmt = PyString_FromString("[Errno %s] %s: %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
674 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
675 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
676 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
677 repr = PyObject_Repr(self->filename); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
678 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
679 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
680 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
681 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
682 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
683 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
684 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
685 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
686 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
687 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
688 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
689 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
690 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
691 PyTuple_SET_ITEM(tuple, 0, self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
692 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
693 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
694 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
695 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
696 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
697 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
698 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
699 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
700 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
701 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
702 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
703 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
704 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
705 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
706 PyTuple_SET_ITEM(tuple, 2, repr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
707 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
708 rtnval = PyString_Format(fmt, tuple); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
709 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
710 Py_DECREF(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
711 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
712 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
713 else if (self->myerrno && self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
714 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
715 PyObject *tuple; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
716 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
717 fmt = PyString_FromString("[Errno %s] %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
718 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
719 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
720 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
721 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
722 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
723 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
724 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
725 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
726 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
727 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
728 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
729 PyTuple_SET_ITEM(tuple, 0, self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
730 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
731 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
732 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
733 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
734 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
735 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
736 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
737 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
738 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
739 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
740 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
741 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
742 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
743 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
744 rtnval = PyString_Format(fmt, tuple); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
745 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
746 Py_DECREF(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
747 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
748 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
749 else |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
750 rtnval = BaseException_str((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
751 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
752 return rtnval; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
753 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
754 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
755 static PyMemberDef EnvironmentError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
756 {"errno", T_OBJECT, offsetof(PyEnvironmentErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
757 PyDoc_STR("exception errno")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
758 {"strerror", T_OBJECT, offsetof(PyEnvironmentErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
759 PyDoc_STR("exception strerror")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
760 {"filename", T_OBJECT, offsetof(PyEnvironmentErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
761 PyDoc_STR("exception filename")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
762 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
763 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
764 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
765 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
766 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
767 EnvironmentError_reduce(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
768 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
769 PyObject *args = self->args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
770 PyObject *res = NULL, *tmp; |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
771 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
772 /* self->args is only the first two real arguments if there was a |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
773 * file name given to EnvironmentError. */ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
774 if (PyTuple_GET_SIZE(args) == 2 && self->filename) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
775 args = PyTuple_New(3); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
776 if (!args) return NULL; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
777 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
778 tmp = PyTuple_GET_ITEM(self->args, 0); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
779 Py_INCREF(tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
780 PyTuple_SET_ITEM(args, 0, tmp); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
781 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
782 tmp = PyTuple_GET_ITEM(self->args, 1); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
783 Py_INCREF(tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
784 PyTuple_SET_ITEM(args, 1, tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
785 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
786 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
787 PyTuple_SET_ITEM(args, 2, self->filename); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
788 } else |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
789 Py_INCREF(args); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
790 |
|
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
791 if (self->dict) |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
792 res = PyTuple_Pack(3, Py_TYPE(self), args, self->dict); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
793 else |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
794 res = PyTuple_Pack(2, Py_TYPE(self), args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
795 Py_DECREF(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
796 return res; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
797 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
798 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
799 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
800 static PyMethodDef EnvironmentError_methods[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
801 {"__reduce__", (PyCFunction)EnvironmentError_reduce, METH_NOARGS}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
802 {NULL} |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
803 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
804 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
805 ComplexExtendsException(PyExc_StandardError, EnvironmentError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
806 EnvironmentError, EnvironmentError_dealloc, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
807 EnvironmentError_methods, EnvironmentError_members, |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
808 EnvironmentError_str, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
809 "Base class for I/O related errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
810 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
811 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
812 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
813 * IOError extends EnvironmentError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
814 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
815 MiddlingExtendsException(PyExc_EnvironmentError, IOError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
816 EnvironmentError, "I/O operation failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
817 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
818 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
819 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
820 * OSError extends EnvironmentError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
821 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
822 MiddlingExtendsException(PyExc_EnvironmentError, OSError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
823 EnvironmentError, "OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
824 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
825 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
826 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
827 * WindowsError extends OSError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
828 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
829 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
830 #include "errmap.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
831 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
832 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
833 WindowsError_clear(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
834 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
835 Py_CLEAR(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
836 Py_CLEAR(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
837 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
838 Py_CLEAR(self->winerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
839 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
840 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
841 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
842 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
843 WindowsError_dealloc(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
844 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
845 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
846 WindowsError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
847 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
848 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
849 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
850 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
851 WindowsError_traverse(PyWindowsErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
852 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
853 Py_VISIT(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
854 Py_VISIT(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
855 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
856 Py_VISIT(self->winerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
857 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
858 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
859 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
860 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
861 WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
862 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
863 PyObject *o_errcode = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
864 long errcode; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
865 long posix_errno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
866 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
867 if (EnvironmentError_init((PyEnvironmentErrorObject *)self, args, kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
868 == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
869 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
870 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
871 if (self->myerrno == NULL) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
872 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
873 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
874 /* Set errno to the POSIX errno, and winerror to the Win32 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
875 error code. */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
876 errcode = PyInt_AsLong(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
877 if (errcode == -1 && PyErr_Occurred()) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
878 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
879 posix_errno = winerror_to_errno(errcode); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
880 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
881 Py_CLEAR(self->winerror); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
882 self->winerror = self->myerrno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
883 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
884 o_errcode = PyInt_FromLong(posix_errno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
885 if (!o_errcode) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
886 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
887 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
888 self->myerrno = o_errcode; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
889 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
890 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
891 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
892 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
893 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
894 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
895 WindowsError_str(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
896 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
897 PyObject *rtnval = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
898 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
899 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
900 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
901 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
902 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
903 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
904 fmt = PyString_FromString("[Error %s] %s: %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
905 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
906 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
907 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
908 repr = PyObject_Repr(self->filename); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
909 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
910 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
911 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
912 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
913 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
914 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
915 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
916 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
917 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
918 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
919 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
920 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
921 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
922 PyTuple_SET_ITEM(tuple, 0, self->winerror); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
923 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
924 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
925 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
926 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
927 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
928 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
929 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
930 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
931 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
932 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
933 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
934 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
935 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
936 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
937 PyTuple_SET_ITEM(tuple, 2, repr); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
938 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
939 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
940 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
941 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
942 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
943 } |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
944 else if (self->winerror && self->strerror) { |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
945 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
946 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
947 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
948 fmt = PyString_FromString("[Error %s] %s"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
949 if (!fmt) |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
950 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
951 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
952 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
953 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
954 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
955 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
956 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
957 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
958 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
959 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
960 PyTuple_SET_ITEM(tuple, 0, self->winerror); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
961 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
962 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
963 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
964 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
965 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
966 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
967 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
968 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
969 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
970 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
971 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
972 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
973 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
974 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
975 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
976 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
977 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
978 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
979 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
980 else |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
981 rtnval = EnvironmentError_str((PyEnvironmentErrorObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
982 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
983 return rtnval; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
984 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
985 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
986 static PyMemberDef WindowsError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
987 {"errno", T_OBJECT, offsetof(PyWindowsErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
988 PyDoc_STR("POSIX exception code")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
989 {"strerror", T_OBJECT, offsetof(PyWindowsErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
990 PyDoc_STR("exception strerror")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
991 {"filename", T_OBJECT, offsetof(PyWindowsErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
992 PyDoc_STR("exception filename")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
993 {"winerror", T_OBJECT, offsetof(PyWindowsErrorObject, winerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
994 PyDoc_STR("Win32 exception code")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
995 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
996 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
997 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
998 ComplexExtendsException(PyExc_OSError, WindowsError, WindowsError, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
999 WindowsError_dealloc, 0, WindowsError_members, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1000 WindowsError_str, "MS-Windows OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1001 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1002 #endif /* MS_WINDOWS */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1003 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1004 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1005 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1006 * VMSError extends OSError (I think) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1007 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1008 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1009 MiddlingExtendsException(PyExc_OSError, VMSError, EnvironmentError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1010 "OpenVMS OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1011 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1012 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1013 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1014 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1015 * EOFError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1016 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1017 SimpleExtendsException(PyExc_StandardError, EOFError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1018 "Read beyond end of file."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1019 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1020 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1021 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1022 * RuntimeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1023 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1024 SimpleExtendsException(PyExc_StandardError, RuntimeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1025 "Unspecified run-time error."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1026 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1027 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1028 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1029 * NotImplementedError extends RuntimeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1030 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1031 SimpleExtendsException(PyExc_RuntimeError, NotImplementedError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1032 "Method or function hasn't been implemented yet."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1033 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1034 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1035 * NameError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1036 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1037 SimpleExtendsException(PyExc_StandardError, NameError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1038 "Name not found globally."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1039 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1040 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1041 * UnboundLocalError extends NameError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1042 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1043 SimpleExtendsException(PyExc_NameError, UnboundLocalError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1044 "Local name referenced but not bound to a value."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1045 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1046 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1047 * AttributeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1048 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1049 SimpleExtendsException(PyExc_StandardError, AttributeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1050 "Attribute not found."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1051 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1052 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1053 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1054 * SyntaxError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1055 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1056 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1057 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1058 SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1059 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1060 PyObject *info = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1061 Py_ssize_t lenargs = PyTuple_GET_SIZE(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1062 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1063 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1064 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1065 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1066 if (lenargs >= 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1067 Py_CLEAR(self->msg); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1068 self->msg = PyTuple_GET_ITEM(args, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1069 Py_INCREF(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1070 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1071 if (lenargs == 2) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1072 info = PyTuple_GET_ITEM(args, 1); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1073 info = PySequence_Tuple(info); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1074 if (!info) return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1075 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1076 if (PyTuple_GET_SIZE(info) != 4) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1077 /* not a very good error message, but it's what Python 2.4 gives */ |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1078 PyErr_SetString(PyExc_IndexError, "tuple index out of range"); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1079 Py_DECREF(info); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1080 return -1; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1081 } |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1082 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1083 Py_CLEAR(self->filename); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1084 self->filename = PyTuple_GET_ITEM(info, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1085 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1086 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1087 Py_CLEAR(self->lineno); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1088 self->lineno = PyTuple_GET_ITEM(info, 1); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1089 Py_INCREF(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1090 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1091 Py_CLEAR(self->offset); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1092 self->offset = PyTuple_GET_ITEM(info, 2); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1093 Py_INCREF(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1094 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1095 Py_CLEAR(self->text); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1096 self->text = PyTuple_GET_ITEM(info, 3); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1097 Py_INCREF(self->text); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1098 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1099 Py_DECREF(info); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1100 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1101 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1102 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1103 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1104 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1105 SyntaxError_clear(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1106 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1107 Py_CLEAR(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1108 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1109 Py_CLEAR(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1110 Py_CLEAR(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1111 Py_CLEAR(self->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1112 Py_CLEAR(self->print_file_and_line); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1113 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1114 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1115 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1116 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1117 SyntaxError_dealloc(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1118 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1119 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1120 SyntaxError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
1121 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1122 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1123 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1124 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1125 SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1126 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1127 Py_VISIT(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1128 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1129 Py_VISIT(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1130 Py_VISIT(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1131 Py_VISIT(self->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1132 Py_VISIT(self->print_file_and_line); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1133 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1134 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1135 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1136 /* This is called "my_basename" instead of just "basename" to avoid name |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1137 conflicts with glibc; basename is already prototyped if _GNU_SOURCE is |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1138 defined, and Python does define that. */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1139 static char * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1140 my_basename(char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1141 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1142 char *cp = name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1143 char *result = name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1144 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1145 if (name == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1146 return "???"; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1147 while (*cp != '\0') { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1148 if (*cp == SEP) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1149 result = cp + 1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1150 ++cp; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1151 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1152 return result; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1153 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1154 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1155 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1156 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1157 SyntaxError_str(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1158 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1159 PyObject *str; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1160 PyObject *result; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1161 int have_filename = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1162 int have_lineno = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1163 char *buffer = NULL; |
|
38469
95fb2cd1d3ba
Make last patch valid C89 so Windows compilers can deal with it.
Thomas Wouters <thomas@python.org>
parents:
38468
diff
changeset
|
1164 Py_ssize_t bufsize; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1165 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1166 if (self->msg) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1167 str = PyObject_Str(self->msg); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1168 else |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1169 str = PyObject_Str(Py_None); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1170 if (!str) return NULL; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1171 /* Don't fiddle with non-string return (shouldn't happen anyway) */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1172 if (!PyString_Check(str)) return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1173 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1174 /* XXX -- do all the additional formatting with filename and |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1175 lineno here */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1176 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1177 have_filename = (self->filename != NULL) && |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1178 PyString_Check(self->filename); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1179 have_lineno = (self->lineno != NULL) && PyInt_Check(self->lineno); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1180 |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1181 if (!have_filename && !have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1182 return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1183 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1184 bufsize = PyString_GET_SIZE(str) + 64; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1185 if (have_filename) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1186 bufsize += PyString_GET_SIZE(self->filename); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1187 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1188 buffer = PyMem_MALLOC(bufsize); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1189 if (buffer == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1190 return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1191 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1192 if (have_filename && have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1193 PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1194 PyString_AS_STRING(str), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1195 my_basename(PyString_AS_STRING(self->filename)), |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1196 PyInt_AsLong(self->lineno)); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1197 else if (have_filename) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1198 PyOS_snprintf(buffer, bufsize, "%s (%s)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1199 PyString_AS_STRING(str), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1200 my_basename(PyString_AS_STRING(self->filename))); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1201 else /* only have_lineno */ |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1202 PyOS_snprintf(buffer, bufsize, "%s (line %ld)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1203 PyString_AS_STRING(str), |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1204 PyInt_AsLong(self->lineno)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1205 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1206 result = PyString_FromString(buffer); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1207 PyMem_FREE(buffer); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1208 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1209 if (result == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1210 result = str; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1211 else |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1212 Py_DECREF(str); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1213 return result; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1214 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1215 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1216 static PyMemberDef SyntaxError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1217 {"msg", T_OBJECT, offsetof(PySyntaxErrorObject, msg), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1218 PyDoc_STR("exception msg")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1219 {"filename", T_OBJECT, offsetof(PySyntaxErrorObject, filename), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1220 PyDoc_STR("exception filename")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1221 {"lineno", T_OBJECT, offsetof(PySyntaxErrorObject, lineno), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1222 PyDoc_STR("exception lineno")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1223 {"offset", T_OBJECT, offsetof(PySyntaxErrorObject, offset), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1224 PyDoc_STR("exception offset")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1225 {"text", T_OBJECT, offsetof(PySyntaxErrorObject, text), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1226 PyDoc_STR("exception text")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1227 {"print_file_and_line", T_OBJECT, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1228 offsetof(PySyntaxErrorObject, print_file_and_line), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1229 PyDoc_STR("exception print_file_and_line")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1230 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1231 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1232 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1233 ComplexExtendsException(PyExc_StandardError, SyntaxError, SyntaxError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1234 SyntaxError_dealloc, 0, SyntaxError_members, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1235 SyntaxError_str, "Invalid syntax."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1236 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1237 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1238 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1239 * IndentationError extends SyntaxError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1240 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1241 MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1242 "Improper indentation."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1243 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1244 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1245 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1246 * TabError extends IndentationError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1247 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1248 MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1249 "Improper mixture of spaces and tabs."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1250 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1251 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1252 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1253 * LookupError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1254 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1255 SimpleExtendsException(PyExc_StandardError, LookupError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1256 "Base class for lookup errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1257 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1258 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1259 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1260 * IndexError extends LookupError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1261 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1262 SimpleExtendsException(PyExc_LookupError, IndexError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1263 "Sequence index out of range."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1264 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1265 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1266 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1267 * KeyError extends LookupError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1268 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1269 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1270 KeyError_str(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1271 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1272 /* If args is a tuple of exactly one item, apply repr to args[0]. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1273 This is done so that e.g. the exception raised by {}[''] prints |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1274 KeyError: '' |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1275 rather than the confusing |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1276 KeyError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1277 alone. The downside is that if KeyError is raised with an explanatory |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1278 string, that string will be displayed in quotes. Too bad. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1279 If args is anything else, use the default BaseException__str__(). |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1280 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1281 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1282 return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1283 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1284 return BaseException_str(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1285 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1286 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1287 ComplexExtendsException(PyExc_LookupError, KeyError, BaseException, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1288 0, 0, 0, KeyError_str, "Mapping key not found."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1289 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1290 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1291 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1292 * ValueError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1293 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1294 SimpleExtendsException(PyExc_StandardError, ValueError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1295 "Inappropriate argument value (of correct type)."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1296 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1297 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1298 * UnicodeError extends ValueError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1299 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1300 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1301 SimpleExtendsException(PyExc_ValueError, UnicodeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1302 "Unicode related error."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1303 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1304 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1305 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1306 get_string(PyObject *attr, const char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1307 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1308 if (!attr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1309 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1310 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1311 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1312 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1313 if (!PyString_Check(attr)) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1314 PyErr_Format(PyExc_TypeError, "%.200s attribute must be str", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1315 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1316 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1317 Py_INCREF(attr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1318 return attr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1319 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1320 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1321 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1322 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1323 set_string(PyObject **attr, const char *value) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1324 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1325 PyObject *obj = PyString_FromString(value); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1326 if (!obj) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1327 return -1; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1328 Py_CLEAR(*attr); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1329 *attr = obj; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1330 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1331 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1332 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1333 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1334 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1335 get_unicode(PyObject *attr, const char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1336 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1337 if (!attr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1338 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1339 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1340 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1341 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1342 if (!PyUnicode_Check(attr)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1343 PyErr_Format(PyExc_TypeError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1344 "%.200s attribute must be unicode", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1345 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1346 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1347 Py_INCREF(attr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1348 return attr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1349 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1350 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1351 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1352 PyUnicodeEncodeError_GetEncoding(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1353 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1354 return get_string(((PyUnicodeErrorObject *)exc)->encoding, "encoding"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1355 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1356 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1357 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1358 PyUnicodeDecodeError_GetEncoding(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1359 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1360 return get_string(((PyUnicodeErrorObject *)exc)->encoding, "encoding"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1361 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1362 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1363 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1364 PyUnicodeEncodeError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1365 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1366 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1367 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1368 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1369 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1370 PyUnicodeDecodeError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1371 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1372 return get_string(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1373 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1374 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1375 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1376 PyUnicodeTranslateError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1377 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1378 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1379 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1380 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1381 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1382 PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1383 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1384 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1385 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1386 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1387 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1388 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1389 *start = ((PyUnicodeErrorObject *)exc)->start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1390 size = PyUnicode_GET_SIZE(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1391 if (*start<0) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1392 *start = 0; /*XXX check for values <0*/ |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1393 if (*start>=size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1394 *start = size-1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1395 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1396 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1397 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1398 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1399 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1400 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1401 PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1402 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1403 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1404 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1405 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1406 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1407 return -1; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1408 size = PyString_GET_SIZE(obj); |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1409 *start = ((PyUnicodeErrorObject *)exc)->start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1410 if (*start<0) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1411 *start = 0; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1412 if (*start>=size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1413 *start = size-1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1414 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1415 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1416 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1417 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1418 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1419 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1420 PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1421 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1422 return PyUnicodeEncodeError_GetStart(exc, start); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1423 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1424 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1425 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1426 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1427 PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1428 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1429 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1430 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1431 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1432 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1433 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1434 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1435 PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1436 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1437 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1438 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1439 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1440 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1441 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1442 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1443 PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1444 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1445 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1446 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1447 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1448 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1449 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1450 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1451 PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1452 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1453 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1454 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1455 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1456 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1457 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1458 *end = ((PyUnicodeErrorObject *)exc)->end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1459 size = PyUnicode_GET_SIZE(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1460 if (*end<1) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1461 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1462 if (*end>size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1463 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1464 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1465 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1466 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1467 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1468 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1469 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1470 PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1471 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1472 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1473 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1474 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1475 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1476 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1477 *end = ((PyUnicodeErrorObject *)exc)->end; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1478 size = PyString_GET_SIZE(obj); |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1479 if (*end<1) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1480 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1481 if (*end>size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1482 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1483 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1484 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1485 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1486 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1487 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1488 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1489 PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1490 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1491 return PyUnicodeEncodeError_GetEnd(exc, start); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1492 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1493 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1494 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1495 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1496 PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1497 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1498 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1499 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1500 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1501 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1502 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1503 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1504 PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1505 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1506 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1507 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1508 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1509 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1510 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1511 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1512 PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1513 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1514 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1515 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1516 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1517 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1518 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1519 PyUnicodeEncodeError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1520 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1521 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1522 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1523 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1524 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1525 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1526 PyUnicodeDecodeError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1527 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1528 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1529 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1530 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1531 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1532 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1533 PyUnicodeTranslateError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1534 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1535 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1536 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1537 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1538 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1539 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1540 PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1541 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1542 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1543 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1544 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1545 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1546 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1547 PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1548 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1549 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1550 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1551 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1552 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1553 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1554 PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1555 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1556 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1557 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1558 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1559 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1560 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1561 UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1562 PyTypeObject *objecttype) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1563 { |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1564 Py_CLEAR(self->encoding); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1565 Py_CLEAR(self->object); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1566 Py_CLEAR(self->reason); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1567 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1568 if (!PyArg_ParseTuple(args, "O!O!nnO!", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1569 &PyString_Type, &self->encoding, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1570 objecttype, &self->object, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1571 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1572 &self->end, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1573 &PyString_Type, &self->reason)) { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1574 self->encoding = self->object = self->reason = NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1575 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1576 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1577 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1578 Py_INCREF(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1579 Py_INCREF(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1580 Py_INCREF(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1581 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1582 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1583 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1584 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1585 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1586 UnicodeError_clear(PyUnicodeErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1587 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1588 Py_CLEAR(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1589 Py_CLEAR(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1590 Py_CLEAR(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1591 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1592 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1593 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1594 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1595 UnicodeError_dealloc(PyUnicodeErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1596 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1597 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1598 UnicodeError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
1599 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1600 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1601 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1602 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1603 UnicodeError_traverse(PyUnicodeErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1604 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1605 Py_VISIT(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1606 Py_VISIT(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1607 Py_VISIT(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1608 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1609 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1610 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1611 static PyMemberDef UnicodeError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1612 {"encoding", T_OBJECT, offsetof(PyUnicodeErrorObject, encoding), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1613 PyDoc_STR("exception encoding")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1614 {"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1615 PyDoc_STR("exception object")}, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1616 {"start", T_PYSSIZET, offsetof(PyUnicodeErrorObject, start), 0, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1617 PyDoc_STR("exception start")}, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1618 {"end", T_PYSSIZET, offsetof(PyUnicodeErrorObject, end), 0, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1619 PyDoc_STR("exception end")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1620 {"reason", T_OBJECT, offsetof(PyUnicodeErrorObject, reason), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1621 PyDoc_STR("exception reason")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1622 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1623 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1624 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1625 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1626 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1627 * UnicodeEncodeError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1628 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1629 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1630 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1631 UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1632 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1633 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1634 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1635 return UnicodeError_init((PyUnicodeErrorObject *)self, args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1636 kwds, &PyUnicode_Type); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1637 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1638 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1639 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1640 UnicodeEncodeError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1641 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1642 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1643 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1644 if (uself->end==uself->start+1) { |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1645 int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start]; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1646 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1647 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1648 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1649 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1650 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1651 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1652 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1653 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1654 "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1655 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1656 badchar_str, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1657 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1658 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1659 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1660 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1661 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1662 "'%.400s' codec can't encode characters in position %zd-%zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1663 PyString_AS_STRING(uself->encoding), |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1664 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1665 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1666 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1667 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1668 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1669 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1670 static PyTypeObject _PyExc_UnicodeEncodeError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1671 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1672 0, |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1673 EXC_MODULE_NAME "UnicodeEncodeError", |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1674 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1675 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1676 (reprfunc)UnicodeEncodeError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1677 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
38468
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1678 PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse, |
|
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1679 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1680 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1681 (initproc)UnicodeEncodeError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1682 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1683 PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1684 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1685 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1686 PyUnicodeEncodeError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1687 const char *encoding, const Py_UNICODE *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1688 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1689 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1690 return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1691 encoding, object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1692 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1693 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1694 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1695 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1696 * UnicodeDecodeError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1697 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1698 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1699 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1700 UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1701 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1702 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1703 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1704 return UnicodeError_init((PyUnicodeErrorObject *)self, args, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1705 kwds, &PyString_Type); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1706 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1707 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1708 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1709 UnicodeDecodeError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1710 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1711 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1712 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1713 if (uself->end==uself->start+1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1714 /* FromFormat does not support %02x, so format that separately */ |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1715 char byte[4]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1716 PyOS_snprintf(byte, sizeof(byte), "%02x", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1717 ((int)PyString_AS_STRING(uself->object)[uself->start])&0xff); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1718 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1719 "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1720 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1721 byte, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1722 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1723 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1724 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1725 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1726 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1727 "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1728 PyString_AS_STRING(uself->encoding), |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1729 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1730 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1731 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1732 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1733 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1734 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1735 static PyTypeObject _PyExc_UnicodeDecodeError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1736 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1737 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1738 EXC_MODULE_NAME "UnicodeDecodeError", |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1739 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1740 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1741 (reprfunc)UnicodeDecodeError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1742 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
38468
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1743 PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse, |
|
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1744 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1745 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1746 (initproc)UnicodeDecodeError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1747 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1748 PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1749 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1750 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1751 PyUnicodeDecodeError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1752 const char *encoding, const char *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1753 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1754 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1755 assert(length < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1756 assert(start < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1757 assert(end < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1758 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1759 encoding, object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1760 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1761 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1762 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1763 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1764 * UnicodeTranslateError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1765 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1766 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1767 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1768 UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1769 PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1770 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1771 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1772 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1773 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1774 Py_CLEAR(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1775 Py_CLEAR(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1776 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1777 if (!PyArg_ParseTuple(args, "O!nnO!", |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1778 &PyUnicode_Type, &self->object, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1779 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1780 &self->end, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1781 &PyString_Type, &self->reason)) { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1782 self->object = self->reason = NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1783 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1784 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1785 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1786 Py_INCREF(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1787 Py_INCREF(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1788 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1789 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1790 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1791 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1792 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1793 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1794 UnicodeTranslateError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1795 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1796 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1797 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1798 if (uself->end==uself->start+1) { |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1799 int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start]; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1800 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1801 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1802 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1803 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1804 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1805 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1806 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1807 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1808 "can't translate character u'\\%s' in position %zd: %.400s", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1809 badchar_str, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1810 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1811 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1812 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1813 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1814 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1815 "can't translate characters in position %zd-%zd: %.400s", |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1816 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1817 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1818 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1819 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1820 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1821 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1822 static PyTypeObject _PyExc_UnicodeTranslateError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1823 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1824 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1825 EXC_MODULE_NAME "UnicodeTranslateError", |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1826 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1827 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1828 (reprfunc)UnicodeTranslateError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1829 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1830 PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1831 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1832 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1833 (initproc)UnicodeTranslateError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1834 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1835 PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1836 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1837 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1838 PyUnicodeTranslateError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1839 const Py_UNICODE *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1840 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1841 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1842 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1843 object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1844 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1845 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1846 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1847 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1848 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1849 * AssertionError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1850 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1851 SimpleExtendsException(PyExc_StandardError, AssertionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1852 "Assertion failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1853 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1854 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1855 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1856 * ArithmeticError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1857 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1858 SimpleExtendsException(PyExc_StandardError, ArithmeticError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1859 "Base class for arithmetic errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1860 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1861 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1862 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1863 * FloatingPointError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1864 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1865 SimpleExtendsException(PyExc_ArithmeticError, FloatingPointError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1866 "Floating point operation failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1867 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1868 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1869 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1870 * OverflowError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1871 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1872 SimpleExtendsException(PyExc_ArithmeticError, OverflowError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1873 "Result too large to be represented."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1874 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1875 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1876 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1877 * ZeroDivisionError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1878 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1879 SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1880 "Second argument to a division or modulo operation was zero."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1881 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1882 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1883 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1884 * SystemError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1885 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1886 SimpleExtendsException(PyExc_StandardError, SystemError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1887 "Internal error in the Python interpreter.\n" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1888 "\n" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1889 "Please report this to the Python maintainer, along with the traceback,\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1890 "the Python version, and the hardware/OS platform and version."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1891 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1892 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1893 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1894 * ReferenceError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1895 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1896 SimpleExtendsException(PyExc_StandardError, ReferenceError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1897 "Weak ref proxy used after referent went away."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1898 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1899 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1900 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1901 * MemoryError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1902 */ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1903 SimpleExtendsException(PyExc_StandardError, MemoryError, "Out of memory."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1904 |
|
45832
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1905 /* |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1906 * BufferError extends StandardError |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1907 */ |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1908 SimpleExtendsException(PyExc_StandardError, BufferError, "Buffer error."); |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1909 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1910 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1911 /* Warning category docstrings */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1912 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1913 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1914 * Warning extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1915 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1916 SimpleExtendsException(PyExc_Exception, Warning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1917 "Base class for warning categories."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1918 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1919 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1920 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1921 * UserWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1922 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1923 SimpleExtendsException(PyExc_Warning, UserWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1924 "Base class for warnings generated by user code."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1925 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1926 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1927 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1928 * DeprecationWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1929 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1930 SimpleExtendsException(PyExc_Warning, DeprecationWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1931 "Base class for warnings about deprecated features."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1932 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1933 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1934 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1935 * PendingDeprecationWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1936 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1937 SimpleExtendsException(PyExc_Warning, PendingDeprecationWarning, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1938 "Base class for warnings about features which will be deprecated\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1939 "in the future."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1940 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1941 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1942 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1943 * SyntaxWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1944 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1945 SimpleExtendsException(PyExc_Warning, SyntaxWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1946 "Base class for warnings about dubious syntax."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1947 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1948 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1949 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1950 * RuntimeWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1951 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1952 SimpleExtendsException(PyExc_Warning, RuntimeWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1953 "Base class for warnings about dubious runtime behavior."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1954 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1955 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1956 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1957 * FutureWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1958 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1959 SimpleExtendsException(PyExc_Warning, FutureWarning, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1960 "Base class for warnings about constructs that will change semantically\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1961 "in the future."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1962 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1963 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1964 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1965 * ImportWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1966 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1967 SimpleExtendsException(PyExc_Warning, ImportWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1968 "Base class for warnings about probable mistakes in module imports"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1969 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1970 |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1971 /* |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1972 * UnicodeWarning extends Warning |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1973 */ |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1974 SimpleExtendsException(PyExc_Warning, UnicodeWarning, |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1975 "Base class for warnings about Unicode related problems, mostly\n" |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1976 "related to conversion problems."); |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1977 |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1978 /* |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1979 * BytesWarning extends Warning |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1980 */ |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1981 SimpleExtendsException(PyExc_Warning, BytesWarning, |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1982 "Base class for warnings about bytes and buffer related problems, mostly\n" |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1983 "related to conversion from str or comparing to str."); |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1984 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1985 /* Pre-computed MemoryError instance. Best to create this as early as |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1986 * possible and not wait until a MemoryError is actually raised! |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1987 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1988 PyObject *PyExc_MemoryErrorInst=NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1989 |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1990 /* Pre-computed RuntimeError instance for when recursion depth is reached. |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1991 Meant to be used when normalizing the exception for exceeding the recursion |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1992 depth will cause its own infinite recursion. |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1993 */ |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1994 PyObject *PyExc_RecursionErrorInst = NULL; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1995 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1996 /* module global functions */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1997 static PyMethodDef functions[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1998 /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1999 {NULL, NULL} |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2000 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2001 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2002 #define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2003 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2004 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2005 #define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2006 PyModule_AddObject(m, # TYPE, PyExc_ ## TYPE); \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2007 if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2008 Py_FatalError("Module dictionary insertion problem."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2009 |
|
38779
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2010 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2011 PyMODINIT_FUNC |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
2012 _PyExc_Init(void) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2013 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2014 PyObject *m, *bltinmod, *bdict; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2015 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2016 PRE_INIT(BaseException) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2017 PRE_INIT(Exception) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2018 PRE_INIT(StandardError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2019 PRE_INIT(TypeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2020 PRE_INIT(StopIteration) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2021 PRE_INIT(GeneratorExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2022 PRE_INIT(SystemExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2023 PRE_INIT(KeyboardInterrupt) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2024 PRE_INIT(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2025 PRE_INIT(EnvironmentError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2026 PRE_INIT(IOError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2027 PRE_INIT(OSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2028 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2029 PRE_INIT(WindowsError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2030 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2031 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2032 PRE_INIT(VMSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2033 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2034 PRE_INIT(EOFError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2035 PRE_INIT(RuntimeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2036 PRE_INIT(NotImplementedError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2037 PRE_INIT(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2038 PRE_INIT(UnboundLocalError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2039 PRE_INIT(AttributeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2040 PRE_INIT(SyntaxError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2041 PRE_INIT(IndentationError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2042 PRE_INIT(TabError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2043 PRE_INIT(LookupError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2044 PRE_INIT(IndexError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2045 PRE_INIT(KeyError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2046 PRE_INIT(ValueError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2047 PRE_INIT(UnicodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2048 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2049 PRE_INIT(UnicodeEncodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2050 PRE_INIT(UnicodeDecodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2051 PRE_INIT(UnicodeTranslateError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2052 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2053 PRE_INIT(AssertionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2054 PRE_INIT(ArithmeticError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2055 PRE_INIT(FloatingPointError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2056 PRE_INIT(OverflowError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2057 PRE_INIT(ZeroDivisionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2058 PRE_INIT(SystemError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2059 PRE_INIT(ReferenceError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2060 PRE_INIT(MemoryError) |
| 48103 | 2061 PRE_INIT(BufferError) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2062 PRE_INIT(Warning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2063 PRE_INIT(UserWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2064 PRE_INIT(DeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2065 PRE_INIT(PendingDeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2066 PRE_INIT(SyntaxWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2067 PRE_INIT(RuntimeWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2068 PRE_INIT(FutureWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2069 PRE_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2070 PRE_INIT(UnicodeWarning) |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
2071 PRE_INIT(BytesWarning) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2072 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2073 m = Py_InitModule4("exceptions", functions, exceptions_doc, |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2074 (PyObject *)NULL, PYTHON_API_VERSION); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2075 if (m == NULL) return; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2076 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2077 bltinmod = PyImport_ImportModule("__builtin__"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2078 if (bltinmod == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2079 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2080 bdict = PyModule_GetDict(bltinmod); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2081 if (bdict == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2082 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2083 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2084 POST_INIT(BaseException) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2085 POST_INIT(Exception) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2086 POST_INIT(StandardError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2087 POST_INIT(TypeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2088 POST_INIT(StopIteration) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2089 POST_INIT(GeneratorExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2090 POST_INIT(SystemExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2091 POST_INIT(KeyboardInterrupt) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2092 POST_INIT(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2093 POST_INIT(EnvironmentError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2094 POST_INIT(IOError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2095 POST_INIT(OSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2096 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2097 POST_INIT(WindowsError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2098 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2099 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2100 POST_INIT(VMSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2101 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2102 POST_INIT(EOFError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2103 POST_INIT(RuntimeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2104 POST_INIT(NotImplementedError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2105 POST_INIT(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2106 POST_INIT(UnboundLocalError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2107 POST_INIT(AttributeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2108 POST_INIT(SyntaxError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2109 POST_INIT(IndentationError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2110 POST_INIT(TabError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2111 POST_INIT(LookupError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2112 POST_INIT(IndexError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2113 POST_INIT(KeyError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2114 POST_INIT(ValueError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2115 POST_INIT(UnicodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2116 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2117 POST_INIT(UnicodeEncodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2118 POST_INIT(UnicodeDecodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2119 POST_INIT(UnicodeTranslateError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2120 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2121 POST_INIT(AssertionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2122 POST_INIT(ArithmeticError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2123 POST_INIT(FloatingPointError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2124 POST_INIT(OverflowError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2125 POST_INIT(ZeroDivisionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2126 POST_INIT(SystemError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2127 POST_INIT(ReferenceError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2128 POST_INIT(MemoryError) |
| 48103 | 2129 POST_INIT(BufferError) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2130 POST_INIT(Warning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2131 POST_INIT(UserWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2132 POST_INIT(DeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2133 POST_INIT(PendingDeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2134 POST_INIT(SyntaxWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2135 POST_INIT(RuntimeWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2136 POST_INIT(FutureWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2137 POST_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2138 POST_INIT(UnicodeWarning) |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
2139 POST_INIT(BytesWarning) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2140 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2141 PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2142 if (!PyExc_MemoryErrorInst) |
|
50830
e158c70511fe
#4077: No need to append \n when calling Py_FatalError
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48103
diff
changeset
|
2143 Py_FatalError("Cannot pre-allocate MemoryError instance"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2144 |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2145 PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2146 if (!PyExc_RecursionErrorInst) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2147 Py_FatalError("Cannot pre-allocate RuntimeError instance for " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2148 "recursion errors"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2149 else { |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2150 PyBaseExceptionObject *err_inst = |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2151 (PyBaseExceptionObject *)PyExc_RecursionErrorInst; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2152 PyObject *args_tuple; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2153 PyObject *exc_message; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2154 exc_message = PyString_FromString("maximum recursion depth exceeded"); |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2155 if (!exc_message) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2156 Py_FatalError("cannot allocate argument for RuntimeError " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2157 "pre-allocation"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2158 args_tuple = PyTuple_Pack(1, exc_message); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2159 if (!args_tuple) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2160 Py_FatalError("cannot allocate tuple for RuntimeError " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2161 "pre-allocation"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2162 Py_DECREF(exc_message); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2163 if (BaseException_init(err_inst, args_tuple, NULL)) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2164 Py_FatalError("init of pre-allocated RuntimeError failed"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2165 Py_DECREF(args_tuple); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2166 } |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2167 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2168 Py_DECREF(bltinmod); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2169 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2170 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2171 void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2172 _PyExc_Fini(void) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2173 { |
|
54716
f34754a745ae
Clear reference to the static PyExc_RecursionErrorInst in _PyExc_Fini.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
51514
diff
changeset
|
2174 Py_CLEAR(PyExc_MemoryErrorInst); |
|
f34754a745ae
Clear reference to the static PyExc_RecursionErrorInst in _PyExc_Fini.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
51514
diff
changeset
|
2175 Py_CLEAR(PyExc_RecursionErrorInst); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2176 } |
