https://github.com/python/cpython/commit/a5776639c8fde8b3b7c90821ab78ddb64130f4c0
commit: a5776639c8fde8b3b7c90821ab78ddb64130f4c0
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-03-14T09:52:15Z
summary:
gh-111178: Fix function signatures to fix undefined behavior (#131191)
files:
M Modules/_threadmodule.c
M Objects/codeobject.c
M Objects/genobject.c
M Objects/iterobject.c
M Python/lock.c
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 4862b24fa93314..ef045fce3df9aa 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -461,8 +461,9 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func,
PyObject *args,
}
static int
-join_thread(ThreadHandle *handle)
+join_thread(void *arg)
{
+ ThreadHandle *handle = (ThreadHandle*)arg;
assert(get_thread_handle_state(handle) == THREAD_HANDLE_RUNNING);
PyThread_handle_t os_handle;
if (ThreadHandle_get_os_handle(handle, &os_handle)) {
@@ -536,8 +537,7 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
}
}
- if (_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)join_thread,
- self) == -1) {
+ if (_PyOnceFlag_CallOnce(&self->once, join_thread, self) == -1) {
return -1;
}
assert(get_thread_handle_state(self) == THREAD_HANDLE_DONE);
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 60563ea7575604..90f0bfb7b92b7e 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1361,7 +1361,8 @@ lineiter_dealloc(PyObject *self)
}
static PyObject *
-_source_offset_converter(int *value) {
+_source_offset_converter(void *arg) {
+ int *value = (int*)arg;
if (*value == -1) {
Py_RETURN_NONE;
}
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 79aed8571c35e7..2f70df79a3d3b0 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -590,8 +590,9 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
static PyObject *
-gen_throw(PyGenObject *gen, PyObject *const *args, Py_ssize_t nargs)
+gen_throw(PyObject *op, PyObject *const *args, Py_ssize_t nargs)
{
+ PyGenObject *gen = _PyGen_CAST(op);
PyObject *typ;
PyObject *tb = NULL;
PyObject *val = NULL;
@@ -821,8 +822,9 @@ static PyMemberDef gen_memberlist[] = {
};
static PyObject *
-gen_sizeof(PyGenObject *gen, PyObject *Py_UNUSED(ignored))
+gen_sizeof(PyObject *op, PyObject *Py_UNUSED(ignored))
{
+ PyGenObject *gen = _PyGen_CAST(op);
Py_ssize_t res;
res = offsetof(PyGenObject, gi_iframe) + offsetof(_PyInterpreterFrame,
localsplus);
PyCodeObject *code = _PyGen_GetCode(gen);
@@ -837,7 +839,7 @@ static PyMethodDef gen_methods[] = {
{"send", gen_send, METH_O, send_doc},
{"throw", _PyCFunction_CAST(gen_throw), METH_FASTCALL, throw_doc},
{"close", gen_close, METH_NOARGS, close_doc},
- {"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
+ {"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See
PEP 585")},
{NULL, NULL} /* Sentinel */
};
@@ -1197,7 +1199,7 @@ static PyMethodDef coro_methods[] = {
{"send", gen_send, METH_O, coro_send_doc},
{"throw",_PyCFunction_CAST(gen_throw), METH_FASTCALL, coro_throw_doc},
{"close", gen_close, METH_NOARGS, coro_close_doc},
- {"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
+ {"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See
PEP 585")},
{NULL, NULL} /* Sentinel */
};
@@ -1288,7 +1290,7 @@ static PyObject *
coro_wrapper_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyCoroWrapper *cw = _PyCoroWrapper_CAST(self);
- return gen_throw((PyGenObject *)cw->cw_coroutine, args, nargs);
+ return gen_throw((PyObject*)cw->cw_coroutine, args, nargs);
}
static PyObject *
@@ -1625,7 +1627,7 @@ static PyMethodDef async_gen_methods[] = {
{"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc},
{"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc},
{"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc},
- {"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
+ {"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL} /* Sentinel */
@@ -1842,7 +1844,7 @@ async_gen_asend_throw(PyObject *self, PyObject *const
*args, Py_ssize_t nargs)
o->ags_gen->ag_running_async = 1;
}
- PyObject *result = gen_throw((PyGenObject*)o->ags_gen, args, nargs);
+ PyObject *result = gen_throw((PyObject*)o->ags_gen, args, nargs);
result = async_gen_unwrap_value(o->ags_gen, result);
if (result == NULL) {
@@ -2249,7 +2251,7 @@ async_gen_athrow_throw(PyObject *self, PyObject *const
*args, Py_ssize_t nargs)
o->agt_gen->ag_running_async = 1;
}
- PyObject *retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs);
+ PyObject *retval = gen_throw((PyObject*)o->agt_gen, args, nargs);
if (o->agt_args) {
retval = async_gen_unwrap_value(o->agt_gen, retval);
if (retval == NULL) {
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index 87e30d6922ca56..8b33a7ded3ffd6 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -200,8 +200,9 @@ PyCallIter_New(PyObject *callable, PyObject *sentinel)
return (PyObject *)it;
}
static void
-calliter_dealloc(calliterobject *it)
+calliter_dealloc(PyObject *op)
{
+ calliterobject *it = (calliterobject*)op;
_PyObject_GC_UNTRACK(it);
Py_XDECREF(it->it_callable);
Py_XDECREF(it->it_sentinel);
@@ -217,8 +218,9 @@ calliter_traverse(calliterobject *it, visitproc visit, void
*arg)
}
static PyObject *
-calliter_iternext(calliterobject *it)
+calliter_iternext(PyObject *op)
{
+ calliterobject *it = (calliterobject*)op;
PyObject *result;
if (it->it_callable == NULL) {
@@ -249,8 +251,9 @@ calliter_iternext(calliterobject *it)
}
static PyObject *
-calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
+calliter_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
{
+ calliterobject *it = (calliterobject*)op;
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
/* _PyEval_GetBuiltin can invoke arbitrary code,
@@ -264,7 +267,7 @@ calliter_reduce(calliterobject *it, PyObject
*Py_UNUSED(ignored))
}
static PyMethodDef calliter_methods[] = {
- {"__reduce__", (PyCFunction)calliter_reduce, METH_NOARGS, reduce_doc},
+ {"__reduce__", calliter_reduce, METH_NOARGS, reduce_doc},
{NULL, NULL} /* sentinel */
};
@@ -274,7 +277,7 @@ PyTypeObject PyCallIter_Type = {
sizeof(calliterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)calliter_dealloc, /* tp_dealloc */
+ calliter_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -296,7 +299,7 @@ PyTypeObject PyCallIter_Type = {
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
- (iternextfunc)calliter_iternext, /* tp_iternext */
+ calliter_iternext, /* tp_iternext */
calliter_methods, /* tp_methods */
};
diff --git a/Python/lock.c b/Python/lock.c
index f2067ee2cd5f37..28a12ad18352d1 100644
--- a/Python/lock.c
+++ b/Python/lock.c
@@ -137,8 +137,10 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout,
_PyLockFlags flags)
}
static void
-mutex_unpark(PyMutex *m, struct mutex_entry *entry, int has_more_waiters)
+mutex_unpark(void *arg, void *park_arg, int has_more_waiters)
{
+ PyMutex *m = (PyMutex*)arg;
+ struct mutex_entry *entry = (struct mutex_entry*)park_arg;
uint8_t v = 0;
if (entry) {
PyTime_t now;
@@ -168,7 +170,7 @@ _PyMutex_TryUnlock(PyMutex *m)
}
else if ((v & _Py_HAS_PARKED)) {
// wake up a single thread
- _PyParkingLot_Unpark(&m->_bits, (_Py_unpark_fn_t *)mutex_unpark,
m);
+ _PyParkingLot_Unpark(&m->_bits, mutex_unpark, m);
return 0;
}
else if (_Py_atomic_compare_exchange_uint8(&m->_bits, &v,
_Py_UNLOCKED)) {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]