Skip to content

Commit 2300bf2

Browse files
committed
Only update the arr variable when PyObject_RichCompareBool() has been called.
1 parent e7ceef6 commit 2300bf2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/_heapqmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ siftup(PyListObject *heap, Py_ssize_t pos)
7878
if (cmp < 0)
7979
return -1;
8080
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
81+
arr = _PyList_ITEMS(heap); /* arr may have changed */
8182
if (endpos != PyList_GET_SIZE(heap)) {
8283
PyErr_SetString(PyExc_RuntimeError,
8384
"list changed size during iteration");
8485
return -1;
8586
}
8687
}
8788
/* Move the smaller child up. */
88-
arr = _PyList_ITEMS(heap);
8989
tmp1 = arr[childpos];
9090
tmp2 = arr[pos];
9191
arr[childpos] = tmp2;
@@ -432,14 +432,14 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
432432
if (cmp < 0)
433433
return -1;
434434
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
435+
arr = _PyList_ITEMS(heap); /* arr may have changed */
435436
if (endpos != PyList_GET_SIZE(heap)) {
436437
PyErr_SetString(PyExc_RuntimeError,
437438
"list changed size during iteration");
438439
return -1;
439440
}
440441
}
441442
/* Move the smaller child up. */
442-
arr = _PyList_ITEMS(heap);
443443
tmp1 = arr[childpos];
444444
tmp2 = arr[pos];
445445
arr[childpos] = tmp2;

0 commit comments

Comments
 (0)