summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-12-08 23:31:47 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-12-08 23:31:47 (GMT)
commitef7def94c7c681a10031e88efd6511f5c4ff2c75 (patch)
treefa6a39994a3072cf8e272582e1cd725eab3b2686 /Objects
parente9abde4642451f17d98e43aacc2bac74f83451c3 (diff)
downloadcpython-ef7def94c7c681a10031e88efd6511f5c4ff2c75.zip
cpython-ef7def94c7c681a10031e88efd6511f5c4ff2c75.tar.gz
cpython-ef7def94c7c681a10031e88efd6511f5c4ff2c75.tar.bz2
_PyObject_CallFunctionVa() uses fast call
Issue #28915: Use _Py_VaBuildStack() to build a C array of PyObject* and then use _PyObject_FastCall(). The function has a special case if the stack only contains one parameter and the parameter is a tuple: "unpack" the tuple of arguments in this case.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 4f59f04..5c3344c 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2523,7 +2523,12 @@ static PyObject *
_PyObject_CallFunctionVa(PyObject *callable, const char *format,
va_list va, int is_size_t)
{
- PyObject *args, *result;
+ PyObject* small_stack[5];
+ /*const Py_ssize_t small_stack_len = Py_ARRAY_LENGTH(small_stack);*/
+ const Py_ssize_t small_stack_len = 0;
+ PyObject **stack;
+ Py_ssize_t nargs, i;
+ PyObject *result;
if (callable == NULL) {
return null_error();
@@ -2534,24 +2539,35 @@ _PyObject_CallFunctionVa(PyObject *callable, const char *format,
}
if (is_size_t) {
- args = Py_VaBuildValue(format, va);
+ stack = _Py_VaBuildStack(small_stack, small_stack_len, format, va, &nargs);
}
else {
- args = _Py_VaBuildValue_SizeT(format, va);
+ stack = _Py_VaBuildStack_SizeT(small_stack, small_stack_len, format, va, &nargs);
}
- if (args == NULL) {
+ if (stack == NULL) {
return NULL;
}
- if (!PyTuple_Check(args)) {
- PyObject *stack[1] = {args};
- result = _PyObject_FastCall(callable, stack, 1);
+ if (nargs == 1 && PyTuple_Check(stack[0])) {
+ /* Special cases:
+ - PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
+ - PyObject_CallFunction(func, "(OOO)", arg1, arg2, arg3) calls
+ func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */
+ PyObject *args = stack[0];
+ result = _PyObject_FastCall(callable,
+ &PyTuple_GET_ITEM(args, 0),
+ PyTuple_GET_SIZE(args));
}
else {
- result = PyObject_Call(callable, args, NULL);
+ result = _PyObject_FastCall(callable, stack, nargs);
}
- Py_DECREF(args);
+ for (i = 0; i < nargs; ++i) {
+ Py_DECREF(stack[i]);
+ }
+ if (stack != small_stack) {
+ PyMem_Free(stack);
+ }
return result;
}