Skip to content

Commit 4fb9389

Browse files
committed
fix
1 parent 32d767f commit 4fb9389

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Modules/_heapqmodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ siftdown_max(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
441441
arr = _PyList_ITEMS(heap);
442442
parent = arr[parentpos];
443443
newitem = arr[pos];
444-
arr[parentpos] = newitem;
445-
arr[pos] = parent;
444+
FT_ATOMIC_STORE_PTR_RELAXED(arr[parentpos], newitem);
445+
FT_ATOMIC_STORE_PTR_RELAXED(arr[pos], parent);
446446
pos = parentpos;
447447
}
448448
return 0;
@@ -490,8 +490,8 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
490490
/* Move the smaller child up. */
491491
tmp1 = arr[childpos];
492492
tmp2 = arr[pos];
493-
arr[childpos] = tmp2;
494-
arr[pos] = tmp1;
493+
FT_ATOMIC_STORE_PTR_RELAXED(arr[childpos], tmp2);
494+
FT_ATOMIC_STORE_PTR_RELAXED(arr[pos], tmp1);
495495
pos = childpos;
496496
}
497497
/* Bubble it up to its final resting place (by sifting its parents down). */
@@ -625,8 +625,9 @@ _heapq_heappushpop_max_impl(PyObject *module, PyObject *heap, PyObject *item)
625625
}
626626

627627
returnitem = PyList_GET_ITEM(heap, 0);
628-
PyList_SET_ITEM(heap, 0, Py_NewRef(item));
629-
if (siftup_max((PyListObject *)heap, 0) < 0) {
628+
PyListObject * list = _PyList_CAST(heap);
629+
FT_ATOMIC_STORE_PTR_RELAXED(list->ob_item[0], Py_NewRef(item));
630+
if (siftup_max(list, 0) < 0) {
630631
Py_DECREF(returnitem);
631632
return NULL;
632633
}

0 commit comments

Comments
 (0)