summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1999-02-24 00:35:43 (GMT)
committerBarry Warsaw <barry@python.org>1999-02-24 00:35:43 (GMT)
commit72b715d979151e4f1d0439bc922e0afc3eb770cc (patch)
treeeab797260250d6e5843a581c561a6e5b02aadb98 /Python/bltinmodule.c
parent40db48c5ec7ca447a7291062014e83b40cce9ee7 (diff)
downloadcpython-72b715d979151e4f1d0439bc922e0afc3eb770cc.zip
cpython-72b715d979151e4f1d0439bc922e0afc3eb770cc.tar.gz
cpython-72b715d979151e4f1d0439bc922e0afc3eb770cc.tar.bz2
(initerrors): Make sure that the exception tuples ("base-classes" when
string-based exceptions are used) reflect the real class hierarchy, i.e. that SystemExit derives from Exception not StandardError.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index f141f4d..d40c281 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2153,7 +2153,7 @@ static void
initerrors(dict)
PyObject *dict;
{
- int i;
+ int i, j;
int exccnt = 0;
for (i = 0; bltin_exc[i].name; i++, exccnt++) {
Py_XDECREF(*bltin_exc[i].exc);
@@ -2190,23 +2190,33 @@ initerrors(dict)
PyTuple_SET_ITEM(PyExc_EnvironmentError, 1, PyExc_OSError);
PyDict_SetItemString(dict, "EnvironmentError", PyExc_EnvironmentError);
- PyExc_StandardError = PyTuple_New(exccnt-2);
- for (i = 2; bltin_exc[i].name; i++) {
+ /* missing from the StandardError tuple: Exception, StandardError,
+ * and SystemExit
+ */
+ PyExc_StandardError = PyTuple_New(exccnt-3);
+ for (i = 2, j = 0; bltin_exc[i].name; i++) {
PyObject *exc = *bltin_exc[i].exc;
- Py_INCREF(exc);
- PyTuple_SET_ITEM(PyExc_StandardError, i-2, exc);
+ /* SystemExit is not an error, but it is an exception */
+ if (exc != PyExc_SystemExit) {
+ Py_INCREF(exc);
+ PyTuple_SET_ITEM(PyExc_StandardError, j++, exc);
+ }
}
PyDict_SetItemString(dict, "StandardError", PyExc_StandardError);
- /* Exception is treated differently; for now, it's == StandardError */
- PyExc_Exception = PyExc_StandardError;
- Py_INCREF(PyExc_Exception);
+ /* Exception is a 2-tuple */
+ PyExc_Exception = PyTuple_New(2);
+ Py_INCREF(PyExc_SystemExit);
+ PyTuple_SET_ITEM(PyExc_Exception, 0, PyExc_SystemExit);
+ Py_INCREF(PyExc_StandardError);
+ PyTuple_SET_ITEM(PyExc_Exception, 1, PyExc_StandardError);
PyDict_SetItemString(dict, "Exception", PyExc_Exception);
if (PyErr_Occurred())
Py_FatalError("Could not initialize built-in string exceptions");
}
+
static void
finierrors()
{