[Python-checkins] python/nondist/sandbox/collections dequemodule.c, 1.5, 1.6 test_deque.py, 1.3, 1.4

rhettinger at projects.sourceforge.net rhettinger at projects.sourceforge.net
Tue Jan 27 10:04:26 EST 2004


Update of /cvsroot/python/python/nondist/sandbox/collections
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29890

Modified Files:
	dequemodule.c test_deque.py 
Log Message:
Protect the iterator from changes in the underlying data.



Index: dequemodule.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/collections/dequemodule.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** dequemodule.c	27 Jan 2004 14:41:30 -0000	1.5
--- dequemodule.c	27 Jan 2004 15:04:24 -0000	1.6
***************
*** 441,444 ****
--- 441,445 ----
  	block *b;
  	dequeobject *deque;
+ 	int len;
  } dequeiterobject;
  
***************
*** 457,460 ****
--- 458,462 ----
  	Py_INCREF(deque);
  	it->deque = deque;
+ 	it->len = deque->len;
  	return (PyObject *)it;
  }
***************
*** 474,477 ****
--- 476,486 ----
  		return NULL;
  
+ 	if (it->len != it->deque->len) {
+ 		it->len = -1; /* Make this state sticky */
+ 		PyErr_SetString(PyExc_RuntimeError,
+ 				"deque changed size during iteration");
+ 		return NULL;
+ 	}
+ 
  	item = it->b->data[it->index];
  	it->index++;

Index: test_deque.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/collections/test_deque.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** test_deque.py	27 Jan 2004 14:41:30 -0000	1.3
--- test_deque.py	27 Jan 2004 15:04:24 -0000	1.4
***************
*** 257,260 ****
--- 257,266 ----
              self.assertRaises(ZeroDivisionError, deque, E(s))
  
+     def test_iter_with_altered_data(self):
+         d = deque('abcdefg')
+         it = iter(d)
+         d.pop()
+         self.assertRaises(RuntimeError, it.next)
+ 
  class Deque(deque):
      pass




More information about the Python-checkins mailing list