summaryrefslogtreecommitdiffstats
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
authorJeroen Demeyer <J.Demeyer@UGent.be>2019-05-29 18:31:52 (GMT)
committerPetr Viktorin <encukou@gmail.com>2019-05-29 18:31:52 (GMT)
commitaacc77fbd77640a8f03638216fa09372cc21673d (patch)
treefd64be1c4c1167a8bf708d1fd22c733cf3a9a30f /Objects/methodobject.c
parentd30da5dd9a8a965cf24a22bbaff8a5b1341c2944 (diff)
downloadcpython-aacc77fbd77640a8f03638216fa09372cc21673d.zip
cpython-aacc77fbd77640a8f03638216fa09372cc21673d.tar.gz
cpython-aacc77fbd77640a8f03638216fa09372cc21673d.tar.bz2
bpo-36974: implement PEP 590 (GH-13185)
Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be> Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 9fed3fc..76497c9 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -46,6 +46,14 @@ PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
op->m_self = self;
Py_XINCREF(module);
op->m_module = module;
+ if (ml->ml_flags & METH_VARARGS) {
+ /* For METH_VARARGS functions, it's more efficient to use tp_call
+ * instead of vectorcall. */
+ op->vectorcall = NULL;
+ }
+ else {
+ op->vectorcall = &_PyCFunction_FastCallKeywords;
+ }
_PyObject_GC_TRACK(op);
return (PyObject *)op;
}
@@ -264,7 +272,7 @@ PyTypeObject PyCFunction_Type = {
sizeof(PyCFunctionObject),
0,
(destructor)meth_dealloc, /* tp_dealloc */
- 0, /* tp_print */
+ offsetof(PyCFunctionObject, vectorcall), /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
@@ -278,7 +286,8 @@ PyTypeObject PyCFunction_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ _Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */
0, /* tp_doc */
(traverseproc)meth_traverse, /* tp_traverse */
0, /* tp_clear */