summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-03-04 19:35:55 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-03-04 19:35:55 (GMT)
commit221760a3aa89545bc15b126d6723bb037f6e612d (patch)
tree7a7bd1ad7ecda741a9e6c413076c3e9216569066 /Lib
parent42f382facd09e4ae9e2a3a082c35bd7e3ce33931 (diff)
parent31584e30ab3e8d01613bb774b1e3d28e73314096 (diff)
downloadcpython-221760a3aa89545bc15b126d6723bb037f6e612d.zip
cpython-221760a3aa89545bc15b126d6723bb037f6e612d.tar.gz
cpython-221760a3aa89545bc15b126d6723bb037f6e612d.tar.bz2
Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is being resized concurrently.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_heapq.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 54395c0..b48ca68 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -319,6 +319,16 @@ def L(seqn):
return chain(map(lambda x:x, R(Ig(G(seqn)))))
+class SideEffectLT:
+ def __init__(self, value, heap):
+ self.value = value
+ self.heap = heap
+
+ def __lt__(self, other):
+ self.heap[:] = []
+ return self.value < other.value
+
+
class TestErrorHandling:
def test_non_sequence(self):
@@ -369,6 +379,22 @@ class TestErrorHandling:
self.assertRaises(TypeError, f, 2, N(s))
self.assertRaises(ZeroDivisionError, f, 2, E(s))
+ # Issue #17278: the heap may change size while it's being walked.
+
+ def test_heappush_mutating_heap(self):
+ heap = []
+ heap.extend(SideEffectLT(i, heap) for i in range(200))
+ # Python version raises IndexError, C version RuntimeError
+ with self.assertRaises((IndexError, RuntimeError)):
+ self.module.heappush(heap, SideEffectLT(5, heap))
+
+ def test_heappop_mutating_heap(self):
+ heap = []
+ heap.extend(SideEffectLT(i, heap) for i in range(200))
+ # Python version raises IndexError, C version RuntimeError
+ with self.assertRaises((IndexError, RuntimeError)):
+ self.module.heappop(heap)
+
class TestErrorHandlingPython(TestErrorHandling, TestCase):
module = py_heapq