[Python-Dev] New calling convention to avoid temporarily tuples when calling functions (original) (raw)

Victor Stinner victor.stinner at gmail.com
Mon Aug 22 04:01:38 EDT 2016


Hi,

I pushed the most basic implementation of _PyObject_FastCall(), it doesn't support keyword parameters yet: https://hg.python.org/cpython/rev/a1a29d20f52d https://bugs.python.org/issue27128

Then I patched a lot of call sites calling PyObject_Call(), PyObject_CallObject(), PyEval_CallObject(), etc. with a temporary tuple. Just one example:

The next step is to support keyword parameters. In fact, it's already supported in all cases except of Python functions: https://bugs.python.org/issue27809

Supporting keyword parameters will allow to patch much code to avoid temporary tuples, but it is also required for a much more interesting change: https://bugs.python.org/issue27810 "Add METH_FASTCALL: new calling convention for C functions"

I propose to add a new METH_FASTCALL calling convention. The example using METH_VARARGS | METH_KEYWORDS: PyObject* func(DirEntry *self, PyObject *args, PyObject kwargs) becomes: PyObject func(DirEntry *self, PyObject **args, int nargs, PyObject *kwargs)

Later, Argument Clinic will be modified to generate code using the new METH_FASTCALL calling convention. Code written with Argument Clinic will only need to be updated by Argument Clinic to get the new faster calling convention (avoid the creation of a temporary tuple for positional arguments).

Victor



More information about the Python-Dev mailing list