Commit 10c7e864 authored by Tim Peters's avatar Tim Peters

deque_traverse(): If the deque had one block, and its rightindex was

BLOCKLEN-1, this assert-failed in a debug build, or went wild with a
NULL pointer in a release build.  Reported on c.l.py by Stefan Behnel.
parent d6e00327
...@@ -324,6 +324,15 @@ class TestBasic(unittest.TestCase): ...@@ -324,6 +324,15 @@ class TestBasic(unittest.TestCase):
for s in ('abcd', xrange(2000)): for s in ('abcd', xrange(2000)):
self.assertEqual(list(reversed(deque(s))), list(reversed(s))) self.assertEqual(list(reversed(deque(s))), list(reversed(s)))
def test_gc_doesnt_blowup(self):
import gc
# This used to assert-fail in deque_traverse() under a debug
# build, or run wild with a NULL pointer in a release build.
d = deque()
for i in xrange(100):
d.append(1)
gc.collect()
def R(seqn): def R(seqn):
'Regular generator' 'Regular generator'
for i in seqn: for i in seqn:
......
...@@ -478,20 +478,23 @@ deque_dealloc(dequeobject *deque) ...@@ -478,20 +478,23 @@ deque_dealloc(dequeobject *deque)
static int static int
deque_traverse(dequeobject *deque, visitproc visit, void *arg) deque_traverse(dequeobject *deque, visitproc visit, void *arg)
{ {
block * b = deque->leftblock; block *b;
int index = deque->leftindex;
PyObject *item; PyObject *item;
int index;
int indexlo = deque->leftindex;
assert(deque->leftblock != NULL);
for (b = deque->leftblock; b != NULL; b = b->rightlink) {
const int indexhi = b == deque->rightblock ?
deque->rightindex :
BLOCKLEN - 1;
while (b != deque->rightblock || index <= deque->rightindex) { for (index = indexlo; index <= indexhi; ++index) {
item = b->data[index]; item = b->data[index];
index++;
if (index == BLOCKLEN ) {
assert(b->rightlink != NULL);
b = b->rightlink;
index = 0;
}
Py_VISIT(item); Py_VISIT(item);
} }
indexlo = 0;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment