mirror of https://github.com/python/cpython
GH-103182: use vectorcall in `_asyncio` instead of variadic calling APIs (#103175)
This commit is contained in:
parent
385b5d6e09
commit
e6f7d35be7
|
@ -355,33 +355,26 @@ call_soon(asyncio_state *state, PyObject *loop, PyObject *func, PyObject *arg,
|
||||||
PyObject *ctx)
|
PyObject *ctx)
|
||||||
{
|
{
|
||||||
PyObject *handle;
|
PyObject *handle;
|
||||||
PyObject *stack[3];
|
|
||||||
Py_ssize_t nargs;
|
|
||||||
|
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
handle = PyObject_CallMethodObjArgs(
|
PyObject *stack[] = {loop, func, arg};
|
||||||
loop, &_Py_ID(call_soon), func, arg, NULL);
|
size_t nargsf = 3 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||||
|
handle = PyObject_VectorcallMethod(&_Py_ID(call_soon), stack, nargsf, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Use FASTCALL to pass a keyword-only argument to call_soon */
|
|
||||||
|
|
||||||
PyObject *callable = PyObject_GetAttr(loop, &_Py_ID(call_soon));
|
|
||||||
if (callable == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* All refs in 'stack' are borrowed. */
|
/* All refs in 'stack' are borrowed. */
|
||||||
nargs = 1;
|
PyObject *stack[4];
|
||||||
stack[0] = func;
|
size_t nargs = 2;
|
||||||
|
stack[0] = loop;
|
||||||
|
stack[1] = func;
|
||||||
if (arg != NULL) {
|
if (arg != NULL) {
|
||||||
stack[1] = arg;
|
stack[2] = arg;
|
||||||
nargs++;
|
nargs++;
|
||||||
}
|
}
|
||||||
stack[nargs] = (PyObject *)ctx;
|
stack[nargs] = (PyObject *)ctx;
|
||||||
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
|
size_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||||
handle = PyObject_Vectorcall(callable, stack, nargs,
|
handle = PyObject_VectorcallMethod(&_Py_ID(call_soon), stack, nargsf,
|
||||||
state->context_kwname);
|
state->context_kwname);
|
||||||
Py_DECREF(callable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
|
@ -2359,8 +2352,9 @@ _asyncio_Task_get_stack_impl(TaskObj *self, PyTypeObject *cls,
|
||||||
/*[clinic end generated code: output=6774dfc10d3857fa input=8e01c9b2618ae953]*/
|
/*[clinic end generated code: output=6774dfc10d3857fa input=8e01c9b2618ae953]*/
|
||||||
{
|
{
|
||||||
asyncio_state *state = get_asyncio_state_by_cls(cls);
|
asyncio_state *state = get_asyncio_state_by_cls(cls);
|
||||||
return PyObject_CallFunctionObjArgs(
|
PyObject *stack[] = {(PyObject *)self, limit};
|
||||||
state->asyncio_task_get_stack_func, self, limit, NULL);
|
return PyObject_Vectorcall(state->asyncio_task_get_stack_func,
|
||||||
|
stack, 2, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
@ -2387,8 +2381,9 @@ _asyncio_Task_print_stack_impl(TaskObj *self, PyTypeObject *cls,
|
||||||
/*[clinic end generated code: output=b38affe9289ec826 input=150b35ba2d3a7dee]*/
|
/*[clinic end generated code: output=b38affe9289ec826 input=150b35ba2d3a7dee]*/
|
||||||
{
|
{
|
||||||
asyncio_state *state = get_asyncio_state_by_cls(cls);
|
asyncio_state *state = get_asyncio_state_by_cls(cls);
|
||||||
return PyObject_CallFunctionObjArgs(
|
PyObject *stack[] = {(PyObject *)self, limit, file};
|
||||||
state->asyncio_task_print_stack_func, self, limit, file, NULL);
|
return PyObject_Vectorcall(state->asyncio_task_print_stack_func,
|
||||||
|
stack, 3, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
|
Loading…
Reference in New Issue