cpython: a8d35309dcc0 (original) (raw)
Mercurial > cpython
changeset 106217:a8d35309dcc0
PyCFunction_Call() now calls _PyCFunction_FastCallDict() Issue #29259. We had 3 versions of similar code: * PyCFunction_Call() * _PyCFunction_FastCallDict() * _PyCFunction_FastCallKeywords() PyCFunction_Call() now calls _PyCFunction_FastCallDict() to factorize the code. [#29259]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Wed, 18 Jan 2017 14:04:37 +0100 |
parents | a241817424e5 |
children | ee6e1b1151a8 |
files | Objects/methodobject.c |
diffstat | 1 files changed, 5 insertions(+), 70 deletions(-)[+] [-] Objects/methodobject.c 75 |
line wrap: on
line diff
--- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -78,77 +78,12 @@ PyCFunction_GetFlags(PyObject *op) } PyObject * -PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwds) +PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwargs) {
- PyCFunctionObject* f = (PyCFunctionObject*)func;
- PyCFunction meth = PyCFunction_GET_FUNCTION(func);
- PyObject *self = PyCFunction_GET_SELF(func);
- PyObject *arg, *res;
- Py_ssize_t size;
- int flags;
- assert(kwds == NULL || PyDict_Check(kwds));
- /* PyCFunction_Call() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the[](#l1.19)
caller loses its exception */[](#l1.20)
- assert(!PyErr_Occurred());
- if (flags == (METH_VARARGS | METH_KEYWORDS)) {
res = (*(PyCFunctionWithKeywords)meth)(self, args, kwds);[](#l1.26)
- }
- else if (flags == METH_FASTCALL) {
PyObject **stack = &PyTuple_GET_ITEM(args, 0);[](#l1.29)
Py_ssize_t nargs = PyTuple_GET_SIZE(args);[](#l1.30)
res = _PyCFunction_FastCallDict(func, stack, nargs, kwds);[](#l1.31)
- }
- else {
if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) {[](#l1.34)
PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",[](#l1.35)
f->m_ml->ml_name);[](#l1.36)
return NULL;[](#l1.37)
}[](#l1.38)
switch (flags) {[](#l1.40)
case METH_VARARGS:[](#l1.41)
res = (*meth)(self, args);[](#l1.42)
break;[](#l1.43)
case METH_NOARGS:[](#l1.45)
size = PyTuple_GET_SIZE(args);[](#l1.46)
if (size != 0) {[](#l1.47)
PyErr_Format(PyExc_TypeError,[](#l1.48)
"%.200s() takes no arguments (%zd given)",[](#l1.49)
f->m_ml->ml_name, size);[](#l1.50)
return NULL;[](#l1.51)
}[](#l1.52)
res = (*meth)(self, NULL);[](#l1.54)
break;[](#l1.55)
case METH_O:[](#l1.57)
size = PyTuple_GET_SIZE(args);[](#l1.58)
if (size != 1) {[](#l1.59)
PyErr_Format(PyExc_TypeError,[](#l1.60)
"%.200s() takes exactly one argument (%zd given)",[](#l1.61)
f->m_ml->ml_name, size);[](#l1.62)
return NULL;[](#l1.63)
}[](#l1.64)
arg = PyTuple_GET_ITEM(args, 0);[](#l1.66)
res = (*meth)(self, arg);[](#l1.67)
break;[](#l1.68)
default:[](#l1.70)
PyErr_SetString(PyExc_SystemError,[](#l1.71)
"Bad call flags in PyCFunction_Call. "[](#l1.72)
"METH_OLDARGS is no longer supported!");[](#l1.73)
return NULL;[](#l1.74)
}[](#l1.75)
- }