cpython: a25c39873d93 (original) (raw)

Mercurial > cpython

changeset 103467:a25c39873d93

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. [#27810]

Victor Stinner victor.stinner@gmail.com
date Fri, 09 Sep 2016 14:07:44 -0700
parents 672c5fe7372c
children ef3d30cc6b4f 861ddad3e0c1
files Include/abstract.h Include/methodobject.h Objects/abstract.c Objects/methodobject.c Python/ceval.c
diffstat 5 files changed, 76 insertions(+), 143 deletions(-)[+] [-] Include/abstract.h 9 Include/methodobject.h 5 Objects/abstract.c 7 Objects/methodobject.c 26 Python/ceval.c 172

line wrap: on

line diff

--- a/Include/abstract.h +++ b/Include/abstract.h @@ -267,9 +267,16 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PyObject *args, PyObject *kwargs); #ifndef Py_LIMITED_API

+ /* Call the callable object func with the "fast call" calling convention: args is a C array for positional arguments (nargs is the number of positional arguments), kwargs is a dictionary for keyword arguments.

--- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -42,6 +42,11 @@ PyAPI_FUNC(PyObject *) _PyCFunction_Fast PyObject **args, Py_ssize_t nargs, PyObject *kwargs); + +PyAPI_FUNC(PyObject *) _PyCFunction_FastCallKeywords(PyObject *func,

#endif struct PyMethodDef {

--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2366,7 +2366,7 @@ PyObject * return result; } -static PyObject * +PyObject * _PyStack_AsDict(PyObject **values, Py_ssize_t nkwargs, PyObject *kwnames, PyObject *func) { @@ -2415,10 +2415,13 @@ PyObject * assert((nargs == 0 && nkwargs == 0) || stack != NULL); if (PyFunction_Check(func)) {

+ if (nkwargs > 0) { kwdict = _PyStack_AsDict(stack + nargs, nkwargs, kwnames, func); if (kwdict == NULL) {

--- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -155,6 +155,7 @@ PyObject * PyObject *result; int flags;

+PyObject * +_PyCFunction_FastCallKeywords(PyObject *func, PyObject **stack,

+{

+

+

+

+} + /* Methods (the standard built-in methods, that is) */ static void

--- a/Python/ceval.c +++ b/Python/ceval.c @@ -115,8 +115,6 @@ static PyObject * call_function(PyObject #endif static PyObject * fast_function(PyObject *, PyObject **, Py_ssize_t, PyObject *); static PyObject * do_call_core(PyObject *, PyObject *, PyObject *); -static PyObject * create_keyword_args(PyObject *, PyObject ***, PyObject *); -static PyObject * load_args(PyObject ***, Py_ssize_t); #ifdef LLTRACE static int lltrace; @@ -4892,21 +4890,6 @@ PyEval_GetFuncDesc(PyObject *func) return " object"; } -static void -err_args(PyObject *func, int flags, Py_ssize_t nargs) -{

-} - #define C_TRACE(x, call) [](#l5.31) if (tstate->use_tracing && tstate->c_profilefunc) { [](#l5.32) if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, [](#l5.33) @@ -4950,91 +4933,49 @@ call_function(PyObject ***pp_stack, Py_s PyObject *x, *w; Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); Py_ssize_t nargs = oparg - nkwargs;

/* Always dispatch PyCFunction first, because these are presumed to be the most frequent callable object. */ if (PyCFunction_Check(func)) {

PCALL(PCALL_CFUNCTION);

-

-

+

+

+

+

-

-

-

-

- -cfuncerror: + assert((x != NULL) ^ (PyErr_Occurred() != NULL)); /* Clear the stack of the function object. Also removes @@ -5243,55 +5184,6 @@ PyObject * } static PyObject * -create_keyword_args(PyObject *names, PyObject ***pp_stack,

-{

-} - -static PyObject * -load_args(PyObject ***pp_stack, Py_ssize_t nargs) -{

-

-

-} - -static PyObject * do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict) { #ifdef CALL_PROFILE