diff options
author | Barry Warsaw <barry@python.org> | 1998-10-01 15:33:12 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-10-01 15:33:12 (GMT) |
commit | 968f8cbacea38d991cb5c8816da1235355c004df (patch) | |
tree | e4c92e3be7754325ac1f434d50ed8cb078ba8bc5 /Python/bltinmodule.c | |
parent | 566373e974413de66ad1d627f322908597eb2efd (diff) | |
download | cpython-968f8cbacea38d991cb5c8816da1235355c004df.zip cpython-968f8cbacea38d991cb5c8816da1235355c004df.tar.gz cpython-968f8cbacea38d991cb5c8816da1235355c004df.tar.bz2 |
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4f91397..f88ed7a 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -101,20 +101,32 @@ builtin_apply(self, args) PyObject *args; { PyObject *func, *alist = NULL, *kwdict = NULL; + PyObject *t = NULL, *retval = NULL; if (!PyArg_ParseTuple(args, "O|OO:apply", &func, &alist, &kwdict)) return NULL; - if (alist != NULL && !PyTuple_Check(alist)) { - PyErr_SetString(PyExc_TypeError, - "apply() 2nd argument must be tuple"); - return NULL; + if (alist != NULL) { + if (!PyTuple_Check(alist)) { + if (!PySequence_Check(alist)) { + PyErr_SetString(PyExc_TypeError, + "apply() 2nd argument must be a sequence"); + return NULL; + } + t = PySequence_Tuple(alist); + if (t == NULL) + return NULL; + alist = t; + } } if (kwdict != NULL && !PyDict_Check(kwdict)) { PyErr_SetString(PyExc_TypeError, "apply() 3rd argument must be dictionary"); - return NULL; + goto finally; } - return PyEval_CallObjectWithKeywords(func, alist, kwdict); + retval = PyEval_CallObjectWithKeywords(func, alist, kwdict); + finally: + Py_XDECREF(t); + return retval; } static char apply_doc[] = |