mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
gh-111178: Fix function signatures to fix undefined behavior (#131191)
This commit is contained in:
parent
e4ac196aaa
commit
a5776639c8
5 changed files with 28 additions and 20 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -590,8 +590,9 @@ failed_throw:
|
|||
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue