diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-09-10 00:40:22 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-09-10 00:40:22 (GMT) |
commit | a9efb2f56eb6bcb97cebfadf1e778b4cb979357f (patch) | |
tree | ab942c23afa123480faca8207c99c53e804eceed /Objects/methodobject.c | |
parent | 78601a38c22ba1f09104e2562a10a94cbd36f5f0 (diff) | |
download | cpython-a9efb2f56eb6bcb97cebfadf1e778b4cb979357f.zip cpython-a9efb2f56eb6bcb97cebfadf1e778b4cb979357f.tar.gz cpython-a9efb2f56eb6bcb97cebfadf1e778b4cb979357f.tar.bz2 |
Add METH_FASTCALL calling convention
Issue #27810: Add a new calling convention for C functions:
PyObject* func(PyObject *self, PyObject **args,
Py_ssize_t nargs, PyObject *kwnames);
Where args is a C array of positional arguments followed by values of keyword
arguments. nargs is the number of positional arguments, kwnames are keys of
keyword arguments. kwnames can be NULL.
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r-- | Objects/methodobject.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 0fe3315..487ccd7 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -97,6 +97,11 @@ PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwds) if (flags == (METH_VARARGS | METH_KEYWORDS)) { res = (*(PyCFunctionWithKeywords)meth)(self, args, kwds); } + else if (flags == METH_FASTCALL) { + PyObject **stack = &PyTuple_GET_ITEM(args, 0); + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + res = _PyCFunction_FastCallDict(func, stack, nargs, kwds); + } else { if (kwds != NULL && PyDict_Size(kwds) != 0) { PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", @@ -232,6 +237,25 @@ _PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, Py_ssize_t nargs, break; } + case METH_FASTCALL: + { + PyObject **stack; + PyObject *kwnames; + _PyCFunctionFast fastmeth = (_PyCFunctionFast)meth; + + stack = _PyStack_UnpackDict(args, nargs, kwargs, &kwnames, func_obj); + if (stack == NULL) { + return NULL; + } + + result = (*fastmeth) (self, stack, nargs, kwnames); + if (stack != args) { + PyMem_Free(stack); + } + Py_XDECREF(kwnames); + break; + } + default: PyErr_SetString(PyExc_SystemError, "Bad call flags in PyCFunction_Call. " |