]> granicus.if.org Git - python/commitdiff
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 30 May 2015 14:48:19 +0000 (17:48 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 30 May 2015 14:48:19 +0000 (17:48 +0300)
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.

1  2 
Misc/NEWS
Modules/_json.c
Modules/_threadmodule.c
Modules/faulthandler.c
Objects/bytearrayobject.c
Objects/bytesobject.c
Objects/rangeobject.c
Objects/setobject.c
Python/codecs.c
Python/import.c

diff --cc Misc/NEWS
index 2ccbae6fdfa50914a8d96269fe4f806a1ab2f5f4,0a4eadb7089f5c0be8183eec587b38f778126a50..d6ff9e44fd6e5f3ac20863816d7ca8ffc0696d76
+++ 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 e2e8bf3ce327ce4cd393ce9732df845165df9509,2f42c3459cbb311f15a3167c3e99b852f0f794f8..e4478ef420c0ef61f20d95a431f1bfff69b39104
@@@ -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);
Simple merge
Simple merge
Simple merge
index c576678c410a2f045c48f3cc8d2de9ab78f5fc99,57681548b152616b2a1c88cf9e7896be5ac34ea6..6a6e930f73a01fbfcdcdbeeeed4b583621325187
@@@ -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;
      }
Simple merge
index 1805debba11c7329ee6c27a62ed887c3ef632144,304519c5d472af70209542e47fb11490da545fe0..d962c1e44a0431ba4aeed2de1c2d882380d14941
@@@ -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;
                  }
diff --cc Python/codecs.c
Simple merge
diff --cc Python/import.c
Simple merge