mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() to check for and handle errors correctly.
This commit is contained in:
commit
ac5569b1fa
10 changed files with 92 additions and 40 deletions
|
@ -1519,9 +1519,15 @@ set_difference(PySetObject *so, PyObject *other)
|
|||
if (PyDict_CheckExact(other)) {
|
||||
while (set_next(so, &pos, &entry)) {
|
||||
setentry entrycopy;
|
||||
int rv;
|
||||
entrycopy.hash = entry->hash;
|
||||
entrycopy.key = entry->key;
|
||||
if (!_PyDict_Contains(other, entry->key, entry->hash)) {
|
||||
rv = _PyDict_Contains(other, entry->key, entry->hash);
|
||||
if (rv < 0) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
if (!rv) {
|
||||
if (set_add_entry((PySetObject *)result, &entrycopy)) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
|
@ -1757,7 +1763,8 @@ PyDoc_STRVAR(issuperset_doc, "Report whether this set contains another set.");
|
|||
static PyObject *
|
||||
set_richcompare(PySetObject *v, PyObject *w, int op)
|
||||
{
|
||||
PyObject *r1, *r2;
|
||||
PyObject *r1;
|
||||
int r2;
|
||||
|
||||
if(!PyAnySet_Check(w))
|
||||
Py_RETURN_NOTIMPLEMENTED;
|
||||
|
@ -1775,9 +1782,11 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
|
|||
r1 = set_richcompare(v, w, Py_EQ);
|
||||
if (r1 == NULL)
|
||||
return NULL;
|
||||
r2 = PyBool_FromLong(PyObject_Not(r1));
|
||||
r2 = PyObject_IsTrue(r1);
|
||||
Py_DECREF(r1);
|
||||
return r2;
|
||||
if (r2 < 0)
|
||||
return NULL;
|
||||
return PyBool_FromLong(!r2);
|
||||
case Py_LE:
|
||||
return set_issubset(v, w);
|
||||
case Py_GE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue