From: Serhiy Storchaka Date: Sat, 30 May 2015 14:48:19 +0000 (+0300) Subject: Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), X-Git-Tag: v3.5.0b2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac5569b1fa483c50edca82bab1ab0a8a927ba86a;p=python Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() to check for and handle errors correctly. --- ac5569b1fa483c50edca82bab1ab0a8a927ba86a diff --cc Misc/NEWS index 2ccbae6fdf,0a4eadb708..d6ff9e44fd --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -10,38 -10,10 +10,42 @@@ Release date: 2015-07-0 Core and Builtins ----------------- + - Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), + PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() + to check for and handle errors correctly. + +- Issue #24328: Fix importing one character extension modules. + +- Issue #11205: In dictionary displays, evaluate the key before the value. + +- Issue #24285: Fixed regression that prevented importing extension modules + from inside packages. Patch by Petr Viktorin. + +Library +------- + +- Issue #24326: Fixed audioop.ratecv() with non-default weightB argument. + Original patch by David Moore. + +- Issue #16991: Add a C implementation of OrderedDict. + + +What's New in Python 3.5.0 beta 1? +================================== + +Release date: 2015-05-24 + +Core and Builtins +----------------- + +- Issue #24276: Fixed optimization of property descriptor getter. + +- Issue #24268: PEP 489: Multi-phase extension module initialization. + Patch by Petr Viktorin. + +- Issue #23955: Add pyvenv.cfg option to suppress registry/environment + lookup for generating sys.path on Windows. + - Issue #24257: Fixed system error in the comparison of faked types.SimpleNamespace. diff --cc Modules/_json.c index e2e8bf3ce3,2f42c3459c..e4478ef420 --- a/Modules/_json.c +++ b/Modules/_json.c @@@ -1345,15 -1236,8 +1351,15 @@@ encoder_init(PyObject *self, PyObject * s->item_separator = item_separator; s->sort_keys = sort_keys; s->skipkeys = skipkeys; - s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii); + s->fast_encode = NULL; + if (PyCFunction_Check(s->encoder)) { + PyCFunction f = PyCFunction_GetFunction(s->encoder); + if (f == (PyCFunction)py_encode_basestring_ascii || + f == (PyCFunction)py_encode_basestring) { + s->fast_encode = f; + } + } - s->allow_nan = PyObject_IsTrue(allow_nan); + s->allow_nan = allow_nan; Py_INCREF(s->markers); Py_INCREF(s->defaultfn); diff --cc Objects/bytesobject.c index c576678c41,57681548b1..6a6e930f73 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@@ -1423,22 -821,18 +1424,32 @@@ bytes_richcompare(PyBytesObject *a, PyB /* Make sure both arguments are strings. */ if (!(PyBytes_Check(a) && PyBytes_Check(b))) { if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) { - if (PyObject_IsInstance((PyObject*)a, - (PyObject*)&PyUnicode_Type) || - PyObject_IsInstance((PyObject*)b, - (PyObject*)&PyUnicode_Type)) { + 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)) + "Comparison between bytes and string", 1)) return NULL; } - else if (PyObject_IsInstance((PyObject*)a, - (PyObject*)&PyLong_Type) || - PyObject_IsInstance((PyObject*)b, - (PyObject*)&PyLong_Type)) { - if (PyErr_WarnEx(PyExc_BytesWarning, - "Comparison between bytes and int", 1)) ++ else { ++ rc = PyObject_IsInstance((PyObject*)a, ++ (PyObject*)&PyLong_Type); ++ if (!rc) ++ rc = PyObject_IsInstance((PyObject*)b, ++ (PyObject*)&PyLong_Type); ++ if (rc < 0) + return NULL; ++ if (rc) { ++ if (PyErr_WarnEx(PyExc_BytesWarning, ++ "Comparison between bytes and int", 1)) ++ return NULL; ++ } + } } result = Py_NotImplemented; } diff --cc Objects/setobject.c index 1805debba1,304519c5d4..d962c1e44a --- a/Objects/setobject.c +++ b/Objects/setobject.c @@@ -1519,10 -1569,16 +1519,16 @@@ set_difference(PySetObject *so, PyObjec 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) == -1) { + if (set_add_entry((PySetObject *)result, &entrycopy)) { Py_DECREF(result); return NULL; }