Skip to content

Commit 4235f4b

Browse files
committed
pythongh-111178: Fix function signatures to fix undefined behavior
1 parent 9a63138 commit 4235f4b

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

Modules/_threadmodule.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
461461
}
462462

463463
static int
464-
join_thread(ThreadHandle *handle)
464+
join_thread(void *arg)
465465
{
466+
ThreadHandle *handle = (ThreadHandle*)arg;
466467
assert(get_thread_handle_state(handle) == THREAD_HANDLE_RUNNING);
467468
PyThread_handle_t os_handle;
468469
if (ThreadHandle_get_os_handle(handle, &os_handle)) {

Objects/codeobject.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,8 @@ lineiter_dealloc(PyObject *self)
13611361
}
13621362

13631363
static PyObject *
1364-
_source_offset_converter(int *value) {
1364+
_source_offset_converter(void *arg) {
1365+
int *value = (int*)arg;
13651366
if (*value == -1) {
13661367
Py_RETURN_NONE;
13671368
}

Objects/genobject.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
590590

591591

592592
static PyObject *
593-
gen_throw(PyGenObject *gen, PyObject *const *args, Py_ssize_t nargs)
593+
gen_throw(PyObject *op, PyObject *const *args, Py_ssize_t nargs)
594594
{
595+
PyGenObject *gen = _PyGen_CAST(op);
595596
PyObject *typ;
596597
PyObject *tb = NULL;
597598
PyObject *val = NULL;
@@ -821,8 +822,9 @@ static PyMemberDef gen_memberlist[] = {
821822
};
822823

823824
static PyObject *
824-
gen_sizeof(PyGenObject *gen, PyObject *Py_UNUSED(ignored))
825+
gen_sizeof(PyObject *op, PyObject *Py_UNUSED(ignored))
825826
{
827+
PyGenObject *gen = _PyGen_CAST(op);
826828
Py_ssize_t res;
827829
res = offsetof(PyGenObject, gi_iframe) + offsetof(_PyInterpreterFrame, localsplus);
828830
PyCodeObject *code = _PyGen_GetCode(gen);
@@ -837,7 +839,7 @@ static PyMethodDef gen_methods[] = {
837839
{"send", gen_send, METH_O, send_doc},
838840
{"throw", _PyCFunction_CAST(gen_throw), METH_FASTCALL, throw_doc},
839841
{"close", gen_close, METH_NOARGS, close_doc},
840-
{"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
842+
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
841843
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
842844
{NULL, NULL} /* Sentinel */
843845
};
@@ -1197,7 +1199,7 @@ static PyMethodDef coro_methods[] = {
11971199
{"send", gen_send, METH_O, coro_send_doc},
11981200
{"throw",_PyCFunction_CAST(gen_throw), METH_FASTCALL, coro_throw_doc},
11991201
{"close", gen_close, METH_NOARGS, coro_close_doc},
1200-
{"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
1202+
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
12011203
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
12021204
{NULL, NULL} /* Sentinel */
12031205
};
@@ -1288,7 +1290,7 @@ static PyObject *
12881290
coro_wrapper_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
12891291
{
12901292
PyCoroWrapper *cw = _PyCoroWrapper_CAST(self);
1291-
return gen_throw((PyGenObject *)cw->cw_coroutine, args, nargs);
1293+
return gen_throw((PyObject*)cw->cw_coroutine, args, nargs);
12921294
}
12931295

12941296
static PyObject *
@@ -1625,7 +1627,7 @@ static PyMethodDef async_gen_methods[] = {
16251627
{"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc},
16261628
{"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc},
16271629
{"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc},
1628-
{"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
1630+
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
16291631
{"__class_getitem__", Py_GenericAlias,
16301632
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
16311633
{NULL, NULL} /* Sentinel */
@@ -1842,7 +1844,7 @@ async_gen_asend_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
18421844
o->ags_gen->ag_running_async = 1;
18431845
}
18441846

1845-
PyObject *result = gen_throw((PyGenObject*)o->ags_gen, args, nargs);
1847+
PyObject *result = gen_throw((PyObject*)o->ags_gen, args, nargs);
18461848
result = async_gen_unwrap_value(o->ags_gen, result);
18471849

18481850
if (result == NULL) {
@@ -2249,7 +2251,7 @@ async_gen_athrow_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
22492251
o->agt_gen->ag_running_async = 1;
22502252
}
22512253

2252-
PyObject *retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs);
2254+
PyObject *retval = gen_throw((PyObject*)o->agt_gen, args, nargs);
22532255
if (o->agt_args) {
22542256
retval = async_gen_unwrap_value(o->agt_gen, retval);
22552257
if (retval == NULL) {

Objects/iterobject.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ PyCallIter_New(PyObject *callable, PyObject *sentinel)
200200
return (PyObject *)it;
201201
}
202202
static void
203-
calliter_dealloc(calliterobject *it)
203+
calliter_dealloc(PyObject *op)
204204
{
205+
calliterobject *it = (calliterobject*)op;
205206
_PyObject_GC_UNTRACK(it);
206207
Py_XDECREF(it->it_callable);
207208
Py_XDECREF(it->it_sentinel);
@@ -217,8 +218,9 @@ calliter_traverse(calliterobject *it, visitproc visit, void *arg)
217218
}
218219

219220
static PyObject *
220-
calliter_iternext(calliterobject *it)
221+
calliter_iternext(PyObject *op)
221222
{
223+
calliterobject *it = (calliterobject*)op;
222224
PyObject *result;
223225

224226
if (it->it_callable == NULL) {
@@ -249,8 +251,9 @@ calliter_iternext(calliterobject *it)
249251
}
250252

251253
static PyObject *
252-
calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
254+
calliter_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
253255
{
256+
calliterobject *it = (calliterobject*)op;
254257
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
255258

256259
/* _PyEval_GetBuiltin can invoke arbitrary code,
@@ -264,7 +267,7 @@ calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
264267
}
265268

266269
static PyMethodDef calliter_methods[] = {
267-
{"__reduce__", (PyCFunction)calliter_reduce, METH_NOARGS, reduce_doc},
270+
{"__reduce__", calliter_reduce, METH_NOARGS, reduce_doc},
268271
{NULL, NULL} /* sentinel */
269272
};
270273

@@ -274,7 +277,7 @@ PyTypeObject PyCallIter_Type = {
274277
sizeof(calliterobject), /* tp_basicsize */
275278
0, /* tp_itemsize */
276279
/* methods */
277-
(destructor)calliter_dealloc, /* tp_dealloc */
280+
calliter_dealloc, /* tp_dealloc */
278281
0, /* tp_vectorcall_offset */
279282
0, /* tp_getattr */
280283
0, /* tp_setattr */
@@ -296,7 +299,7 @@ PyTypeObject PyCallIter_Type = {
296299
0, /* tp_richcompare */
297300
0, /* tp_weaklistoffset */
298301
PyObject_SelfIter, /* tp_iter */
299-
(iternextfunc)calliter_iternext, /* tp_iternext */
302+
calliter_iternext, /* tp_iternext */
300303
calliter_methods, /* tp_methods */
301304
};
302305

Python/lock.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
137137
}
138138

139139
static void
140-
mutex_unpark(PyMutex *m, struct mutex_entry *entry, int has_more_waiters)
140+
mutex_unpark(void *arg, void *park_arg, int has_more_waiters)
141141
{
142+
PyMutex *m = (PyMutex*)arg;
143+
struct mutex_entry *entry = (struct mutex_entry*)park_arg;
142144
uint8_t v = 0;
143145
if (entry) {
144146
PyTime_t now;

0 commit comments

Comments
 (0)