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:
Serhiy Storchaka 2015-05-30 17:45:22 +03:00
parent 50451eb912
commit fa494fd883
10 changed files with 83 additions and 36 deletions

View file

@ -816,17 +816,23 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
Py_ssize_t len_a, len_b;
Py_ssize_t min_len;
PyObject *result;
int rc;
/* Make sure both arguments are strings. */
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE) &&
(PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type) ||
PyObject_IsInstance((PyObject*)b,
(PyObject*)&PyUnicode_Type))) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytes and string", 1))
if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) {
rc = PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type);
if (!rc)
rc = PyObject_IsInstance((PyObject*)b,
(PyObject*)&PyUnicode_Type);
if (rc < 0)
return NULL;
if (rc) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytes and string", 1))
return NULL;
}
}
result = Py_NotImplemented;
}