Skip to content

Commit 1136a4e

Browse files
committed
fix UBSan failures for PyCodeObject
1 parent b66a4ad commit 1136a4e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Objects/codeobject.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,11 +1865,12 @@ free_monitoring_data(_PyCoMonitoringData *data)
18651865
}
18661866

18671867
static void
1868-
code_dealloc(PyCodeObject *co)
1868+
code_dealloc(PyObject *self)
18691869
{
1870-
_PyObject_ResurrectStart((PyObject *)co);
1870+
PyCodeObject *co = (PyCodeObject *)self;
1871+
_PyObject_ResurrectStart(self);
18711872
notify_code_watchers(PY_CODE_EVENT_DESTROY, co);
1872-
if (_PyObject_ResurrectEnd((PyObject *)co)) {
1873+
if (_PyObject_ResurrectEnd(self)) {
18731874
return;
18741875
}
18751876

@@ -1918,7 +1919,7 @@ code_dealloc(PyCodeObject *co)
19181919
PyMem_Free(co->_co_cached);
19191920
}
19201921
if (co->co_weakreflist != NULL) {
1921-
PyObject_ClearWeakRefs((PyObject*)co);
1922+
PyObject_ClearWeakRefs(self);
19221923
}
19231924
free_monitoring_data(co->_co_monitoring);
19241925
#ifdef Py_GIL_DISABLED
@@ -2198,8 +2199,9 @@ code_linesiterator(PyObject *self, PyObject *Py_UNUSED(args))
21982199
}
21992200

22002201
static PyObject *
2201-
code_branchesiterator(PyCodeObject *code, PyObject *Py_UNUSED(args))
2202+
code_branchesiterator(PyObject *self, PyObject *Py_UNUSED(args))
22022203
{
2204+
PyCodeObject *code = (PyCodeObject*)self;
22032205
return _PyInstrumentation_BranchesIterator(code);
22042206
}
22052207

@@ -2343,7 +2345,7 @@ code__varname_from_oparg_impl(PyCodeObject *self, int oparg)
23432345
static struct PyMethodDef code_methods[] = {
23442346
{"__sizeof__", code_sizeof, METH_NOARGS},
23452347
{"co_lines", code_linesiterator, METH_NOARGS},
2346-
{"co_branches", (PyCFunction)code_branchesiterator, METH_NOARGS},
2348+
{"co_branches", code_branchesiterator, METH_NOARGS},
23472349
{"co_positions", code_positionsiterator, METH_NOARGS},
23482350
CODE_REPLACE_METHODDEF
23492351
CODE__VARNAME_FROM_OPARG_METHODDEF
@@ -2358,7 +2360,7 @@ PyTypeObject PyCode_Type = {
23582360
"code",
23592361
offsetof(PyCodeObject, co_code_adaptive),
23602362
sizeof(_Py_CODEUNIT),
2361-
(destructor)code_dealloc, /* tp_dealloc */
2363+
code_dealloc, /* tp_dealloc */
23622364
0, /* tp_vectorcall_offset */
23632365
0, /* tp_getattr */
23642366
0, /* tp_setattr */

0 commit comments

Comments
 (0)