mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
(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.
This commit is contained in:
parent
40db48c5ec
commit
72b715d979
1 changed files with 18 additions and 8 deletions
|
@ -2153,7 +2153,7 @@ static void
|
||||||
initerrors(dict)
|
initerrors(dict)
|
||||||
PyObject *dict;
|
PyObject *dict;
|
||||||
{
|
{
|
||||||
int i;
|
int i, j;
|
||||||
int exccnt = 0;
|
int exccnt = 0;
|
||||||
for (i = 0; bltin_exc[i].name; i++, exccnt++) {
|
for (i = 0; bltin_exc[i].name; i++, exccnt++) {
|
||||||
Py_XDECREF(*bltin_exc[i].exc);
|
Py_XDECREF(*bltin_exc[i].exc);
|
||||||
|
@ -2190,23 +2190,33 @@ initerrors(dict)
|
||||||
PyTuple_SET_ITEM(PyExc_EnvironmentError, 1, PyExc_OSError);
|
PyTuple_SET_ITEM(PyExc_EnvironmentError, 1, PyExc_OSError);
|
||||||
PyDict_SetItemString(dict, "EnvironmentError", PyExc_EnvironmentError);
|
PyDict_SetItemString(dict, "EnvironmentError", PyExc_EnvironmentError);
|
||||||
|
|
||||||
PyExc_StandardError = PyTuple_New(exccnt-2);
|
/* missing from the StandardError tuple: Exception, StandardError,
|
||||||
for (i = 2; bltin_exc[i].name; i++) {
|
* and SystemExit
|
||||||
|
*/
|
||||||
|
PyExc_StandardError = PyTuple_New(exccnt-3);
|
||||||
|
for (i = 2, j = 0; bltin_exc[i].name; i++) {
|
||||||
PyObject *exc = *bltin_exc[i].exc;
|
PyObject *exc = *bltin_exc[i].exc;
|
||||||
|
/* SystemExit is not an error, but it is an exception */
|
||||||
|
if (exc != PyExc_SystemExit) {
|
||||||
Py_INCREF(exc);
|
Py_INCREF(exc);
|
||||||
PyTuple_SET_ITEM(PyExc_StandardError, i-2, exc);
|
PyTuple_SET_ITEM(PyExc_StandardError, j++, exc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(dict, "StandardError", PyExc_StandardError);
|
PyDict_SetItemString(dict, "StandardError", PyExc_StandardError);
|
||||||
|
|
||||||
/* Exception is treated differently; for now, it's == StandardError */
|
/* Exception is a 2-tuple */
|
||||||
PyExc_Exception = PyExc_StandardError;
|
PyExc_Exception = PyTuple_New(2);
|
||||||
Py_INCREF(PyExc_Exception);
|
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);
|
PyDict_SetItemString(dict, "Exception", PyExc_Exception);
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
Py_FatalError("Could not initialize built-in string exceptions");
|
Py_FatalError("Could not initialize built-in string exceptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
finierrors()
|
finierrors()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue