summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-08-23 22:59:40 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-08-23 22:59:40 (GMT)
commitd48af09043e3f84bc8d3d0e2d9adb4f0be2a70fd (patch)
tree5ca52d94c2515faa65fca0873bb7a4c53875bd50 /Objects/abstract.c
parentf0cba67d0b145738dcce92c7ad768eafee82b3e1 (diff)
downloadcpython-d48af09043e3f84bc8d3d0e2d9adb4f0be2a70fd.zip
cpython-d48af09043e3f84bc8d3d0e2d9adb4f0be2a70fd.tar.gz
cpython-d48af09043e3f84bc8d3d0e2d9adb4f0be2a70fd.tar.bz2
Backed out changeset 0e4f26083bbb (PyObject_CallMethodObjArgs)
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c103
1 files changed, 32 insertions, 71 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 14021ba..0e67693 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2499,52 +2499,32 @@ _PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name,
return retval;
}
-static PyObject **
-objargs_mkstack(PyObject **small_stack, Py_ssize_t small_stack_size,
- va_list va, Py_ssize_t *p_nargs)
+static PyObject *
+objargs_mktuple(va_list va)
{
- Py_ssize_t i, n;
+ int i, n = 0;
va_list countva;
- PyObject **stack;
+ PyObject *result, *tmp;
- /* Count the number of arguments */
- Py_VA_COPY(countva, va);
+ Py_VA_COPY(countva, va);
- n = 0;
- while (1) {
- PyObject *arg = (PyObject *)va_arg(countva, PyObject *);
- if (arg == NULL) {
- break;
- }
- n++;
- }
- *p_nargs = n;
-
- /* Copy arguments */
- if (small_stack_size <= n) {
- stack = small_stack;
- }
- else {
- stack = PyMem_Malloc(n * sizeof(PyObject**));
- if (stack == NULL) {
- PyErr_NoMemory();
- return NULL;
+ while (((PyObject *)va_arg(countva, PyObject *)) != NULL)
+ ++n;
+ result = PyTuple_New(n);
+ if (result != NULL && n > 0) {
+ for (i = 0; i < n; ++i) {
+ tmp = (PyObject *)va_arg(va, PyObject *);
+ PyTuple_SET_ITEM(result, i, tmp);
+ Py_INCREF(tmp);
}
}
-
- for (i = 0; i < n; ++i) {
- stack[i] = va_arg(va, PyObject *);
- }
- return stack;
+ return result;
}
PyObject *
PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...)
{
- PyObject *small_stack[5];
- PyObject **stack;
- Py_ssize_t nargs;
- PyObject *result;
+ PyObject *args, *tmp;
va_list vargs;
if (callable == NULL || name == NULL) {
@@ -2557,31 +2537,24 @@ PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...)
/* count the args */
va_start(vargs, name);
- stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack),
- vargs, &nargs);
+ args = objargs_mktuple(vargs);
va_end(vargs);
- if (stack == NULL) {
+ if (args == NULL) {
Py_DECREF(callable);
return NULL;
}
-
- result = _PyObject_FastCall(callable, stack, nargs);
+ tmp = PyObject_Call(callable, args, NULL);
+ Py_DECREF(args);
Py_DECREF(callable);
- if (stack != small_stack) {
- PyMem_Free(stack);
- }
- return result;
+ return tmp;
}
PyObject *
_PyObject_CallMethodIdObjArgs(PyObject *callable,
struct _Py_Identifier *name, ...)
{
- PyObject *small_stack[5];
- PyObject **stack;
- Py_ssize_t nargs;
- PyObject *result;
+ PyObject *args, *tmp;
va_list vargs;
if (callable == NULL || name == NULL) {
@@ -2594,30 +2567,23 @@ _PyObject_CallMethodIdObjArgs(PyObject *callable,
/* count the args */
va_start(vargs, name);
- stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack),
- vargs, &nargs);
+ args = objargs_mktuple(vargs);
va_end(vargs);
- if (stack == NULL) {
+ if (args == NULL) {
Py_DECREF(callable);
return NULL;
}
-
- result = _PyObject_FastCall(callable, stack, nargs);
+ tmp = PyObject_Call(callable, args, NULL);
+ Py_DECREF(args);
Py_DECREF(callable);
- if (stack != small_stack) {
- PyMem_Free(stack);
- }
- return result;
+ return tmp;
}
PyObject *
PyObject_CallFunctionObjArgs(PyObject *callable, ...)
{
- PyObject *small_stack[5];
- PyObject **stack;
- Py_ssize_t nargs;
- PyObject *result;
+ PyObject *args, *tmp;
va_list vargs;
if (callable == NULL) {
@@ -2626,19 +2592,14 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...)
/* count the args */
va_start(vargs, callable);
- stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack),
- vargs, &nargs);
+ args = objargs_mktuple(vargs);
va_end(vargs);
- if (stack == NULL) {
+ if (args == NULL)
return NULL;
- }
-
- result = _PyObject_FastCall(callable, stack, nargs);
- if (stack != small_stack) {
- PyMem_Free(stack);
- }
+ tmp = PyObject_Call(callable, args, NULL);
+ Py_DECREF(args);
- return result;
+ return tmp;
}