with self.assertRaises(RuntimeError):
n in d
- def test_contains_count_stop_crashes(self):
+ def test_contains_count_index_stop_crashes(self):
class A:
def __eq__(self, other):
d.clear()
with self.assertRaises(RuntimeError):
_ = d.count(3)
+ d = deque([A()])
+ with self.assertRaises(RuntimeError):
+ d.index(0)
+
def test_extend(self):
d = deque('a')
self.assertRaises(TypeError, d.extend, 1)
--- /dev/null
+Fix possible crashes in :meth:`collections.deque.index` when the deque is concurrently modified.
n = stop - i;
while (--n >= 0) {
CHECK_NOT_END(b);
- item = b->data[index];
+ item = Py_NewRef(b->data[index]);
cmp = PyObject_RichCompareBool(item, v, Py_EQ);
+ Py_DECREF(item);
if (cmp > 0)
return PyLong_FromSsize_t(stop - n - 1);
if (cmp < 0)