Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.

Patch by Serhiy Storchaka.
This commit is contained in:
Antoine Pitrou 2012-08-15 23:20:39 +02:00
commit 721738fbee
10 changed files with 76 additions and 74 deletions

View file

@ -1105,11 +1105,13 @@ dropwhile_next(dropwhileobject *lz)
}
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 @@ static PyObject *
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 @@ takewhile_next(takewhileobject *lz)
}
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 @@ static PyObject *
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 @@ compress_next(compressobject *lz)
if (ok == 1)
return datum;
Py_DECREF(datum);
if (ok == -1)
if (ok < 0)
return NULL;
}
}
@ -3692,9 +3695,11 @@ filterfalse_next(filterfalseobject *lz)
ok = PyObject_IsTrue(good);
Py_DECREF(good);
}
if (!ok)
if (ok == 0)
return item;
Py_DECREF(item);
if (ok < 0)
return NULL;
}
}