8000 fix UBSan failures for `PyBaseExceptionGroupObject` · python/cpython@0437291 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0437291

Browse files
committed
fix UBSan failures for PyBaseExceptionGroupObject
1 parent 96430d9 commit 0437291

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Objects/exceptions.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit,
759759

760760

761761
static inline PyBaseExceptionGroupObject*
762-
_PyBaseExceptionGroupObject_cast(PyObject *exc)
762+
_PyBaseExceptionGroup_CAST(PyObject *exc)
763763
{
764764
assert(_PyBaseExceptionGroup_Check(exc));
765765
return (PyBaseExceptionGroupObject *)exc;
@@ -865,7 +865,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
865865
cls = (PyTypeObject*)PyExc_BaseExceptionGroup;
866866
}
867867
PyBaseExceptionGroupObject *self =
868-
_PyBaseExceptionGroupObject_cast(BaseException_new(cls, args, kwds));
868+
_PyBaseExceptionGroup_CAST(BaseException_new(cls, args, kwds));
869869
if (!self) {
870870
goto error;
871871
}
@@ -896,46 +896,47 @@ _PyExc_CreateExceptionGroup(const char *msg_str, PyObject *excs)
896896
}
897897

898898
static int
899-
BaseExceptionGroup_init(PyBaseExceptionGroupObject *self,
900-
PyObject *args, PyObject *kwds)
899+
BaseExceptionGroup_init(PyObject *self, PyObject *args, PyObject *kwds)
901900
{
902901
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) {
903902
return -1;
904903
}
905-
if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) {
904+
if (BaseException_init(self, args, kwds) == -1) {
906905
return -1;
907906
}
908907
return 0;
909908
}
910909

911910
static int
912-
BaseExceptionGroup_clear(PyBaseExceptionGroupObject *self)
911+
BaseExceptionGroup_clear(PyObject *op)
913912
{
913+
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
914914
Py_CLEAR(self->msg);
915915
Py_CLEAR(self->excs);
916-
return BaseException_clear((PyBaseExceptionObject *)self);
916+
return BaseException_clear(op);
917917
}
918918

919919
static void
920-
BaseExceptionGroup_dealloc(PyBaseExceptionGroupObject *self)
920+
BaseExceptionGroup_dealloc(PyObject *self)
921921
{
922922
_PyObject_GC_UNTRACK(self);
923-
BaseExceptionGroup_clear(self);
924-
Py_TYPE(self)->tp_free((PyObject *)self);
923+
(void)BaseExceptionGroup_clear(self);
924+
Py_TYPE(self)->tp_free(self);
925925
}
926926

927927
static int
928-
BaseExceptionGroup_traverse(PyBaseExceptionGroupObject *self,
929-
visitproc visit, void *arg)
928+
BaseExceptionGroup_traverse(PyObject *op, visitproc visit, void *arg)
930929
{
930+
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
931931
Py_VISIT(self->msg);
932932
Py_VISIT(self->excs);
933-
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
933+
return BaseException_traverse(op, visit, arg);
934934
}
935935

936936
static PyObject *
937-
BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
937+
BaseExceptionGroup_str(PyObject *op)
938938
{
939+
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
939940
assert(self->msg);
940941
assert(PyUnicode_Check(self->msg));
941942

@@ -949,7 +950,7 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
949950
static PyObject *
950951
BaseExceptionGroup_derive(PyObject *self_, PyObject *excs)
951952
{
952-
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroupObject_cast(self_);
953+
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(self_);
953954
PyObject *init_args = PyTuple_Pack(2, self->msg, excs);
954955
if (!init_args) {
955956
return NULL;
@@ -1162,7 +1163,7 @@ exceptiongroup_split_recursive(PyObject *exc,
11621163

11631164
/* Partial match */
11641165

1165-
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
1166+
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroup_CAST(exc);
11661167
assert(PyTuple_CheckExact(eg->excs));
11671168
Py_ssize_t num_excs = PyTuple_Size(eg->excs);
11681169
if (num_excs < 0) {
@@ -1313,7 +1314,7 @@ collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids)
13131314
Py_DECREF(exc_id);
13141315
return res;
13151316
}
1316-
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
1317+
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroup_CAST(exc);
13171318
Py_ssize_t num_excs = PyTuple_GET_SIZE(eg->excs);
13181319
/* recursive calls */
13191320
for (Py_ssize_t i = 0; i < num_excs; i++) {
@@ -1545,9 +1546,9 @@ static PyMemberDef BaseExceptionGroup_members[] = {
15451546
static PyMethodDef BaseExceptionGroup_methods[] = {
15461547
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
15471548
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
1548-
{"derive", (PyCFunction)BaseExceptionGroup_derive, METH_O},
1549-
{"split", (PyCFunction)BaseExceptionGroup_split, METH_O},
1550-
{"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_O},
1549+
{"derive", BaseExceptionGroup_derive, METH_O},
1550+
{"split", BaseExceptionGroup_split, METH_O},
1551+
{"subgroup", BaseExceptionGroup_subgroup, METH_O},
15511552
{NULL}
15521553
};
15531554

0 commit comments

Comments
 (0)
0