]> granicus.if.org Git - python/commitdiff
Only update the arr variable when PyObject_RichCompareBool() has been called.
authorRaymond Hettinger <python@rcn.com>
Tue, 8 Dec 2015 04:45:16 +0000 (20:45 -0800)
committerRaymond Hettinger <python@rcn.com>
Tue, 8 Dec 2015 04:45:16 +0000 (20:45 -0800)
Modules/_heapqmodule.c

index 28604afee9593b939b00cdde6bb75aa74c633150..1c37c75c8fd61a3edea46a0eb7603bf0ef062947 100644 (file)
@@ -78,6 +78,7 @@ siftup(PyListObject *heap, Py_ssize_t pos)
             if (cmp < 0)
                 return -1;
             childpos += ((unsigned)cmp ^ 1);   /* increment when cmp==0 */
+            arr = _PyList_ITEMS(heap);         /* arr may have changed */
             if (endpos != PyList_GET_SIZE(heap)) {
                 PyErr_SetString(PyExc_RuntimeError,
                                 "list changed size during iteration");
@@ -85,7 +86,6 @@ siftup(PyListObject *heap, Py_ssize_t pos)
             }
         }
         /* Move the smaller child up. */
-        arr = _PyList_ITEMS(heap);
         tmp1 = arr[childpos];
         tmp2 = arr[pos];
         arr[childpos] = tmp2;
@@ -432,6 +432,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
             if (cmp < 0)
                 return -1;
             childpos += ((unsigned)cmp ^ 1);   /* increment when cmp==0 */
+            arr = _PyList_ITEMS(heap);         /* arr may have changed */
             if (endpos != PyList_GET_SIZE(heap)) {
                 PyErr_SetString(PyExc_RuntimeError,
                                 "list changed size during iteration");
@@ -439,7 +440,6 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
             }
         }
         /* Move the smaller child up. */
-        arr = _PyList_ITEMS(heap);
         tmp1 = arr[childpos];
         tmp2 = arr[pos];
         arr[childpos] = tmp2;