summaryrefslogtreecommitdiff
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index a77dfe84c1..00a85b5741 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1156,43 +1156,27 @@ map_traverse(mapobject *lz, visitproc visit, void *arg)
static PyObject *
map_next(mapobject *lz)
{
- PyObject *small_stack[5];
- PyObject **stack;
- Py_ssize_t niters, nargs, i;
- PyObject *result = NULL;
+ PyObject *val;
+ PyObject *argtuple;
+ PyObject *result;
+ Py_ssize_t numargs, i;
- niters = PyTuple_GET_SIZE(lz->iters);
- if (niters <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
- stack = small_stack;
- }
- else {
- stack = PyMem_Malloc(niters * sizeof(PyObject*));
- if (stack == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
- }
+ numargs = PyTuple_GET_SIZE(lz->iters);
+ argtuple = PyTuple_New(numargs);
+ if (argtuple == NULL)
+ return NULL;
- nargs = 0;
- for (i=0; i < niters; i++) {
+ for (i=0 ; i<numargs ; i++) {
PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
- PyObject *val = Py_TYPE(it)->tp_iternext(it);
+ val = Py_TYPE(it)->tp_iternext(it);
if (val == NULL) {
- goto exit;
+ Py_DECREF(argtuple);
+ return NULL;
}
- stack[i] = val;
- nargs++;
- }
-
- result = _PyObject_FastCall(lz->func, stack, nargs);
-
-exit:
- for (i=0; i < nargs; i++) {
- Py_DECREF(stack[i]);
- }
- if (stack != small_stack) {
- PyMem_Free(stack);
+ PyTuple_SET_ITEM(argtuple, i, val);
}
+ result = PyObject_Call(lz->func, argtuple, NULL);
+ Py_DECREF(argtuple);
return result;
}