mirror of https://github.com/python/cpython
Fix zero-length corner case for iterating over a mutating deque.
This commit is contained in:
parent
1812f8cf3f
commit
51c2f6cd18
|
@ -396,6 +396,12 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
|||
d.pop()
|
||||
self.assertRaises(RuntimeError, it.next)
|
||||
|
||||
def test_runtime_error_on_empty_deque(self):
|
||||
d = deque()
|
||||
it = iter(d)
|
||||
d.append(10)
|
||||
self.assertRaises(RuntimeError, it.next)
|
||||
|
||||
class Deque(deque):
|
||||
pass
|
||||
|
||||
|
|
|
@ -911,15 +911,14 @@ dequeiter_next(dequeiterobject *it)
|
|||
{
|
||||
PyObject *item;
|
||||
|
||||
if (it->counter == 0)
|
||||
return NULL;
|
||||
|
||||
if (it->deque->state != it->state) {
|
||||
it->counter = 0;
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"deque mutated during iteration");
|
||||
return NULL;
|
||||
}
|
||||
if (it->counter == 0)
|
||||
return NULL;
|
||||
assert (!(it->b == it->deque->rightblock &&
|
||||
it->index > it->deque->rightindex));
|
||||
|
||||
|
|
Loading…
Reference in New Issue