mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #27810: Add _PyCFunction_FastCallKeywords()
Use _PyCFunction_FastCallKeywords() in ceval.c: it allows to remove a lot of code from ceval.c which was only used to call C functions.
This commit is contained in:
parent
502893896a
commit
ae8b69c410
5 changed files with 71 additions and 138 deletions
|
@ -2366,7 +2366,7 @@ _PyObject_Call_Prepend(PyObject *func,
|
|||
return result;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyObject *
|
||||
_PyStack_AsDict(PyObject **values, Py_ssize_t nkwargs, PyObject *kwnames,
|
||||
PyObject *func)
|
||||
{
|
||||
|
@ -2415,10 +2415,13 @@ _PyObject_FastCallKeywords(PyObject *func, PyObject **stack, Py_ssize_t nargs,
|
|||
assert((nargs == 0 && nkwargs == 0) || stack != NULL);
|
||||
|
||||
if (PyFunction_Check(func)) {
|
||||
/* Fast-path: avoid temporary tuple or dict */
|
||||
return _PyFunction_FastCallKeywords(func, stack, nargs, kwnames);
|
||||
}
|
||||
|
||||
if (PyCFunction_Check(func)) {
|
||||
return _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames);
|
||||
}
|
||||
|
||||
if (nkwargs > 0) {
|
||||
kwdict = _PyStack_AsDict(stack + nargs, nkwargs, kwnames, func);
|
||||
if (kwdict == NULL) {
|
||||
|
|
|
@ -155,6 +155,7 @@ _PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, Py_ssize_t nargs,
|
|||
PyObject *result;
|
||||
int flags;
|
||||
|
||||
assert(PyCFunction_Check(func));
|
||||
assert(func != NULL);
|
||||
assert(nargs >= 0);
|
||||
assert(nargs == 0 || args != NULL);
|
||||
|
@ -243,6 +244,31 @@ _PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, Py_ssize_t nargs,
|
|||
return result;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyCFunction_FastCallKeywords(PyObject *func, PyObject **stack,
|
||||
Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *kwdict, *result;
|
||||
Py_ssize_t nkwargs;
|
||||
|
||||
assert(PyCFunction_Check(func));
|
||||
|
||||
nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
||||
if (nkwargs > 0) {
|
||||
kwdict = _PyStack_AsDict(stack + nargs, nkwargs, kwnames, func);
|
||||
if (kwdict == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
kwdict = NULL;
|
||||
}
|
||||
|
||||
result = _PyCFunction_FastCallDict(func, stack, nargs, kwdict);
|
||||
Py_XDECREF(kwdict);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Methods (the standard built-in methods, that is) */
|
||||
|
||||
static void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue