Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9423023

Browse files
committed
Minor code cleanup for PyArg_UnpackTuple.
1 parent 53b0a41 commit 9423023

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Python/getargs.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,16 +1771,9 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
17711771
PyObject **o;
17721772
va_list vargs;
17731773

1774-
#ifdef HAVE_STDARG_PROTOTYPES
1775-
va_start(vargs, max);
1776-
#else
1777-
va_start(vargs);
1778-
#endif
1779-
17801774
assert(min >= 0);
17811775
assert(min <= max);
17821776
if (!PyTuple_Check(args)) {
1783-
va_end(vargs);
17841777
PyErr_SetString(PyExc_SystemError,
17851778
"PyArg_UnpackTuple() argument list is not a tuple");
17861779
return 0;
@@ -1798,9 +1791,10 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
17981791
"unpacked tuple should have %s%zd elements,"
17991792
" but has %zd",
18001793
(min == max ? "" : "at least "), min, l);
1801-
va_end(vargs);
18021794
return 0;
18031795
}
1796+
if (l == 0)
1797+
return 1;
18041798
if (l > max) {
18051799
if (name != NULL)
18061800
PyErr_Format(
@@ -1813,9 +1807,14 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
18131807
"unpacked tuple should have %s%zd elements,"
18141808
" but has %zd",
18151809
(min == max ? "" : "at most "), max, l);
1816-
va_end(vargs);
18171810
return 0;
18181811
}
1812+
1813+
#ifdef HAVE_STDARG_PROTOTYPES
1814+
va_start(vargs, max);
1815+
#else
1816+
va_start(vargs);
1817+
#endif
18191818
for (i = 0; i < l; i++) {
18201819
o = va_arg(vargs, PyObject **);
18211820
*o = PyTuple_GET_ITEM(args, i);

0 commit comments

Comments
 (0)