Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 194f7fb..9115b67 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1105,11 +1105,13 @@
}
ok = PyObject_IsTrue(good);
Py_DECREF(good);
- if (!ok) {
+ if (ok == 0) {
lz->start = 1;
return item;
}
Py_DECREF(item);
+ if (ok < 0)
+ return NULL;
}
}
@@ -1124,7 +1126,7 @@
dropwhile_setstate(dropwhileobject *lz, PyObject *state)
{
int start = PyObject_IsTrue(state);
- if (start == -1)
+ if (start < 0)
return NULL;
lz->start = start;
Py_RETURN_NONE;
@@ -1270,10 +1272,11 @@
}
ok = PyObject_IsTrue(good);
Py_DECREF(good);
- if (ok)
+ if (ok == 1)
return item;
Py_DECREF(item);
- lz->stop = 1;
+ if (ok == 0)
+ lz->stop = 1;
return NULL;
}
@@ -1288,7 +1291,7 @@
takewhile_reduce_setstate(takewhileobject *lz, PyObject *state)
{
int stop = PyObject_IsTrue(state);
- if (stop == -1)
+ if (stop < 0)
return NULL;
lz->stop = stop;
Py_RETURN_NONE;
@@ -3536,7 +3539,7 @@
if (ok == 1)
return datum;
Py_DECREF(datum);
- if (ok == -1)
+ if (ok < 0)
return NULL;
}
}
@@ -3692,9 +3695,11 @@
ok = PyObject_IsTrue(good);
Py_DECREF(good);
}
- if (!ok)
+ if (ok == 0)
return item;
Py_DECREF(item);
+ if (ok < 0)
+ return NULL;
}
}