mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
Fix zero-length corner case for iterating over a mutating deque.
This commit is contained in:
parent
f96725af8b
commit
5b44cbe6d8
3 changed files with 11 additions and 3 deletions
|
@ -396,6 +396,12 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
||||||
d.pop()
|
d.pop()
|
||||||
self.assertRaises(RuntimeError, it.next)
|
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):
|
class Deque(deque):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,9 @@ Extension Modules
|
||||||
|
|
||||||
- Added support for linking the bsddb module against BerkeleyDB 4.5.x.
|
- Added support for linking the bsddb module against BerkeleyDB 4.5.x.
|
||||||
|
|
||||||
|
- Modifying an empty deque during iteration now raises RuntimeError
|
||||||
|
instead of StopIteration.
|
||||||
|
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -911,15 +911,14 @@ dequeiter_next(dequeiterobject *it)
|
||||||
{
|
{
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
|
|
||||||
if (it->counter == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (it->deque->state != it->state) {
|
if (it->deque->state != it->state) {
|
||||||
it->counter = 0;
|
it->counter = 0;
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
"deque mutated during iteration");
|
"deque mutated during iteration");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (it->counter == 0)
|
||||||
|
return NULL;
|
||||||
assert (!(it->b == it->deque->rightblock &&
|
assert (!(it->b == it->deque->rightblock &&
|
||||||
it->index > it->deque->rightindex));
|
it->index > it->deque->rightindex));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue