[Python-checkins] cpython (merge 3.5 -> default): Merge from 3.5.

eric.snow python-checkins at python.org
Sat May 30 20:55:44 CEST 2015


https://hg.python.org/cpython/rev/39acefd27d8d
changeset:   96400:39acefd27d8d
parent:      96398:6f99cd255237
parent:      96399:030205f1e716
user:        Eric Snow <ericsnowcurrently at gmail.com>
date:        Sat May 30 12:55:22 2015 -0600
summary:
  Merge from 3.5.

files:
  Objects/odictobject.c |  26 ++++++++++++++------------
  1 files changed, 14 insertions(+), 12 deletions(-)


diff --git a/Objects/odictobject.c b/Objects/odictobject.c
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1030,8 +1030,7 @@
             goto Done;
         if (!ns_len) {
             /* nothing novel to pickle in od.__dict__ */
-            Py_DECREF(ns);
-            ns = NULL;
+            Py_CLEAR(ns);
         }
     }
 
@@ -1184,8 +1183,7 @@
             value = PyObject_GetItem(od, key);
             if (value != NULL) {
                 if (PyObject_DelItem(od, key) == -1) {
-                    Py_DECREF(value);
-                    value = NULL;
+                    Py_CLEAR(value);
                 }
             }
         }
@@ -1718,10 +1716,10 @@
 {
     PyObject *od = PyDict_Type.tp_new(type, args, kwds);
     if (od != NULL) {
+        if (_odict_initialize((PyODictObject *)od) < 0)
+            return NULL;
         ((PyODictObject *)od)->od_inst_dict = PyDict_New();
         ((PyODictObject *)od)->od_weakreflist = NULL;
-        if (_odict_initialize((PyODictObject *)od) < 0)
-            return NULL;
     }
     return od;
 }
@@ -1845,8 +1843,7 @@
     node = _odict_find_node(di->di_odict, di->di_current);
     if (node == NULL) {
         /* Must have been deleted. */
-        Py_DECREF(di->di_current);
-        di->di_current = NULL;
+        Py_CLEAR(di->di_current);
         return NULL;
     }
     key = di->di_current;
@@ -1884,8 +1881,11 @@
         PyObject *result = di->di_result;
 
         value = PyODict_GetItem((PyObject *)di->di_odict, key);  /* borrowed */
-        if (value == NULL)
+        if (value == NULL) {
+            Py_DECREF(key);
             return NULL;
+        }
+        Py_INCREF(value);
 
         if (result->ob_refcnt == 1) {
             /* not in use so we can reuse it
@@ -1896,11 +1896,13 @@
         }
         else {
             result = PyTuple_New(2);
-            if (result == NULL)
+            if (result == NULL) {
+                Py_DECREF(key);
+                Py_DECREF(value);
                 return NULL;
+            }
         }
 
-        Py_INCREF(value);
         PyTuple_SET_ITEM(result, 0, key);  /* steals reference */
         PyTuple_SET_ITEM(result, 1, value);  /* steals reference */
 
@@ -2365,7 +2367,6 @@
         else if (PyObject_HasAttrString(other, "keys")) {  /* never fails */
             PyObject *keys, *iterator, *key;
             keys = PyObject_CallMethod(other, "keys", NULL);
-            Py_DECREF(other);
             if (keys == NULL)
                 return NULL;
             iterator = PyObject_GetIter(keys);
@@ -2383,6 +2384,7 @@
                 }
                 Py_DECREF(key);
             }
+            Py_DECREF(other);
             Py_DECREF(iterator);
             if (res != 0 || PyErr_Occurred())
                 return NULL;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list