Skip to content

Commit f0f5b73

Browse files
committed
fix UBSan failures for PyDecContextManagerObject
1 parent 1bed6f6 commit f0f5b73

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Modules/_decimal/_decimal.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,39 +1956,39 @@ ctxmanager_new(PyObject *m, PyObject *args, PyObject *kwds)
19561956
}
19571957

19581958
static int
1959-
ctxmanager_traverse(PyDecContextManagerObject *self, visitproc visit,
1960-
void *arg)
1959+
ctxmanager_traverse(PyObject *op, visitproc visit, void *arg)
19611960
{
1961+
PyDecContextManagerObject *self = _PyDecContextManagerObject_CAST(op);
19621962
Py_VISIT(Py_TYPE(self));
19631963
Py_VISIT(self->local);
19641964
Py_VISIT(self->global);
19651965
return 0;
19661966
}
19671967

19681968
static int
1969-
ctxmanager_clear(PyDecContextManagerObject *self)
1969+
ctxmanager_clear(PyObject *op)
19701970
{
1971+
PyDecContextManagerObject *self = _PyDecContextManagerObject_CAST(op);
19711972
Py_CLEAR(self->local);
19721973
Py_CLEAR(self->global);
19731974
return 0;
19741975
}
19751976

19761977
static void
1977-
ctxmanager_dealloc(PyDecContextManagerObject *self)
1978+
ctxmanager_dealloc(PyObject *self)
19781979
{
19791980
PyTypeObject *tp = Py_TYPE(self);
19801981
PyObject_GC_UnTrack(self);
19811982
(void)ctxmanager_clear(self);
1982-
tp->tp_free((PyObject *)self);
1983+
tp->tp_free(self);
19831984
Py_DECREF(tp);
19841985
}
19851986

19861987
static PyObject *
1987-
ctxmanager_set_local(PyDecContextManagerObject *self,
1988-
PyObject *Py_UNUSED(dummy))
1988+
ctxmanager_set_local(PyObject *op, PyObject *Py_UNUSED(dummy))
19891989
{
19901990
PyObject *ret;
1991-
1991+
PyDecContextManagerObject *self = _PyDecContextManagerObject_CAST(op);
19921992
ret = PyDec_SetCurrentContext(PyType_GetModule(Py_TYPE(self)), self->local);
19931993
if (ret == NULL) {
19941994
return NULL;
@@ -1999,11 +1999,10 @@ ctxmanager_set_local(PyDecContextManagerObject *self,
19991999
}
20002000

20012001
static PyObject *
2002-
ctxmanager_restore_global(PyDecContextManagerObject *self,
2003-
PyObject *Py_UNUSED(args))
2002+
ctxmanager_restore_global(PyObject *op, PyObject *Py_UNUSED(args))
20042003
{
20052004
PyObject *ret;
2006-
2005+
PyDecContextManagerObject *self = _PyDecContextManagerObject_CAST(op);
20072006
ret = PyDec_SetCurrentContext(PyType_GetModule(Py_TYPE(self)), self->global);
20082007
if (ret == NULL) {
20092008
return NULL;
@@ -2015,8 +2014,8 @@ ctxmanager_restore_global(PyDecContextManagerObject *self,
20152014

20162015

20172016
static PyMethodDef ctxmanager_methods[] = {
2018-
{"__enter__", (PyCFunction)ctxmanager_set_local, METH_NOARGS, NULL},
2019-
{"__exit__", (PyCFunction)ctxmanager_restore_global, METH_VARARGS, NULL},
2017+
{"__enter__", ctxmanager_set_local, METH_NOARGS, NULL},
2018+
{"__exit__", ctxmanager_restore_global, METH_VARARGS, NULL},
20202019
{NULL, NULL}
20212020
};
20222021

0 commit comments

Comments
 (0)