diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 154cde9316866e..28c7fdbd47ba8d 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -45,6 +45,13 @@ get_exc_state(void) * Lib/test/exception_hierarchy.txt */ +static inline PyBaseExceptionObject * +PyBaseExceptionObject_CAST(PyObject *exc) +{ + assert(PyExceptionInstance_Check(exc)); + return (PyBaseExceptionObject *)exc; +} + /* * BaseException */ @@ -77,8 +84,9 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } static int -BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) +BaseException_init(PyObject *op, PyObject *args, PyObject *kwds) { + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) return -1; @@ -121,8 +129,9 @@ BaseException_vectorcall(PyObject *type_obj, PyObject * const*args, static int -BaseException_clear(PyBaseExceptionObject *self) +BaseException_clear(PyObject *op) { + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); Py_CLEAR(self->dict); Py_CLEAR(self->args); Py_CLEAR(self->notes); @@ -133,21 +142,23 @@ BaseException_clear(PyBaseExceptionObject *self) } static void -BaseException_dealloc(PyBaseExceptionObject *self) +BaseException_dealloc(PyObject *op) { + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); PyObject_GC_UnTrack(self); // bpo-44348: The trashcan mechanism prevents stack overflow when deleting // long chains of exceptions. For example, exceptions can be chained // through the __context__ attributes or the __traceback__ attribute. Py_TRASHCAN_BEGIN(self, BaseException_dealloc) - BaseException_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)BaseException_clear(op); + Py_TYPE(self)->tp_free(self); Py_TRASHCAN_END } static int -BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg) +BaseException_traverse(PyObject *op, visitproc visit, void *arg) { + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); Py_VISIT(self->dict); Py_VISIT(self->args); Py_VISIT(self->notes); @@ -158,8 +169,10 @@ BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg) } static PyObject * -BaseException_str(PyBaseExceptionObject *self) +BaseException_str(PyObject *op) { + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); + PyObject *res; Py_BEGIN_CRITICAL_SECTION(self); switch (PyTuple_GET_SIZE(self->args)) { @@ -178,8 +191,11 @@ BaseException_str(PyBaseExceptionObject *self) } static PyObject * -BaseException_repr(PyBaseExceptionObject *self) +BaseException_repr(PyObject *op) { + + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); + PyObject *res; Py_BEGIN_CRITICAL_SECTION(self); const char *name = _PyType_Name(Py_TYPE(self)); @@ -270,13 +286,6 @@ BaseException_with_traceback_impl(PyBaseExceptionObject *self, PyObject *tb) return Py_NewRef(self); } -static inline PyBaseExceptionObject* -_PyBaseExceptionObject_cast(PyObject *exc) -{ - assert(PyExceptionInstance_Check(exc)); - return (PyBaseExceptionObject *)exc; -} - /*[clinic input] @critical_section BaseException.add_note @@ -512,7 +521,7 @@ PyException_GetTraceback(PyObject *self) { PyObject *traceback; Py_BEGIN_CRITICAL_SECTION(self); - traceback = Py_XNewRef(_PyBaseExceptionObject_cast(self)->traceback); + traceback = Py_XNewRef(PyBaseExceptionObject_CAST(self)->traceback); Py_END_CRITICAL_SECTION(); return traceback; } @@ -523,7 +532,7 @@ PyException_SetTraceback(PyObject *self, PyObject *tb) { int res; Py_BEGIN_CRITICAL_SECTION(self); - res = BaseException___traceback___set_impl(_PyBaseExceptionObject_cast(self), tb); + res = BaseException___traceback___set_impl(PyBaseExceptionObject_CAST(self), tb); Py_END_CRITICAL_SECTION(); return res; } @@ -533,7 +542,7 @@ PyException_GetCause(PyObject *self) { PyObject *cause; Py_BEGIN_CRITICAL_SECTION(self); - cause = Py_XNewRef(_PyBaseExceptionObject_cast(self)->cause); + cause = Py_XNewRef(PyBaseExceptionObject_CAST(self)->cause); Py_END_CRITICAL_SECTION(); return cause; } @@ -543,7 +552,7 @@ void PyException_SetCause(PyObject *self, PyObject *cause) { Py_BEGIN_CRITICAL_SECTION(self); - PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); + PyBaseExceptionObject *base_self = PyBaseExceptionObject_CAST(self); base_self->suppress_context = 1; Py_XSETREF(base_self->cause, cause); Py_END_CRITICAL_SECTION(); @@ -554,7 +563,7 @@ PyException_GetContext(PyObject *self) { PyObject *context; Py_BEGIN_CRITICAL_SECTION(self); - context = Py_XNewRef(_PyBaseExceptionObject_cast(self)->context); + context = Py_XNewRef(PyBaseExceptionObject_CAST(self)->context); Py_END_CRITICAL_SECTION(); return context; } @@ -564,7 +573,7 @@ void PyException_SetContext(PyObject *self, PyObject *context) { Py_BEGIN_CRITICAL_SECTION(self); - Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context); + Py_XSETREF(PyBaseExceptionObject_CAST(self)->context, context); Py_END_CRITICAL_SECTION(); } @@ -573,7 +582,7 @@ PyException_GetArgs(PyObject *self) { PyObject *args; Py_BEGIN_CRITICAL_SECTION(self); - args = Py_NewRef(_PyBaseExceptionObject_cast(self)->args); + args = Py_NewRef(PyBaseExceptionObject_CAST(self)->args); Py_END_CRITICAL_SECTION(); return args; } @@ -583,7 +592,7 @@ PyException_SetArgs(PyObject *self, PyObject *args) { Py_BEGIN_CRITICAL_SECTION(self); Py_INCREF(args); - Py_XSETREF(_PyBaseExceptionObject_cast(self)->args, args); + Py_XSETREF(PyBaseExceptionObject_CAST(self)->args, args); Py_END_CRITICAL_SECTION(); } @@ -606,26 +615,26 @@ static PyTypeObject _PyExc_BaseException = { "BaseException", /*tp_name*/ sizeof(PyBaseExceptionObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ - (destructor)BaseException_dealloc, /*tp_dealloc*/ + BaseException_dealloc, /*tp_dealloc*/ 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_as_async*/ - (reprfunc)BaseException_repr, /*tp_repr*/ + BaseException_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ - (reprfunc)BaseException_str, /*tp_str*/ + BaseException_str, /*tp_str*/ PyObject_GenericGetAttr, /*tp_getattro*/ PyObject_GenericSetAttr, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/ PyDoc_STR("Common base class for all exceptions"), /* tp_doc */ - (traverseproc)BaseException_traverse, /* tp_traverse */ - (inquiry)BaseException_clear, /* tp_clear */ + BaseException_traverse, /* tp_traverse */ + BaseException_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ @@ -638,7 +647,7 @@ static PyTypeObject _PyExc_BaseException = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ offsetof(PyBaseExceptionObject, dict), /* tp_dictoffset */ - (initproc)BaseException_init, /* tp_init */ + BaseException_init, /* tp_init */ 0, /* tp_alloc */ BaseException_new, /* tp_new */ .tp_vectorcall = BaseException_vectorcall, @@ -656,13 +665,13 @@ static PyTypeObject _PyExc_ ## EXCNAME = { \ PyVarObject_HEAD_INIT(NULL, 0) \ # EXCNAME, \ sizeof(PyBaseExceptionObject), \ - 0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \ + 0, BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, \ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ - PyDoc_STR(EXCDOC), (traverseproc)BaseException_traverse, \ - (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ + PyDoc_STR(EXCDOC), BaseException_traverse, \ + BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ 0, 0, 0, offsetof(PyBaseExceptionObject, dict), \ - (initproc)BaseException_init, 0, BaseException_new,\ + BaseException_init, 0, BaseException_new,\ }; \ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME @@ -671,13 +680,13 @@ PyTypeObject _PyExc_ ## EXCNAME = { \ PyVarObject_HEAD_INIT(NULL, 0) \ # PYEXCNAME, \ sizeof(Py ## EXCSTORE ## Object), \ - 0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, \ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ - PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ - (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ + PyDoc_STR(EXCDOC), EXCSTORE ## _traverse, \ + EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ - (initproc)EXCSTORE ## _init, 0, 0, \ + EXCSTORE ## _init, 0, 0, \ }; #define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \ @@ -692,14 +701,14 @@ static PyTypeObject _PyExc_ ## EXCNAME = { \ PyVarObject_HEAD_INIT(NULL, 0) \ # EXCNAME, \ sizeof(Py ## EXCSTORE ## Object), 0, \ - (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ - (reprfunc)EXCSTR, 0, 0, 0, \ + EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ + EXCSTR, 0, 0, 0, \ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ - PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ - (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \ + PyDoc_STR(EXCDOC), EXCSTORE ## _traverse, \ + EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \ EXCMEMBERS, EXCGETSET, &_ ## EXCBASE, \ 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ - (initproc)EXCSTORE ## _init, 0, EXCNEW,\ + EXCSTORE ## _init, 0, EXCNEW,\ }; \ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME @@ -735,14 +744,22 @@ static PyMemberDef StopIteration_members[] = { {NULL} /* Sentinel */ }; +static inline PyStopIterationObject * +PyStopIterationObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_StopIteration)); + return (PyStopIterationObject *)self; +} + static int -StopIteration_init(PyStopIterationObject *self, PyObject *args, PyObject *kwds) +StopIteration_init(PyObject *op, PyObject *args, PyObject *kwds) { Py_ssize_t size = PyTuple_GET_SIZE(args); PyObject *value; - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) + if (BaseException_init(op, args, kwds) == -1) return -1; + PyStopIterationObject *self = PyStopIterationObject_CAST(op); Py_CLEAR(self->value); if (size > 0) value = PyTuple_GET_ITEM(args, 0); @@ -753,25 +770,27 @@ StopIteration_init(PyStopIterationObject *self, PyObject *args, PyObject *kwds) } static int -StopIteration_clear(PyStopIterationObject *self) +StopIteration_clear(PyObject *op) { + PyStopIterationObject *self = PyStopIterationObject_CAST(op); Py_CLEAR(self->value); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -StopIteration_dealloc(PyStopIterationObject *self) +StopIteration_dealloc(PyObject *self) { PyObject_GC_UnTrack(self); - StopIteration_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)StopIteration_clear(self); + Py_TYPE(self)->tp_free(self); } static int -StopIteration_traverse(PyStopIterationObject *self, visitproc visit, void *arg) +StopIteration_traverse(PyObject *op, visitproc visit, void *arg) { + PyStopIterationObject *self = PyStopIterationObject_CAST(op); Py_VISIT(self->value); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } ComplexExtendsException(PyExc_Exception, StopIteration, StopIteration, @@ -790,14 +809,22 @@ SimpleExtendsException(PyExc_BaseException, GeneratorExit, * SystemExit extends BaseException */ +static inline PySystemExitObject * +PySystemExitObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_SystemExit)); + return (PySystemExitObject *)self; +} + static int -SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) +SystemExit_init(PyObject *op, PyObject *args, PyObject *kwds) { Py_ssize_t size = PyTuple_GET_SIZE(args); - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) + if (BaseException_init(op, args, kwds) == -1) return -1; + PySystemExitObject *self = PySystemExitObject_CAST(op); if (size == 0) return 0; if (size == 1) { @@ -810,25 +837,27 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) } static int -SystemExit_clear(PySystemExitObject *self) +SystemExit_clear(PyObject *op) { + PySystemExitObject *self = PySystemExitObject_CAST(op); Py_CLEAR(self->code); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -SystemExit_dealloc(PySystemExitObject *self) +SystemExit_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - SystemExit_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)SystemExit_clear(self); + Py_TYPE(self)->tp_free(self); } static int -SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg) +SystemExit_traverse(PyObject *op, visitproc visit, void *arg) { + PySystemExitObject *self = PySystemExitObject_CAST(op); Py_VISIT(self->code); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } static PyMemberDef SystemExit_members[] = { @@ -848,7 +877,7 @@ ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit, static inline PyBaseExceptionGroupObject* -_PyBaseExceptionGroupObject_cast(PyObject *exc) +PyBaseExceptionGroupObject_CAST(PyObject *exc) { assert(_PyBaseExceptionGroup_Check(exc)); return (PyBaseExceptionGroupObject *)exc; @@ -954,7 +983,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds) cls = (PyTypeObject*)PyExc_BaseExceptionGroup; } PyBaseExceptionGroupObject *self = - _PyBaseExceptionGroupObject_cast(BaseException_new(cls, args, kwds)); + PyBaseExceptionGroupObject_CAST(BaseException_new(cls, args, kwds)); if (!self) { goto error; } @@ -985,46 +1014,47 @@ _PyExc_CreateExceptionGroup(const char *msg_str, PyObject *excs) } static int -BaseExceptionGroup_init(PyBaseExceptionGroupObject *self, - PyObject *args, PyObject *kwds) +BaseExceptionGroup_init(PyObject *self, PyObject *args, PyObject *kwds) { if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) { return -1; } - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) { + if (BaseException_init(self, args, kwds) == -1) { return -1; } return 0; } static int -BaseExceptionGroup_clear(PyBaseExceptionGroupObject *self) +BaseExceptionGroup_clear(PyObject *op) { + PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op); Py_CLEAR(self->msg); Py_CLEAR(self->excs); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -BaseExceptionGroup_dealloc(PyBaseExceptionGroupObject *self) +BaseExceptionGroup_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - BaseExceptionGroup_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)BaseExceptionGroup_clear(self); + Py_TYPE(self)->tp_free(self); } static int -BaseExceptionGroup_traverse(PyBaseExceptionGroupObject *self, - visitproc visit, void *arg) +BaseExceptionGroup_traverse(PyObject *op, visitproc visit, void *arg) { + PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op); Py_VISIT(self->msg); Py_VISIT(self->excs); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } static PyObject * -BaseExceptionGroup_str(PyBaseExceptionGroupObject *self) +BaseExceptionGroup_str(PyObject *op) { + PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op); assert(self->msg); assert(PyUnicode_Check(self->msg)); @@ -1259,7 +1289,7 @@ exceptiongroup_split_recursive(PyObject *exc, /* Partial match */ - PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc); + PyBaseExceptionGroupObject *eg = PyBaseExceptionGroupObject_CAST(exc); assert(PyTuple_CheckExact(eg->excs)); Py_ssize_t num_excs = PyTuple_Size(eg->excs); if (num_excs < 0) { @@ -1428,7 +1458,7 @@ collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids) Py_DECREF(exc_id); return res; } - PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc); + PyBaseExceptionGroupObject *eg = PyBaseExceptionGroupObject_CAST(exc); Py_ssize_t num_excs = PyTuple_GET_SIZE(eg->excs); /* recursive calls */ for (Py_ssize_t i = 0; i < num_excs; i++) { @@ -1525,7 +1555,7 @@ _PyExc_PrepReraiseStar(PyObject *orig, PyObject *excs) { /* orig must be a raised & caught exception, so it has a traceback */ assert(PyExceptionInstance_Check(orig)); - assert(_PyBaseExceptionObject_cast(orig)->traceback != NULL); + assert(PyBaseExceptionObject_CAST(orig)->traceback != NULL); assert(PyList_Check(excs)); @@ -1658,7 +1688,7 @@ static PyMemberDef BaseExceptionGroup_members[] = { }; static PyMethodDef BaseExceptionGroup_methods[] = { - {"__class_getitem__", (PyCFunction)Py_GenericAlias, + {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, BASEEXCEPTIONGROUP_DERIVE_METHODDEF BASEEXCEPTIONGROUP_SPLIT_METHODDEF @@ -1704,8 +1734,15 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt, * ImportError extends Exception */ +static inline PyImportErrorObject * +PyImportErrorObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_ImportError)); + return (PyImportErrorObject *)self; +} + static int -ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) +ImportError_init(PyObject *op, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"name", "path", "name_from", 0}; PyObject *empty_tuple; @@ -1714,9 +1751,10 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) PyObject *path = NULL; PyObject *name_from = NULL; - if (BaseException_init((PyBaseExceptionObject *)self, args, NULL) == -1) + if (BaseException_init(op, args, NULL) == -1) return -1; + PyImportErrorObject *self = PyImportErrorObject_CAST(op); empty_tuple = PyTuple_New(0); if (!empty_tuple) return -1; @@ -1740,48 +1778,50 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) } static int -ImportError_clear(PyImportErrorObject *self) +ImportError_clear(PyObject *op) { + PyImportErrorObject *self = PyImportErrorObject_CAST(op); Py_CLEAR(self->msg); Py_CLEAR(self->name); Py_CLEAR(self->path); Py_CLEAR(self->name_from); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -ImportError_dealloc(PyImportErrorObject *self) +ImportError_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - ImportError_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)ImportError_clear(self); + Py_TYPE(self)->tp_free(self); } static int -ImportError_traverse(PyImportErrorObject *self, visitproc visit, void *arg) +ImportError_traverse(PyObject *op, visitproc visit, void *arg) { + PyImportErrorObject *self = PyImportErrorObject_CAST(op); Py_VISIT(self->msg); Py_VISIT(self->name); Py_VISIT(self->path); Py_VISIT(self->name_from); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } static PyObject * -ImportError_str(PyImportErrorObject *self) +ImportError_str(PyObject *op) { + PyImportErrorObject *self = PyImportErrorObject_CAST(op); if (self->msg && PyUnicode_CheckExact(self->msg)) { return Py_NewRef(self->msg); } - else { - return BaseException_str((PyBaseExceptionObject *)self); - } + return BaseException_str(op); } static PyObject * -ImportError_getstate(PyImportErrorObject *self) +ImportError_getstate(PyObject *op) { - PyObject *dict = ((PyBaseExceptionObject *)self)->dict; + PyImportErrorObject *self = PyImportErrorObject_CAST(op); + PyObject *dict = self->dict; if (self->name || self->path || self->name_from) { dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) @@ -1810,18 +1850,17 @@ ImportError_getstate(PyImportErrorObject *self) /* Pickling support */ static PyObject * -ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored)) +ImportError_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *res; - PyObject *args; PyObject *state = ImportError_getstate(self); if (state == NULL) return NULL; - args = ((PyBaseExceptionObject *)self)->args; + PyBaseExceptionObject *exc = PyBaseExceptionObject_CAST(self); if (state == Py_None) - res = PyTuple_Pack(2, Py_TYPE(self), args); + res = PyTuple_Pack(2, Py_TYPE(self), exc->args); else - res = PyTuple_Pack(3, Py_TYPE(self), args, state); + res = PyTuple_Pack(3, Py_TYPE(self), exc->args, state); Py_DECREF(state); return res; } @@ -1839,7 +1878,7 @@ static PyMemberDef ImportError_members[] = { }; static PyMethodDef ImportError_methods[] = { - {"__reduce__", (PyCFunction)ImportError_reduce, METH_NOARGS}, + {"__reduce__", ImportError_reduce, METH_NOARGS}, {NULL} }; @@ -1861,6 +1900,13 @@ MiddlingExtendsException(PyExc_ImportError, ModuleNotFoundError, ImportError, * OSError extends Exception */ +static inline PyOSErrorObject * +PyOSErrorObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_OSError)); + return (PyOSErrorObject *)self; +} + #ifdef MS_WINDOWS #include "errmap.h" #endif @@ -1997,7 +2043,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args, static PyObject * OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds); static int -OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds); +OSError_init(PyObject *self, PyObject *args, PyObject *kwds); static int oserror_use_init(PyTypeObject *type) @@ -2012,8 +2058,7 @@ oserror_use_init(PyTypeObject *type) (see http://bugs.python.org/issue12555#msg148829 ) */ - if (type->tp_init != (initproc) OSError_init && - type->tp_new == (newfunc) OSError_new) { + if (type->tp_init != OSError_init && type->tp_new == OSError_new) { assert((PyObject *) type != PyExc_OSError); return 1; } @@ -2089,8 +2134,9 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } static int -OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds) +OSError_init(PyObject *op, PyObject *args, PyObject *kwds) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); PyObject *myerrno = NULL, *strerror = NULL; PyObject *filename = NULL, *filename2 = NULL; #ifdef MS_WINDOWS @@ -2127,8 +2173,9 @@ OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds) } static int -OSError_clear(PyOSErrorObject *self) +OSError_clear(PyObject *op) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); Py_CLEAR(self->myerrno); Py_CLEAR(self->strerror); Py_CLEAR(self->filename); @@ -2136,21 +2183,21 @@ OSError_clear(PyOSErrorObject *self) #ifdef MS_WINDOWS Py_CLEAR(self->winerror); #endif - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -OSError_dealloc(PyOSErrorObject *self) +OSError_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - OSError_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)OSError_clear(self); + Py_TYPE(self)->tp_free(self); } static int -OSError_traverse(PyOSErrorObject *self, visitproc visit, - void *arg) +OSError_traverse(PyObject *op, visitproc visit, void *arg) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); Py_VISIT(self->myerrno); Py_VISIT(self->strerror); Py_VISIT(self->filename); @@ -2158,12 +2205,13 @@ OSError_traverse(PyOSErrorObject *self, visitproc visit, #ifdef MS_WINDOWS Py_VISIT(self->winerror); #endif - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } static PyObject * -OSError_str(PyOSErrorObject *self) +OSError_str(PyObject *op) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); #define OR_NONE(x) ((x)?(x):Py_None) #ifdef MS_WINDOWS /* If available, winerror has the priority over myerrno */ @@ -2203,12 +2251,13 @@ OSError_str(PyOSErrorObject *self) if (self->myerrno && self->strerror) return PyUnicode_FromFormat("[Errno %S] %S", self->myerrno, self->strerror); - return BaseException_str((PyBaseExceptionObject *)self); + return BaseException_str(op); } static PyObject * -OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) +OSError_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); PyObject *args = self->args; PyObject *res = NULL; @@ -2247,8 +2296,9 @@ OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject * -OSError_written_get(PyOSErrorObject *self, void *context) +OSError_written_get(PyObject *op, void *context) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); if (self->written == -1) { PyErr_SetString(PyExc_AttributeError, "characters_written"); return NULL; @@ -2257,8 +2307,9 @@ OSError_written_get(PyOSErrorObject *self, void *context) } static int -OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context) +OSError_written_set(PyObject *op, PyObject *arg, void *context) { + PyOSErrorObject *self = PyOSErrorObject_CAST(op); if (arg == NULL) { if (self->written == -1) { PyErr_SetString(PyExc_AttributeError, "characters_written"); @@ -2292,13 +2343,13 @@ static PyMemberDef OSError_members[] = { }; static PyMethodDef OSError_methods[] = { - {"__reduce__", (PyCFunction)OSError_reduce, METH_NOARGS}, + {"__reduce__", OSError_reduce, METH_NOARGS}, {NULL} }; static PyGetSetDef OSError_getset[] = { - {"characters_written", (getter) OSError_written_get, - (setter) OSError_written_set, NULL}, + {"characters_written", OSError_written_get, + OSError_written_set, NULL}, {NULL} }; @@ -2377,13 +2428,20 @@ SimpleExtendsException(PyExc_RuntimeError, NotImplementedError, * NameError extends Exception */ +static inline PyNameErrorObject * +PyNameErrorObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_NameError)); + return (PyNameErrorObject *)self; +} + static int -NameError_init(PyNameErrorObject *self, PyObject *args, PyObject *kwds) +NameError_init(PyObject *op, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"name", NULL}; PyObject *name = NULL; - if (BaseException_init((PyBaseExceptionObject *)self, args, NULL) == -1) { + if (BaseException_init(op, args, NULL) == -1) { return -1; } @@ -2398,31 +2456,34 @@ NameError_init(PyNameErrorObject *self, PyObject *args, PyObject *kwds) } Py_DECREF(empty_tuple); + PyNameErrorObject *self = PyNameErrorObject_CAST(op); Py_XSETREF(self->name, Py_XNewRef(name)); return 0; } static int -NameError_clear(PyNameErrorObject *self) +NameError_clear(PyObject *op) { + PyNameErrorObject *self = PyNameErrorObject_CAST(op); Py_CLEAR(self->name); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -NameError_dealloc(PyNameErrorObject *self) +NameError_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - NameError_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)NameError_clear(self); + Py_TYPE(self)->tp_free(self); } static int -NameError_traverse(PyNameErrorObject *self, visitproc visit, void *arg) +NameError_traverse(PyObject *op, visitproc visit, void *arg) { + PyNameErrorObject *self = PyNameErrorObject_CAST(op); Py_VISIT(self->name); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } static PyMemberDef NameError_members[] = { @@ -2450,14 +2511,21 @@ MiddlingExtendsException(PyExc_NameError, UnboundLocalError, NameError, * AttributeError extends Exception */ +static inline PyAttributeErrorObject * +PyAttributeErrorObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_AttributeError)); + return (PyAttributeErrorObject *)self; +} + static int -AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds) +AttributeError_init(PyObject *op, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"name", "obj", NULL}; PyObject *name = NULL; PyObject *obj = NULL; - if (BaseException_init((PyBaseExceptionObject *)self, args, NULL) == -1) { + if (BaseException_init(op, args, NULL) == -1) { return -1; } @@ -2472,6 +2540,7 @@ AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds } Py_DECREF(empty_tuple); + PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op); Py_XSETREF(self->name, Py_XNewRef(name)); Py_XSETREF(self->obj, Py_XNewRef(obj)); @@ -2479,34 +2548,37 @@ AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds } static int -AttributeError_clear(PyAttributeErrorObject *self) +AttributeError_clear(PyObject *op) { + PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op); Py_CLEAR(self->obj); Py_CLEAR(self->name); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -AttributeError_dealloc(PyAttributeErrorObject *self) +AttributeError_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - AttributeError_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)AttributeError_clear(self); + Py_TYPE(self)->tp_free(self); } static int -AttributeError_traverse(PyAttributeErrorObject *self, visitproc visit, void *arg) +AttributeError_traverse(PyObject *op, visitproc visit, void *arg) { + PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op); Py_VISIT(self->obj); Py_VISIT(self->name); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } /* Pickling support */ static PyObject * -AttributeError_getstate(PyAttributeErrorObject *self, PyObject *Py_UNUSED(ignored)) +AttributeError_getstate(PyObject *op, PyObject *Py_UNUSED(ignored)) { - PyObject *dict = ((PyAttributeErrorObject *)self)->dict; + PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op); + PyObject *dict = self->dict; if (self->name || self->args) { dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) { @@ -2532,13 +2604,14 @@ AttributeError_getstate(PyAttributeErrorObject *self, PyObject *Py_UNUSED(ignore } static PyObject * -AttributeError_reduce(PyAttributeErrorObject *self, PyObject *Py_UNUSED(ignored)) +AttributeError_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) { - PyObject *state = AttributeError_getstate(self, NULL); + PyObject *state = AttributeError_getstate(op, NULL); if (state == NULL) { return NULL; } + PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op); PyObject *return_value = PyTuple_Pack(3, Py_TYPE(self), self->args, state); Py_DECREF(state); return return_value; @@ -2551,8 +2624,8 @@ static PyMemberDef AttributeError_members[] = { }; static PyMethodDef AttributeError_methods[] = { - {"__getstate__", (PyCFunction)AttributeError_getstate, METH_NOARGS}, - {"__reduce__", (PyCFunction)AttributeError_reduce, METH_NOARGS }, + {"__getstate__", AttributeError_getstate, METH_NOARGS}, + {"__reduce__", AttributeError_reduce, METH_NOARGS }, {NULL} }; @@ -2565,15 +2638,23 @@ ComplexExtendsException(PyExc_Exception, AttributeError, * SyntaxError extends Exception */ +static inline PySyntaxErrorObject * +PySyntaxErrorObject_CAST(PyObject *self) +{ + assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_SyntaxError)); + return (PySyntaxErrorObject *)self; +} + static int -SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) +SyntaxError_init(PyObject *op, PyObject *args, PyObject *kwds) { PyObject *info = NULL; Py_ssize_t lenargs = PyTuple_GET_SIZE(args); - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) + if (BaseException_init(op, args, kwds) == -1) return -1; + PySyntaxErrorObject *self = PySyntaxErrorObject_CAST(op); if (lenargs >= 1) { Py_XSETREF(self->msg, Py_NewRef(PyTuple_GET_ITEM(args, 0))); } @@ -2611,8 +2692,9 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) } static int -SyntaxError_clear(PySyntaxErrorObject *self) +SyntaxError_clear(PyObject *op) { + PySyntaxErrorObject *self = PySyntaxErrorObject_CAST(op); Py_CLEAR(self->msg); Py_CLEAR(self->filename); Py_CLEAR(self->lineno); @@ -2621,20 +2703,21 @@ SyntaxError_clear(PySyntaxErrorObject *self) Py_CLEAR(self->end_offset); Py_CLEAR(self->text); Py_CLEAR(self->print_file_and_line); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(op); } static void -SyntaxError_dealloc(PySyntaxErrorObject *self) +SyntaxError_dealloc(PyObject *self) { _PyObject_GC_UNTRACK(self); - SyntaxError_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); + (void)SyntaxError_clear(self); + Py_TYPE(self)->tp_free(self); } static int -SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) +SyntaxError_traverse(PyObject *op, visitproc visit, void *arg) { + PySyntaxErrorObject *self = PySyntaxErrorObject_CAST(op); Py_VISIT(self->msg); Py_VISIT(self->filename); Py_VISIT(self->lineno); @@ -2643,7 +2726,7 @@ SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) Py_VISIT(self->end_offset); Py_VISIT(self->text); Py_VISIT(self->print_file_and_line); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(op, visit, arg); } /* This is called "my_basename" instead of just "basename" to avoid name @@ -2675,8 +2758,9 @@ my_basename(PyObject *name) static PyObject * -SyntaxError_str(PySyntaxErrorObject *self) +SyntaxError_str(PyObject *op) { + PySyntaxErrorObject *self = PySyntaxErrorObject_CAST(op); int have_lineno = 0; PyObject *filename; PyObject *result; @@ -2779,8 +2863,9 @@ SimpleExtendsException(PyExc_LookupError, IndexError, /* * KeyError extends LookupError */ + static PyObject * -KeyError_str(PyBaseExceptionObject *self) +KeyError_str(PyObject *op) { /* If args is a tuple of exactly one item, apply repr to args[0]. This is done so that e.g. the exception raised by {}[''] prints @@ -2791,10 +2876,11 @@ KeyError_str(PyBaseExceptionObject *self) string, that string will be displayed in quotes. Too bad. If args is anything else, use the default BaseException__str__(). */ + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); if (PyTuple_GET_SIZE(self->args) == 1) { return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0)); } - return BaseException_str(self); + return BaseException_str(op); } ComplexExtendsException(PyExc_LookupError, KeyError, BaseException, @@ -3038,6 +3124,10 @@ unicode_error_adjust_end(Py_ssize_t end, Py_ssize_t objlen) return end; } +#define PyUnicodeError_Check(PTR) \ + PyObject_TypeCheck((PTR), (PyTypeObject *)PyExc_UnicodeError) +#define PyUnicodeErrorObject_CAST(op) \ + (assert(PyUnicodeError_Check(op)), ((PyUnicodeErrorObject *)(op))) /* Assert some properties of the adjusted 'end' value. */ #ifndef NDEBUG @@ -3408,11 +3498,11 @@ PyUnicodeTranslateError_SetReason(PyObject *self, const char *reason) static int UnicodeError_clear(PyObject *self) { - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); Py_CLEAR(exc->encoding); Py_CLEAR(exc->object); Py_CLEAR(exc->reason); - return BaseException_clear((PyBaseExceptionObject *)self); + return BaseException_clear(self); } static void @@ -3427,11 +3517,11 @@ UnicodeError_dealloc(PyObject *self) static int UnicodeError_traverse(PyObject *self, visitproc visit, void *arg) { - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); Py_VISIT(exc->encoding); Py_VISIT(exc->object); Py_VISIT(exc->reason); - return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); + return BaseException_traverse(self, visit, arg); } static PyMemberDef UnicodeError_members[] = { @@ -3456,7 +3546,7 @@ static PyMemberDef UnicodeError_members[] = { static int UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) { - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) { + if (BaseException_init(self, args, kwds) == -1) { return -1; } @@ -3469,7 +3559,7 @@ UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) return -1; } - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); Py_XSETREF(exc->encoding, Py_NewRef(encoding)); Py_XSETREF(exc->object, Py_NewRef(object)); exc->start = start; @@ -3481,7 +3571,7 @@ UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * UnicodeEncodeError_str(PyObject *self) { - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); PyObject *result = NULL; PyObject *reason_str = NULL; PyObject *encoding_str = NULL; @@ -3542,13 +3632,13 @@ static PyTypeObject _PyExc_UnicodeEncodeError = { PyVarObject_HEAD_INIT(NULL, 0) "UnicodeEncodeError", sizeof(PyUnicodeErrorObject), 0, - (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (reprfunc)UnicodeEncodeError_str, 0, 0, 0, + UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + UnicodeEncodeError_str, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse, - (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, + PyDoc_STR("Unicode encoding error."), UnicodeError_traverse, + UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeEncodeError_init, 0, BaseException_new, + UnicodeEncodeError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; @@ -3560,7 +3650,7 @@ PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; static int UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) { - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) { + if (BaseException_init(self, args, kwds) == -1) { return -1; } @@ -3589,7 +3679,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) } } - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); Py_XSETREF(exc->encoding, Py_NewRef(encoding)); Py_XSETREF(exc->object, object /* already a strong reference */); exc->start = start; @@ -3601,7 +3691,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * UnicodeDecodeError_str(PyObject *self) { - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); PyObject *result = NULL; PyObject *reason_str = NULL; PyObject *encoding_str = NULL; @@ -3652,13 +3742,13 @@ static PyTypeObject _PyExc_UnicodeDecodeError = { PyVarObject_HEAD_INIT(NULL, 0) "UnicodeDecodeError", sizeof(PyUnicodeErrorObject), 0, - (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (reprfunc)UnicodeDecodeError_str, 0, 0, 0, + UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + UnicodeDecodeError_str, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse, - (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, + PyDoc_STR("Unicode decoding error."), UnicodeError_traverse, + UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeDecodeError_init, 0, BaseException_new, + UnicodeDecodeError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError; @@ -3679,7 +3769,7 @@ PyUnicodeDecodeError_Create( static int UnicodeTranslateError_init(PyObject *self, PyObject *args, PyObject *kwds) { - if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) { + if (BaseException_init(self, args, kwds) == -1) { return -1; } @@ -3690,7 +3780,7 @@ UnicodeTranslateError_init(PyObject *self, PyObject *args, PyObject *kwds) return -1; } - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); Py_XSETREF(exc->object, Py_NewRef(object)); exc->start = start; exc->end = end; @@ -3702,7 +3792,7 @@ UnicodeTranslateError_init(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * UnicodeTranslateError_str(PyObject *self) { - PyUnicodeErrorObject *exc = PyUnicodeError_CAST(self); + PyUnicodeErrorObject *exc = PyUnicodeErrorObject_CAST(self); PyObject *result = NULL; PyObject *reason_str = NULL; @@ -3755,13 +3845,13 @@ static PyTypeObject _PyExc_UnicodeTranslateError = { PyVarObject_HEAD_INIT(NULL, 0) "UnicodeTranslateError", sizeof(PyUnicodeErrorObject), 0, - (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (reprfunc)UnicodeTranslateError_str, 0, 0, 0, + UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + UnicodeTranslateError_str, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse, - (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, + PyDoc_STR("Unicode translation error."), UnicodeError_traverse, + UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeTranslateError_init, 0, BaseException_new, + UnicodeTranslateError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; @@ -3899,17 +3989,17 @@ _PyErr_NoMemory(PyThreadState *tstate) } static void -MemoryError_dealloc(PyObject *obj) +MemoryError_dealloc(PyObject *op) { - PyBaseExceptionObject *self = (PyBaseExceptionObject *)obj; + PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op); _PyObject_GC_UNTRACK(self); - BaseException_clear(self); + (void)BaseException_clear(op); /* If this is a subclass of MemoryError, we don't need to * do anything in the free-list*/ if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) { - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free(op); return; } @@ -3954,7 +4044,7 @@ free_preallocated_memerrors(struct _Py_exc_state *state) while (state->memerrors_freelist != NULL) { PyObject *self = (PyObject *) state->memerrors_freelist; state->memerrors_freelist = (PyBaseExceptionObject *)state->memerrors_freelist->dict; - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free(self); } } @@ -3966,10 +4056,10 @@ PyTypeObject _PyExc_MemoryError = { 0, MemoryError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Out of memory."), (traverseproc)BaseException_traverse, - (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_PyExc_Exception, + PyDoc_STR("Out of memory."), BaseException_traverse, + BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_PyExc_Exception, 0, 0, 0, offsetof(PyBaseExceptionObject, dict), - (initproc)BaseException_init, 0, MemoryError_new + BaseException_init, 0, MemoryError_new }; PyObject *PyExc_MemoryError = (PyObject *) &_PyExc_MemoryError; @@ -4231,7 +4321,7 @@ _PyExc_InitTypes(PyInterpreterState *interp) return -1; } if (exc->tp_new == BaseException_new - && exc->tp_init == (initproc)BaseException_init) + && exc->tp_init == BaseException_init) { exc->tp_vectorcall = BaseException_vectorcall; }