summaryrefslogtreecommitdiffstats
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2017-02-02 22:43:03 (GMT)
committerINADA Naoki <songofacandy@gmail.com>2017-02-02 22:43:03 (GMT)
commit5566bbb8d563646d83e8172410fa0c085e8233b1 (patch)
treecb8ca83c2b1a6eb01a6b51258532b4fccf548b6d /Objects/methodobject.c
parent144fff8b900f9d452402a8e47ff79e88e4916d28 (diff)
downloadcpython-5566bbb8d563646d83e8172410fa0c085e8233b1.zip
cpython-5566bbb8d563646d83e8172410fa0c085e8233b1.tar.gz
cpython-5566bbb8d563646d83e8172410fa0c085e8233b1.tar.bz2
Issue #29263: LOAD_METHOD support for C methods
Calling builtin method is at most 10% faster.
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 35a827e..6618d78 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -215,32 +215,24 @@ _PyCFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
}
PyObject *
-_PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
- Py_ssize_t nargs, PyObject *kwnames)
+_PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self, PyObject **args,
+ Py_ssize_t nargs, PyObject *kwnames)
{
- PyCFunctionObject *func;
- PyCFunction meth;
- PyObject *self, *result;
- Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
- int flags;
+ /* _PyMethodDef_RawFastCallKeywords() must not be called with an exception set,
+ because it can clear it (directly or indirectly) and so the
+ caller loses its exception */
+ assert(!PyErr_Occurred());
- assert(func_obj != NULL);
- assert(PyCFunction_Check(func_obj));
+ assert(method != NULL);
assert(nargs >= 0);
assert(kwnames == NULL || PyTuple_CheckExact(kwnames));
- assert((nargs == 0 && nkwargs == 0) || args != NULL);
/* kwnames must only contains str strings, no subclass, and all keys must
be unique */
- /* _PyCFunction_FastCallKeywords() must not be called with an exception
- set, because it can clear it (directly or indirectly) and so the caller
- loses its exception */
- assert(!PyErr_Occurred());
-
- func = (PyCFunctionObject*)func_obj;
- meth = PyCFunction_GET_FUNCTION(func);
- self = PyCFunction_GET_SELF(func);
- flags = PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
+ PyCFunction meth = method->ml_meth;
+ int flags = method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
+ Py_ssize_t nkwargs = kwnames == NULL ? 0 : PyTuple_Size(kwnames);
+ PyObject *result;
switch (flags)
{
@@ -248,7 +240,7 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
if (nargs != 0) {
PyErr_Format(PyExc_TypeError,
"%.200s() takes no arguments (%zd given)",
- func->m_ml->ml_name, nargs);
+ method->ml_name, nargs);
return NULL;
}
@@ -263,7 +255,7 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
if (nargs != 1) {
PyErr_Format(PyExc_TypeError,
"%.200s() takes exactly one argument (%zd given)",
- func->m_ml->ml_name, nargs);
+ method->ml_name, nargs);
return NULL;
}
@@ -326,16 +318,31 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
return NULL;
}
- result = _Py_CheckFunctionResult(func_obj, result, NULL);
return result;
no_keyword_error:
PyErr_Format(PyExc_TypeError,
"%.200s() takes no keyword arguments",
- func->m_ml->ml_name);
+ method->ml_name);
return NULL;
}
+PyObject *
+_PyCFunction_FastCallKeywords(PyObject *func, PyObject **args,
+ Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *result;
+
+ assert(func != NULL);
+ assert(PyCFunction_Check(func));
+
+ result = _PyMethodDef_RawFastCallKeywords(((PyCFunctionObject*)func)->m_ml,
+ PyCFunction_GET_SELF(func),
+ args, nargs, kwnames);
+ result = _Py_CheckFunctionResult(func, result, NULL);
+ return result;
+}
+
/* Methods (the standard built-in methods, that is) */
static void