Skip to content

Commit 19bc7e1

Browse files
committed
fix UBSan failures for PyDateTime_IsoCalendarDate
1 parent 0a3cb0e commit 19bc7e1

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

Modules/_datetimemodule.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,17 +3611,17 @@ typedef struct {
36113611
} PyDateTime_IsoCalendarDate;
36123612

36133613
static PyObject *
3614-
iso_calendar_date_repr(PyDateTime_IsoCalendarDate *self)
3614+
iso_calendar_date_repr(PyObject *self)
36153615
{
3616-
PyObject* year = PyTuple_GetItem((PyObject *)self, 0);
3616+
PyObject *year = PyTuple_GetItem(self, 0);
36173617
if (year == NULL) {
36183618
return NULL;
36193619
}
3620-
PyObject* week = PyTuple_GetItem((PyObject *)self, 1);
3620+
PyObject *week = PyTuple_GetItem(self, 1);
36213621
if (week == NULL) {
36223622
return NULL;
36233623
}
3624-
PyObject* weekday = PyTuple_GetItem((PyObject *)self, 2);
3624+
PyObject *weekday = PyTuple_GetItem(self, 2);
36253625
if (weekday == NULL) {
36263626
return NULL;
36273627
}
@@ -3634,7 +3634,7 @@ static PyObject *
36343634
iso_calendar_date_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
36353635
{
36363636
// Construct the tuple that this reduces to
3637-
PyObject * reduce_tuple = Py_BuildValue(
3637+
PyObject *reduce_tuple = Py_BuildValue(
36383638
"O((OOO))", &PyTuple_Type,
36393639
PyTuple_GET_ITEM(self, 0),
36403640
PyTuple_GET_ITEM(self, 1),
@@ -3645,61 +3645,60 @@ iso_calendar_date_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
36453645
}
36463646

36473647
static PyObject *
3648-
iso_calendar_date_year(PyDateTime_IsoCalendarDate *self, void *unused)
3648+
iso_calendar_date_year(PyObject *self, void *unused)
36493649
{
3650-
PyObject *year = PyTuple_GetItem((PyObject *)self, 0);
3650+
PyObject *year = PyTuple_GetItem(self, 0);
36513651
if (year == NULL) {
36523652
return NULL;
36533653
}
36543654
return Py_NewRef(year);
36553655
}
36563656

36573657
static PyObject *
3658-
iso_calendar_date_week(PyDateTime_IsoCalendarDate *self, void *unused)
3658+
iso_calendar_date_week(PyObject *self, void *unused)
36593659
{
3660-
PyObject *week = PyTuple_GetItem((PyObject *)self, 1);
3660+
PyObject *week = PyTuple_GetItem(self, 1);
36613661
if (week == NULL) {
36623662
return NULL;
36633663
}
36643664
return Py_NewRef(week);
36653665
}
36663666

36673667
static PyObject *
3668-
iso_calendar_date_weekday(PyDateTime_IsoCalendarDate *self, void *unused)
3668+
iso_calendar_date_weekday(PyObject *self, void *unused)
36693669
{
3670-
PyObject *weekday = PyTuple_GetItem((PyObject *)self, 2);
3670+
PyObject *weekday = PyTuple_GetItem(self, 2);
36713671
if (weekday == NULL) {
36723672
return NULL;
36733673
}
36743674
return Py_NewRef(weekday);
36753675
}
36763676

36773677
static PyGetSetDef iso_calendar_date_getset[] = {
3678-
{"year", (getter)iso_calendar_date_year},
3679-
{"week", (getter)iso_calendar_date_week},
3680-
{"weekday", (getter)iso_calendar_date_weekday},
3678+
{"year", iso_calendar_date_year},
3679+
{"week", iso_calendar_date_week},
3680+
{"weekday", iso_calendar_date_weekday},
36813681
{NULL}
36823682
};
36833683

36843684
static PyMethodDef iso_calendar_date_methods[] = {
3685-
{"__reduce__", (PyCFunction)iso_calendar_date_reduce, METH_NOARGS,
3685+
{"__reduce__", iso_calendar_date_reduce, METH_NOARGS,
36863686
PyDoc_STR("__reduce__() -> (cls, state)")},
36873687
{NULL, NULL},
36883688
};
36893689

36903690
static int
3691-
iso_calendar_date_traverse(PyDateTime_IsoCalendarDate *self, visitproc visit,
3692-
void *arg)
3691+
iso_calendar_date_traverse(PyObject *self, visitproc visit, void *arg)
36933692
{
36943693
Py_VISIT(Py_TYPE(self));
3695-
return PyTuple_Type.tp_traverse((PyObject *)self, visit, arg);
3694+
return PyTuple_Type.tp_traverse(self, visit, arg);
36963695
}
36973696

36983697
static void
3699-
iso_calendar_date_dealloc(PyDateTime_IsoCalendarDate *self)
3698+
iso_calendar_date_dealloc(PyObject *self)
37003699
{
37013700
PyTypeObject *tp = Py_TYPE(self);
3702-
PyTuple_Type.tp_dealloc((PyObject *)self); // delegate GC-untrack as well
3701+
PyTuple_Type.tp_dealloc(self); // delegate GC-untrack as well
37033702
Py_DECREF(tp);
37043703
}
37053704

0 commit comments

Comments
 (0)