8000 gh-111178: fix UBSan failures in `Modules/_abc.c` (GH-128253) · python/cpython@bcdf654 · GitHub
[go: up one dir, main page]

Skip to content

Commit bcdf654

Browse files
authored
gh-111178: fix UBSan failures in Modules/_abc.c (GH-128253)
* fix UBSan failures in `_abc.c` * suppress unused return values
1 parent 61b9811 commit bcdf654

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Modules/_abc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ typedef struct {
6767
uint64_t _abc_negative_cache_version;
6868
} _abc_data;
6969

70+
#define _abc_data_CAST(op) ((_abc_data *)(op))
71+
7072
static inline uint64_t
7173
get_cache_version(_abc_data *impl)
7274
{
@@ -88,8 +90,9 @@ set_cache_version(_abc_data *impl, uint64_t version)
8890
}
8991

9092
static int
91-
abc_data_traverse(_abc_data *self, visitproc visit, void *arg)
93+
abc_data_traverse(PyObject *op, visitproc visit, void *arg)
9294
{
95+
_abc_data *self = _abc_data_CAST(op);
9396
Py_VISIT(Py_TYPE(self));
9497
Py_VISIT(self->_abc_registry);
9598
Py_VISIT(self->_abc_cache);
@@ -98,16 +101,17 @@ abc_data_traverse(_abc_data *self, visitproc visit, void *arg)
98101
}
99102

100103
static int
101-
abc_data_clear(_abc_data *self)
104+
abc_data_clear(PyObject *op)
102105
{
106+
_abc_data *self = _abc_data_CAST(op);
103107
Py_CLEAR(self->_abc_registry);
104108
Py_CLEAR(self->_abc_cache);
105109
Py_CLEAR(self->_abc_negative_cache);
106110
return 0;
107111
}
108112

109113
static void
110-
abc_data_dealloc(_abc_data *self)
114+
abc_data_dealloc(PyObject *self)
111115
{
112116
PyObject_GC_UnTrack(self);
113117
PyTypeObject *tp = Py_TYPE(self);
@@ -212,7 +216,7 @@ _destroy(PyObject *setweakref, PyObject *objweakref)
212216
}
213217

214218
static PyMethodDef _destroy_def = {
215-
"_destroy", (PyCFunction) _destroy, METH_O
219+
"_destroy", _destroy, METH_O
216220
};
217221

218222
static int
@@ -964,7 +968,7 @@ _abcmodule_clear(PyObject *module)
964968
static void
965969
_abcmodule_free(void *module)
966970
{
967-
_abcmodule_clear((PyObject *)module);
971+
(void)_abcmodule_clear((PyObject *)module);
968972
}
969973

970974
static PyModuleDef_Slot _abcmodule_slots[] = {

0 commit comments

Comments
 (0)
0