8000 Fix compiler warnings. · python/cpython@9852e27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9852e27

Browse files
Fix compiler warnings.
1 parent 4dae576 commit 9852e27

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Python/bltinmodule.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ builtin_locals_impl(PyObject *module)
17681768
static PyObject *
17691769
min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
17701770
{
1771-
PyObject *it, *item, *val, *maxitem, *maxval, *keyfunc=NULL;
1771+
PyObject *it = NULL, *item, *val, *maxitem, *maxval, *keyfunc=NULL;
17721772
PyObject *defaultval = NULL;
17731773
static const char * const keywords[] = {"key", "default", NULL};
17741774
static _PyArg_Parser _parser_min = {"|$OO:min", keywords, 0};
@@ -1807,13 +1807,23 @@ min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
18071807

18081808
maxitem = NULL; /* the result */
18091809
maxval = NULL; /* the value associated with the result */
1810-
int i = 0;
1811-
while (positional ?
1812-
((i < nargs) && (item = args[i++]))
1813-
: !!(item = PyIter_Next(it))) {
1814-
if (positional) {
1810+
while (1) {
1811+
if (it == NULL) {
1812+
if (nargs-- <= 0) {
1813+
break;
1814+
}
1815+
item = *args++;
18151816
Py_INCREF(item);
18161817
}
1818+
else {
1819+
item = PyIter_Next(it);
1820+
if (item == NULL) {
1821+
if (PyErr_Occurred()) {
1822+
goto Fail_it;
1823+
}
1824+
break;
1825+
}
1826+
}
18171827

18181828
/* get the value from the key function */
18191829
if (keyfunc != NULL) {
@@ -1848,8 +1858,6 @@ min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
18481858
}
18491859
}
18501860
}
1851-
if (PyErr_Occurred())
1852-
goto Fail_it;
18531861
if (maxval == NULL) {
18541862
assert(maxitem == NULL);
18551863
if (defaultval != NULL) {
@@ -1861,9 +1869,7 @@ min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
18611869
}
18621870
else
18631871
Py_DECREF(maxval);
1864-
if (!positional) {
1865-
Py_DECREF(it);
1866-
}
1872+
Py_XDECREF(it);
18671873
return maxitem;
18681874

18691875
Fail_it_item_and_val:
@@ -1873,9 +1879,7 @@ min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
18731879
Fail_it:
18741880
Py_XDECREF(maxval);
18751881
Py_XDECREF(maxitem);
1876-
if (!positional) {
1877-
Py_DECREF(it);
1878-
}
1882+
Py_XDECREF(it);
18791883
return NULL;
18801884
}
18811885

0 commit comments

Comments
 (0)
0