[Python-checkins] python/dist/src/Lib/test test_deque.py,1.16,1.17

arigo at users.sourceforge.net arigo at users.sourceforge.net
Sat Oct 2 15:59:36 CEST 2004

Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2501/Lib/test

Modified Files:
Log Message:
Upon insertion, if memory runs out, the deque was left in a corrupted state.

deque_item(): a performance bug: the linked list of blocks was followed
from the left in most cases, because the test (i < (deque->len >> 1)) was
after "i %= BLOCKLEN".

deque_clear(): replaced a call to deque_len() with deque->len; not sure what
this call was here for, nor if all compilers under the sun would inline it.

deque_traverse(): I belive that it could be called by the GC when the deque
has leftblock==rightblock==NULL, because it is tracked before the first block
is allocated (though closely before).  Still, a C extension module subclassing
deque could provide its own tp_alloc that could trigger a GC collection after
the PyObject_GC_Track()...

deque_richcompare(): rewrote to cleanly check for end-of-iterations instead of
relying on deque.__iter__().next() to succeed exactly len(deque) times -- an
assumption which can break if deques are subclassed.  Added a test.

I wonder if the length should be explicitely bounded to INT_MAX, with
OverflowErrors, as in listobject.c.  On 64-bit machines, adding more than
INT_MAX in the deque will result in trouble.  (Note to anyone/me fixing
this: carefully check for overflows if len is close to INT_MAX in the
following functions: deque_rotate(), deque_item(), deque_ass_item())

Index: test_deque.py
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_deque.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- test_deque.py	1 Oct 2004 02:01:03 -0000	1.16
+++ test_deque.py	2 Oct 2004 13:59:34 -0000	1.17
@@ -479,6 +479,15 @@
         d = None
         self.assertRaises(ReferenceError, str, p)
+    def test_strange_subclass(self):
+        class X(deque):
+            def __iter__(self):
+                return iter([])
+        d1 = X([1,2,3])
+        d2 = X([4,5,6])
+        d1 == d2   # not clear if this is supposed to be True or False,
+                   # but it used to give a SystemError
 libreftest = """

More information about the Python-checkins mailing list