Minor code cleanup for PyArg_UnpackTuple.

This commit is contained in:
Raymond Hettinger 2016-03-26 03:02:48 -07:00
parent 53b0a41d31
commit 942302371c
1 changed files with 8 additions and 9 deletions

View File

@ -1771,16 +1771,9 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
PyObject **o;
va_list vargs;
#ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, max);
#else
va_start(vargs);
#endif
assert(min >= 0);
assert(min <= max);
if (!PyTuple_Check(args)) {
va_end(vargs);
PyErr_SetString(PyExc_SystemError,
"PyArg_UnpackTuple() argument list is not a tuple");
return 0;
@ -1798,9 +1791,10 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
"unpacked tuple should have %s%zd elements,"
" but has %zd",
(min == max ? "" : "at least "), min, l);
va_end(vargs);
return 0;
}
if (l == 0)
return 1;
if (l > max) {
if (name != NULL)
PyErr_Format(
@ -1813,9 +1807,14 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
"unpacked tuple should have %s%zd elements,"
" but has %zd",
(min == max ? "" : "at most "), max, l);
va_end(vargs);
return 0;
}
#ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, max);
#else
va_start(vargs);
#endif
for (i = 0; i < l; i++) {
o = va_arg(vargs, PyObject **);
*o = PyTuple_GET_ITEM(args, i);