Mercurial > cpython-lru_cache-weakref
annotate Objects/exceptions.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 9424b84a2ec9 |
| children | 5ac349c322fd |
| 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 MAKE_IT_NONE(x) (x) = Py_None; 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
|
13 #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
|
14 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
15 /* 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
|
16 * Lib/test/exception_hierarchy.txt |
|
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 |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
19 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
|
20 \n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 inheritance hierarchy.\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
25 "); |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
26 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
27 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
28 * BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
29 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
30 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
|
31 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
|
32 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
33 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
|
34 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
35 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
|
36 if (!self) |
|
46d0f4057705
Add some missing NULL checks which trigger crashes on low-memory conditions.
Georg Brandl <georg@python.org>
parents:
40908
diff
changeset
|
37 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
|
38 /* 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
|
39 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
|
40 |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
41 self->args = PyTuple_New(0); |
|
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
46 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
52 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
53 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
56 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
|
57 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
|
58 { |
|
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
|
59 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
|
60 return -1; |
|
13fedd0d0f26
Do the check for no keyword arguments in __init__ so that
Georg Brandl <georg@python.org>
parents:
38508
diff
changeset
|
61 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
66 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
71 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
|
72 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
73 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
74 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
|
75 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
|
76 { |
|
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->dict); |
|
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->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
79 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
|
80 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
83 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
|
84 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
|
85 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
86 _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
|
87 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
|
88 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
|
89 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
90 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
91 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
|
92 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
|
93 { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
100 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
|
101 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
|
102 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
103 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
|
104 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
109 case 1: |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
110 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
|
111 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
112 default: |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
113 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
|
114 break; |
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
117 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
|
118 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
119 |
|
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
|
120 #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
|
121 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
|
122 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
|
123 { |
|
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 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
|
125 |
|
57928
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
126 /* issue6108: if __str__ has been overridden in the subclass, unicode() |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
127 should return the message returned by __str__ as used to happen |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
128 before this method was implemented. */ |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
129 if (Py_TYPE(self)->tp_str != (reprfunc)BaseException_str) { |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
130 PyObject *str; |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
131 /* Unlike PyObject_Str, tp_str can return unicode (i.e. return the |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
132 equivalent of unicode(e.__str__()) instead of unicode(str(e))). */ |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
133 str = Py_TYPE(self)->tp_str((PyObject*)self); |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
134 if (str == NULL) |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
135 return NULL; |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
136 out = PyObject_Unicode(str); |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
137 Py_DECREF(str); |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
138 return out; |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
139 } |
|
9424b84a2ec9
Merged revisions 77045 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56014
diff
changeset
|
140 |
|
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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
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 |
|
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 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
|
154 } |
|
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 #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
|
156 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
157 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
|
158 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
|
159 { |
|
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_suffix; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
165 repr_suffix = PyObject_Repr(self->args); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
166 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
|
167 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
|
168 |
|
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
|
169 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
|
170 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
|
171 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
|
172 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
178 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
179 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
|
180 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
183 /* 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
|
184 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
|
185 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
|
186 { |
|
38505
4f8586946c8f
Restore exception pickle support. #1497319.
Georg Brandl <georg@python.org>
parents:
38476
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 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
|
191 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
192 |
|
38532
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
193 /* |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
194 * 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
|
195 * 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
|
196 * load_build function. |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
197 */ |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
198 static PyObject * |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
199 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
|
200 { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
201 PyObject *d_key, *d_value; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
202 Py_ssize_t i = 0; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
203 |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
204 if (state != Py_None) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
205 if (!PyDict_Check(state)) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
206 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
|
207 return NULL; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
208 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
209 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
|
210 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
|
211 return NULL; |
|
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 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
214 Py_RETURN_NONE; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
215 } |
|
38431
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
218 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
|
219 {"__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
|
220 {"__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
|
221 #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
|
222 {"__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
|
223 #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
|
224 {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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
229 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
|
230 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
|
231 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
232 if (PyErr_WarnPy3k("__getitem__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
233 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
234 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
|
235 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
|
236 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
237 |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
238 static PyObject * |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
239 BaseException_getslice(PyBaseExceptionObject *self, |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
240 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
|
241 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
242 if (PyErr_WarnPy3k("__getslice__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
243 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
244 return NULL; |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
245 return PySequence_GetSlice(self->args, start, stop); |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
246 } |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
247 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 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
|
252 (ssizeargfunc)BaseException_getitem, /* sq_item; */ |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
253 (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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
261 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
|
262 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
|
263 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
269 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
|
270 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
273 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
|
274 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
|
275 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 } |
|
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_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
|
285 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
|
286 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
|
287 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
290 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
|
291 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
|
292 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
297 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
|
298 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
301 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
|
302 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
|
303 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
309 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
|
310 if (!seq) return -1; |
|
38476
d3383063491f
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Georg Brandl <georg@python.org>
parents:
38469
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
315 |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
316 static PyObject * |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
317 BaseException_get_message(PyBaseExceptionObject *self) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
318 { |
|
56014
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
319 PyObject *msg; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
320 |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
321 /* if "message" is in self->dict, accessing a user-set message attribute */ |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
322 if (self->dict && |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
323 (msg = PyDict_GetItemString(self->dict, "message"))) { |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
324 Py_INCREF(msg); |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
325 return msg; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
326 } |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
327 |
|
56014
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
328 if (self->message == NULL) { |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
329 PyErr_SetString(PyExc_AttributeError, "message attribute was deleted"); |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
330 return NULL; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
331 } |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
332 |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
333 /* accessing the deprecated "builtin" message attribute of Exception */ |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
334 if (PyErr_WarnEx(PyExc_DeprecationWarning, |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
335 "BaseException.message has been deprecated as " |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
336 "of Python 2.6", 1) < 0) |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
337 return NULL; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
338 |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
339 Py_INCREF(self->message); |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
340 return self->message; |
|
41617
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 |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
343 static int |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
344 BaseException_set_message(PyBaseExceptionObject *self, PyObject *val) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
345 { |
|
56014
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
346 /* if val is NULL, delete the message attribute */ |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
347 if (val == NULL) { |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
348 if (self->dict && PyDict_GetItemString(self->dict, "message")) { |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
349 if (PyDict_DelItemString(self->dict, "message") < 0) |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
350 return -1; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
351 } |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
352 Py_XDECREF(self->message); |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
353 self->message = NULL; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
354 return 0; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
355 } |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
356 |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
357 /* else set it in __dict__, but may need to create the dict first */ |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
358 if (self->dict == NULL) { |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
359 self->dict = PyDict_New(); |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
360 if (!self->dict) |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
361 return -1; |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
362 } |
|
8ab304034021
Merged revisions 74845 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48103
diff
changeset
|
363 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
|
364 } |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
365 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
366 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
|
367 {"__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
|
368 {"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
|
369 {"message", (getter)BaseException_get_message, |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
370 (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
|
371 {NULL}, |
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 (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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 (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
|
387 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
|
388 &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
|
389 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
|
390 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
|
391 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
|
392 (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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 (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
|
400 (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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 BaseException_methods, /* tp_methods */ |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 (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
|
414 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
|
415 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
|
416 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
417 /* 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
|
418 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
|
419 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
|
420 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
|
421 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
422 /* 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
|
423 * include it and not look strange. |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
424 */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
425 #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
|
426 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
|
427 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
|
428 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 (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
|
436 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
|
437 (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
|
438 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
439 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
|
440 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
441 #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
|
442 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
|
443 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
|
444 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
445 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
|
446 sizeof(Py ## EXCSTORE ## Object), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
447 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
|
448 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
|
449 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
|
450 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
451 (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
|
452 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
|
453 (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
|
454 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
455 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
|
456 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
457 #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
|
458 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
|
459 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
|
460 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
461 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
|
462 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
|
463 (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
|
464 (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
|
465 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
|
466 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
|
467 (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
|
468 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
|
469 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
|
470 (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
|
471 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
472 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
476 * 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
|
477 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
478 SimpleExtendsException(PyExc_BaseException, Exception, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
479 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
483 * 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
|
484 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
485 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
|
486 "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
|
487 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
491 * 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
|
492 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
493 SimpleExtendsException(PyExc_StandardError, TypeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
494 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
498 * 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
|
499 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
500 SimpleExtendsException(PyExc_Exception, StopIteration, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
501 "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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
504 /* |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
505 * 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
|
506 */ |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
507 SimpleExtendsException(PyExc_BaseException, GeneratorExit, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
508 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
512 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
515 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
|
516 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
|
517 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
518 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
|
519 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
520 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
|
521 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
|
522 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
523 if (size == 0) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
524 return 0; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
533 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
534 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
|
535 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
|
536 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
537 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
|
538 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
541 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
|
542 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
|
543 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
544 _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
|
545 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
|
546 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
|
547 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
548 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
549 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
|
550 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
|
551 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
552 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
|
553 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
556 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
|
557 {"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
|
558 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
|
559 {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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
562 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
|
563 SystemExit_dealloc, 0, SystemExit_members, 0, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
564 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
567 * 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
|
568 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
569 SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
570 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
574 * 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
|
575 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
576 SimpleExtendsException(PyExc_StandardError, ImportError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
577 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
581 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
584 /* 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
|
585 * 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
|
586 * 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
|
587 * 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
|
588 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
589 * 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
|
590 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
591 * 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
|
592 * 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
|
593 * 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
|
594 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 { |
|
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 *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
|
600 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
|
601 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
602 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
|
603 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
|
604 |
|
39924
e1ab4653ebc0
Bug #1566800: make sure that EnvironmentError can be called with any
Georg Brandl <georg@python.org>
parents:
39863
diff
changeset
|
605 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
|
606 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
|
607 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
608 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
609 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
|
610 &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
|
611 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
|
612 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
621 /* 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
|
622 if (filename != NULL) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
623 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
|
624 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
|
625 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
|
626 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
627 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
|
628 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
|
629 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
|
630 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
631 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
|
632 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
|
633 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
634 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
|
635 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
636 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
637 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
|
638 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
|
639 { |
|
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->myerrno); |
|
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->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
642 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
|
643 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
646 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
|
647 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
|
648 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
649 _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
|
650 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
|
651 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
|
652 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
653 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 { |
|
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->myerrno); |
|
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->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
660 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
|
661 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
664 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
|
665 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
|
666 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
667 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
|
668 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
669 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
670 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
671 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
672 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
|
673 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
674 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
|
675 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
676 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
677 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
678 repr = PyObject_Repr(self->filename); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
679 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
680 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
|
681 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
|
682 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
683 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
684 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
685 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
686 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
687 return NULL; |
|
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 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
690 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
691 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
692 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
|
693 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
694 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
695 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
696 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
|
697 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
698 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
699 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
700 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
|
701 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
702 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
703 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
704 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
|
705 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
706 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
707 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
|
708 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
709 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
|
710 |
|
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(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
712 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
|
713 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
714 else if (self->myerrno && self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
715 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
716 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
|
717 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
718 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
|
719 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
720 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
721 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
722 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
723 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
724 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
|
725 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
|
726 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
727 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
728 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
729 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
730 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
|
731 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
732 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
733 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
734 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
|
735 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
736 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
737 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
738 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
|
739 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
740 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
741 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
742 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
|
743 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
744 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
745 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
|
746 |
|
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(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
748 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
|
749 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
750 else |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
751 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
|
752 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
753 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
756 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
|
757 {"errno", T_OBJECT, offsetof(PyEnvironmentErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
758 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
|
759 {"strerror", T_OBJECT, offsetof(PyEnvironmentErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
760 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
|
761 {"filename", T_OBJECT, offsetof(PyEnvironmentErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
762 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
|
763 {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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
767 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
|
768 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
|
769 { |
|
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 *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
|
771 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
|
772 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
773 /* 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
|
774 * file name given to EnvironmentError. */ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
775 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
|
776 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
|
777 if (!args) return NULL; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
778 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
779 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
|
780 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
|
781 PyTuple_SET_ITEM(args, 0, tmp); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
782 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
783 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
|
784 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
|
785 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
|
786 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
787 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
|
788 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
|
789 } 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
|
790 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
|
791 |
|
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
801 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
|
802 {"__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
|
803 {NULL} |
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
806 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
|
807 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
|
808 EnvironmentError_methods, EnvironmentError_members, |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
809 EnvironmentError_str, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
810 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
814 * 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
|
815 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
816 MiddlingExtendsException(PyExc_EnvironmentError, IOError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
817 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
821 * 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
|
822 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
823 MiddlingExtendsException(PyExc_EnvironmentError, OSError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
824 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
828 * 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
|
829 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
830 #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
|
831 #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
|
832 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
833 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
|
834 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
|
835 { |
|
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->myerrno); |
|
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->strerror); |
|
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->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
839 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
|
840 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
843 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
|
844 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
|
845 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
846 _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
|
847 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
|
848 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
|
849 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
850 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
851 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
|
852 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
|
853 { |
|
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->myerrno); |
|
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->strerror); |
|
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->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
857 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
|
858 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
861 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
|
862 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
|
863 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
868 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
|
869 == -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 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
|
871 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
872 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
|
873 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
|
874 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
875 /* 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
|
876 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
|
877 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
|
878 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
|
879 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
|
880 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
|
881 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
882 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
|
883 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
|
884 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
885 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
|
886 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
|
887 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
|
888 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
889 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
|
890 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
891 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
895 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
|
896 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
|
897 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
898 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
|
899 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
900 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
901 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
902 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
903 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
904 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
905 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
|
906 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
907 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
908 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
909 repr = PyObject_Repr(self->filename); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
910 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
911 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
912 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
913 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
914 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
915 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
916 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
917 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
918 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
919 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
920 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
921 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
922 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
923 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
|
924 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
925 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
926 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
927 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
|
928 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
929 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
930 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
931 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
|
932 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
933 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
934 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
935 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
|
936 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
937 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
938 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
|
939 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
940 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
941 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
942 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
|
943 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
|
944 } |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
945 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
|
946 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
947 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
948 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
949 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
|
950 if (!fmt) |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
951 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
952 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
953 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
954 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
955 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
956 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
957 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
958 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
959 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
960 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
961 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
|
962 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
963 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
964 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
965 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
|
966 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
967 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
968 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
969 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
|
970 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
971 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
972 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
973 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
|
974 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
975 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
976 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
977 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
978 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
|
979 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
|
980 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
981 else |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
982 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
|
983 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
984 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
987 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
|
988 {"errno", T_OBJECT, offsetof(PyWindowsErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
989 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
|
990 {"strerror", T_OBJECT, offsetof(PyWindowsErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
991 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
|
992 {"filename", T_OBJECT, offsetof(PyWindowsErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
993 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
|
994 {"winerror", T_OBJECT, offsetof(PyWindowsErrorObject, winerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
995 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
|
996 {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
|
997 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
998 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
999 ComplexExtendsException(PyExc_OSError, WindowsError, WindowsError, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1000 WindowsError_dealloc, 0, WindowsError_members, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1001 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
|
1002 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1003 #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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1007 * 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
|
1008 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1009 #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
|
1010 MiddlingExtendsException(PyExc_OSError, VMSError, EnvironmentError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1011 "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
|
1012 #endif |
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1016 * 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
|
1017 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1018 SimpleExtendsException(PyExc_StandardError, EOFError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1019 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1023 * 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
|
1024 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1025 SimpleExtendsException(PyExc_StandardError, RuntimeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1026 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1030 * 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
|
1031 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1032 SimpleExtendsException(PyExc_RuntimeError, NotImplementedError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1033 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1036 * 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
|
1037 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1038 SimpleExtendsException(PyExc_StandardError, NameError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1039 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1042 * 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
|
1043 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1044 SimpleExtendsException(PyExc_NameError, UnboundLocalError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1045 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1048 * 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
|
1049 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1050 SimpleExtendsException(PyExc_StandardError, AttributeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1051 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1055 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1058 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
|
1059 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
|
1060 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1061 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
|
1062 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
|
1063 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1064 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
|
1065 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
|
1066 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1067 if (lenargs >= 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1068 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
|
1069 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
|
1070 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
|
1071 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1072 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
|
1073 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
|
1074 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
|
1075 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
|
1076 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1077 if (PyTuple_GET_SIZE(info) != 4) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1078 /* 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
|
1079 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
|
1080 Py_DECREF(info); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1081 return -1; |
|
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 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1084 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
|
1085 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
|
1086 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
|
1087 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1092 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
|
1093 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
|
1094 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
|
1095 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1096 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
|
1097 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
|
1098 Py_INCREF(self->text); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1099 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1100 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
|
1101 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1102 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
|
1103 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1104 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1105 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
|
1106 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
|
1107 { |
|
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->msg); |
|
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->filename); |
|
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->lineno); |
|
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->offset); |
|
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->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1113 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
|
1114 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1117 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
|
1118 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
|
1119 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1120 _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
|
1121 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
|
1122 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
|
1123 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1124 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1125 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
|
1126 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
|
1127 { |
|
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->msg); |
|
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->filename); |
|
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->lineno); |
|
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->offset); |
|
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->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1133 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
|
1134 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1137 /* 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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 { |
|
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 *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
|
1144 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
|
1145 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1146 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
|
1147 return "???"; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 ++cp; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1152 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1153 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1157 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
|
1158 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
|
1159 { |
|
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 *str; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1161 PyObject *result; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1162 int have_filename = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1163 int have_lineno = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1164 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
|
1165 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
|
1166 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1167 if (self->msg) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1168 str = PyObject_Str(self->msg); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1169 else |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1170 str = PyObject_Str(Py_None); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1171 if (!str) return NULL; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1172 /* 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
|
1173 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
|
1174 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1175 /* 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
|
1176 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
|
1177 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1178 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
|
1179 PyString_Check(self->filename); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1180 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
|
1181 |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1182 if (!have_filename && !have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1183 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
|
1184 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1185 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
|
1186 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
|
1187 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
|
1188 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1189 buffer = PyMem_MALLOC(bufsize); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1190 if (buffer == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1191 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
|
1192 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1193 if (have_filename && have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1194 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
|
1195 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
|
1196 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
|
1197 PyInt_AsLong(self->lineno)); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1198 else if (have_filename) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1199 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
|
1200 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
|
1201 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
|
1202 else /* only have_lineno */ |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1203 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
|
1204 PyString_AS_STRING(str), |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1205 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
|
1206 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1207 result = PyString_FromString(buffer); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1208 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
|
1209 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1210 if (result == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1211 result = str; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1212 else |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1213 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
|
1214 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1217 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
|
1218 {"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
|
1219 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
|
1220 {"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
|
1221 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
|
1222 {"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
|
1223 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
|
1224 {"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
|
1225 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
|
1226 {"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
|
1227 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
|
1228 {"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
|
1229 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
|
1230 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
|
1231 {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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1234 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
|
1235 SyntaxError_dealloc, 0, SyntaxError_members, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1236 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1240 * 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
|
1241 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1242 MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1243 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1247 * 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
|
1248 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1249 MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1250 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1254 * 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
|
1255 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1256 SimpleExtendsException(PyExc_StandardError, LookupError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1257 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1261 * 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
|
1262 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1263 SimpleExtendsException(PyExc_LookupError, IndexError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1264 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1268 * 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
|
1269 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1270 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
|
1271 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
|
1272 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1273 /* 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
|
1274 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
|
1275 KeyError: '' |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1276 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
|
1277 KeyError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1278 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
|
1279 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
|
1280 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
|
1281 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1282 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1283 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
|
1284 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1285 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1288 ComplexExtendsException(PyExc_LookupError, KeyError, BaseException, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1289 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1293 * 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
|
1294 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1295 SimpleExtendsException(PyExc_StandardError, ValueError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1296 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1299 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1302 SimpleExtendsException(PyExc_ValueError, UnicodeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1303 "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
|
1304 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1305 #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
|
1306 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
|
1307 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
|
1308 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1309 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
|
1310 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
|
1311 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
|
1312 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1313 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1314 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
|
1315 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
|
1316 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
|
1317 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1318 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
|
1319 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1323 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
|
1324 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
|
1325 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1326 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
|
1327 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
|
1328 return -1; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1329 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
|
1330 *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
|
1331 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1335 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
|
1336 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
|
1337 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1338 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
|
1339 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
|
1340 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1343 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
|
1344 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
|
1345 "%.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
|
1346 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
|
1347 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1348 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
|
1349 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1352 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1353 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
|
1354 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1355 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1358 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1359 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
|
1360 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1361 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1364 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1365 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
|
1366 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1367 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1370 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1371 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
|
1372 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1373 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1376 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1377 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
|
1378 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1379 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1382 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1383 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
|
1384 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1385 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
|
1386 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
|
1387 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1388 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1389 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1390 *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
|
1391 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
|
1392 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
|
1393 *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
|
1394 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
|
1395 *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
|
1396 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
|
1397 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1401 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1402 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
|
1403 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1404 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
|
1405 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
|
1406 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1407 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1408 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
|
1409 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
|
1410 *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
|
1411 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
|
1412 *start = 0; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1413 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
|
1414 *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
|
1415 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
|
1416 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1420 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1421 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
|
1422 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1423 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1427 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1428 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
|
1429 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1430 ((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
|
1431 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1435 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1436 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
|
1437 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1438 ((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
|
1439 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1443 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1444 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
|
1445 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1446 ((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
|
1447 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1451 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1452 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
|
1453 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1454 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
|
1455 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
|
1456 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1457 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1458 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1459 *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
|
1460 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
|
1461 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
|
1462 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1463 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
|
1464 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1465 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
|
1466 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1470 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1471 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
|
1472 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1473 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
|
1474 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
|
1475 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1476 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1477 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1478 *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
|
1479 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
|
1480 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
|
1481 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1482 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
|
1483 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1484 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
|
1485 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1489 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1490 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
|
1491 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1492 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1496 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1497 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
|
1498 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1499 ((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
|
1500 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1504 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1505 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
|
1506 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1507 ((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
|
1508 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1512 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1513 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
|
1514 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1515 ((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
|
1516 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1519 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1520 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
|
1521 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1522 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1526 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1527 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
|
1528 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1529 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1533 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1534 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
|
1535 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1536 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1540 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1541 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
|
1542 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1543 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1547 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1548 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
|
1549 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1550 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1554 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1555 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
|
1556 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1557 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1561 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
|
1562 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
|
1563 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
|
1564 { |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1565 Py_CLEAR(self->encoding); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1566 Py_CLEAR(self->object); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1567 Py_CLEAR(self->reason); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1568 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1569 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
|
1570 &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
|
1571 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
|
1572 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1573 &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
|
1574 &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
|
1575 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
|
1576 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
|
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 |
|
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->encoding); |
|
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->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1581 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
|
1582 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1583 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
|
1584 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1585 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1586 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
|
1587 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
|
1588 { |
|
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->encoding); |
|
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->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1591 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
|
1592 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1595 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
|
1596 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
|
1597 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1598 _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
|
1599 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
|
1600 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
|
1601 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1602 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1603 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
|
1604 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
|
1605 { |
|
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->encoding); |
|
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->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1608 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
|
1609 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1612 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
|
1613 {"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
|
1614 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
|
1615 {"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
|
1616 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
|
1617 {"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
|
1618 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
|
1619 {"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
|
1620 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
|
1621 {"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
|
1622 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
|
1623 {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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1628 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1631 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
|
1632 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
|
1633 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1634 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
|
1635 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
|
1636 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
|
1637 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1640 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
|
1641 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
|
1642 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1643 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
|
1644 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1645 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
|
1646 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
|
1647 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1648 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1649 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
|
1650 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1651 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
|
1652 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1653 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
|
1654 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1655 "'%.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
|
1656 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1657 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
|
1658 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
|
1659 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1660 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1661 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1662 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
|
1663 "'%.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
|
1664 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
|
1665 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1666 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
|
1667 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1671 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
|
1672 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
|
1673 0, |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1674 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
|
1675 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
|
1676 (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
|
1677 (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
|
1678 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
|
1679 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
|
1680 (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
|
1681 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
|
1682 (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
|
1683 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1684 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
|
1685 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1686 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1687 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
|
1688 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
|
1689 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
|
1690 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1691 return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1692 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1697 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1700 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
|
1701 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
|
1702 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1703 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
|
1704 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
|
1705 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
|
1706 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1709 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
|
1710 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
|
1711 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1712 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
|
1713 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1714 if (uself->end==uself->start+1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1715 /* 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
|
1716 char byte[4]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1717 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
|
1718 ((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
|
1719 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1720 "'%.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
|
1721 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1722 byte, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1723 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
|
1724 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1725 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1726 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1727 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
|
1728 "'%.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
|
1729 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
|
1730 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1731 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
|
1732 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1736 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
|
1737 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
|
1738 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1739 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
|
1740 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
|
1741 (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
|
1742 (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
|
1743 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
|
1744 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
|
1745 (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
|
1746 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
|
1747 (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
|
1748 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1749 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
|
1750 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1751 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1752 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
|
1753 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
|
1754 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
|
1755 { |
|
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(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
|
1757 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
|
1758 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
|
1759 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1760 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1765 * 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1768 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
|
1769 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
|
1770 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
|
1771 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1772 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
|
1773 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
|
1774 |
|
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->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1776 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
|
1777 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1778 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
|
1779 &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
|
1780 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1781 &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
|
1782 &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
|
1783 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
|
1784 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
|
1785 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1786 |
|
38431
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->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1788 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
|
1789 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1790 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1794 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
|
1795 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
|
1796 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1797 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
|
1798 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1799 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
|
1800 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
|
1801 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1802 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1803 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
|
1804 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1805 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
|
1806 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1807 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
|
1808 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
|
1809 "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
|
1810 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
|
1811 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
|
1812 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1813 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1814 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1815 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
|
1816 "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
|
1817 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1818 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
|
1819 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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1823 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
|
1824 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
|
1825 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1826 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
|
1827 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
|
1828 (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
|
1829 (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
|
1830 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
|
1831 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
|
1832 (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
|
1833 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
|
1834 (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
|
1835 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1836 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
|
1837 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1838 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1839 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
|
1840 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
|
1841 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
|
1842 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1843 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1844 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
|
1845 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1846 #endif |
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1850 * 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
|
1851 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1852 SimpleExtendsException(PyExc_StandardError, AssertionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1853 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1857 * 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
|
1858 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1859 SimpleExtendsException(PyExc_StandardError, ArithmeticError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1860 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1864 * 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
|
1865 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1866 SimpleExtendsException(PyExc_ArithmeticError, FloatingPointError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1867 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1871 * 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
|
1872 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1873 SimpleExtendsException(PyExc_ArithmeticError, OverflowError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1874 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1878 * 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
|
1879 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1880 SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1881 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1885 * 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
|
1886 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1887 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
|
1888 "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
|
1889 "\n" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1890 "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
|
1891 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1895 * 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
|
1896 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1897 SimpleExtendsException(PyExc_StandardError, ReferenceError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1898 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1902 * 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
|
1903 */ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1904 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
|
1905 |
|
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
|
1906 /* |
|
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 * 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
|
1908 */ |
|
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 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
|
1910 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1911 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1912 /* 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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1915 * 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
|
1916 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1917 SimpleExtendsException(PyExc_Exception, Warning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1918 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1922 * 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
|
1923 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1924 SimpleExtendsException(PyExc_Warning, UserWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1925 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1929 * 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
|
1930 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1931 SimpleExtendsException(PyExc_Warning, DeprecationWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1932 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1936 * 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
|
1937 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1938 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
|
1939 "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
|
1940 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1944 * 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
|
1945 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1946 SimpleExtendsException(PyExc_Warning, SyntaxWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1947 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1951 * 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
|
1952 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1953 SimpleExtendsException(PyExc_Warning, RuntimeWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1954 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1958 * 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
|
1959 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1960 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
|
1961 "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
|
1962 "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
|
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 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1966 * 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
|
1967 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1968 SimpleExtendsException(PyExc_Warning, ImportWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1969 "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
|
1970 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1971 |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1972 /* |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1973 * UnicodeWarning extends Warning |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1974 */ |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1975 SimpleExtendsException(PyExc_Warning, UnicodeWarning, |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1976 "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
|
1977 "related to conversion problems."); |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1978 |
|
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
|
1979 /* |
|
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 * 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
|
1981 */ |
|
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 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
|
1983 "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
|
1984 "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
|
1985 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1986 /* 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
|
1987 * 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
|
1988 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1989 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
|
1990 |
|
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
|
1991 /* 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
|
1992 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
|
1993 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
|
1994 */ |
|
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 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
|
1996 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1997 /* 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
|
1998 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
|
1999 /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2000 {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
|
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 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2003 #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
|
2004 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
|
2005 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2006 #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
|
2007 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
|
2008 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
|
2009 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
|
2010 |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
2011 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
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
|
2012 /* crt variable checking in VisualStudio .NET 2005 */ |
|
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
|
2013 #include <crtdbg.h> |
|
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
|
2014 |
|
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
|
2015 static int prevCrtReportMode; |
|
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
|
2016 static _invalid_parameter_handler prevCrtHandler; |
|
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
|
2017 |
|
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
|
2018 /* Invalid parameter handler. Sets a ValueError exception */ |
|
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
|
2019 static void |
|
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
|
2020 InvalidParameterHandler( |
|
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
|
2021 const wchar_t * expression, |
|
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
|
2022 const wchar_t * function, |
|
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
|
2023 const wchar_t * file, |
|
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
|
2024 unsigned int line, |
|
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
|
2025 uintptr_t pReserved) |
|
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
|
2026 { |
|
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
|
2027 /* Do nothing, allow execution to continue. Usually this |
|
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
|
2028 * means that the CRT will set errno to EINVAL |
|
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
|
2029 */ |
|
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
|
2030 } |
|
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
|
2031 #endif |
|
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
|
2032 |
|
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
|
2033 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2034 PyMODINIT_FUNC |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
2035 _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
|
2036 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2037 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
|
2038 |
|
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(BaseException) |
|
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(Exception) |
|
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(StandardError) |
|
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(TypeError) |
|
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(StopIteration) |
|
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(GeneratorExit) |
|
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(SystemExit) |
|
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(KeyboardInterrupt) |
|
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(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2048 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
|
2049 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
|
2050 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
|
2051 #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
|
2052 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
|
2053 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2054 #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
|
2055 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
|
2056 #endif |
|
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(EOFError) |
|
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(RuntimeError) |
|
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(NotImplementedError) |
|
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(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2061 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
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 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
|
2067 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
|
2068 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
|
2069 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
|
2070 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
|
2071 #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
|
2072 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
|
2073 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
|
2074 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
|
2075 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2076 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
|
2077 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
|
2078 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
|
2079 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
|
2080 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
|
2081 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
|
2082 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
|
2083 PRE_INIT(MemoryError) |
| 48103 | 2084 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
|
2085 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
|
2086 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
|
2087 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
|
2088 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
|
2089 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
|
2090 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
|
2091 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
|
2092 PRE_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2093 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
|
2094 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
|
2095 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2096 m = Py_InitModule4("exceptions", functions, exceptions_doc, |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2097 (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
|
2098 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
|
2099 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2100 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
|
2101 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
|
2102 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
|
2103 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
|
2104 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
|
2105 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
|
2106 |
|
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(BaseException) |
|
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(Exception) |
|
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(StandardError) |
|
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(TypeError) |
|
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(StopIteration) |
|
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(GeneratorExit) |
|
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(SystemExit) |
|
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(KeyboardInterrupt) |
|
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(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2116 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
|
2117 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
|
2118 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
|
2119 #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
|
2120 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
|
2121 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2122 #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
|
2123 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
|
2124 #endif |
|
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(EOFError) |
|
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(RuntimeError) |
|
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(NotImplementedError) |
|
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(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2129 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
|
2130 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
|
2131 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
|
2132 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
|
2133 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
|
2134 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
|
2135 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
|
2136 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
|
2137 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
|
2138 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
|
2139 #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
|
2140 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
|
2141 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
|
2142 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
|
2143 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2144 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
|
2145 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
|
2146 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
|
2147 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
|
2148 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
|
2149 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
|
2150 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
|
2151 POST_INIT(MemoryError) |
| 48103 | 2152 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
|
2153 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
|
2154 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
|
2155 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
|
2156 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
|
2157 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
|
2158 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
|
2159 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
|
2160 POST_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2161 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
|
2162 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
|
2163 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2164 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
|
2165 if (!PyExc_MemoryErrorInst) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2166 Py_FatalError("Cannot pre-allocate MemoryError instance\n"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2167 |
|
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
|
2168 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
|
2169 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
|
2170 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
|
2171 "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
|
2172 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
|
2173 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
|
2174 (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
|
2175 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
|
2176 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
|
2177 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
|
2178 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
|
2179 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
|
2180 "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
|
2181 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
|
2182 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
|
2183 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
|
2184 "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
|
2185 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
|
2186 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
|
2187 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
|
2188 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
|
2189 } |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2190 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2191 Py_DECREF(bltinmod); |
|
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
|
2192 |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
2193 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
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
|
2194 /* Set CRT argument error handler */ |
|
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
|
2195 prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler); |
|
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
|
2196 /* turn off assertions in debug mode */ |
|
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
|
2197 prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0); |
|
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
|
2198 #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
|
2199 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2200 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2201 void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2202 _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
|
2203 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2204 Py_XDECREF(PyExc_MemoryErrorInst); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2205 PyExc_MemoryErrorInst = NULL; |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
2206 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
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
|
2207 /* reset CRT error handling */ |
|
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
|
2208 _set_invalid_parameter_handler(prevCrtHandler); |
|
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
|
2209 _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); |
|
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
|
2210 #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
|
2211 } |
