cpython: 3b2c28061184 (original) (raw)

Mercurial > cpython

changeset 89477:3b2c28061184 3.3

Make the various iterators' "setstate" sliently and consistently clip the index. This avoids the possibility of setting an iterator to an invalid state.

Kristján Valur Jónsson sweskman@gmail.com
date Wed, 05 Mar 2014 13:47:57 +0000
parents 24d4e52f4f87
children 08cf35d4ef49 52743dc788e6
files Lib/test/test_range.py Modules/arraymodule.c Objects/bytearrayobject.c Objects/bytesobject.c Objects/listobject.c Objects/rangeobject.c Objects/tupleobject.c Objects/unicodeobject.c
diffstat 8 files changed, 66 insertions(+), 15 deletions(-)[+] [-] Lib/test/test_range.py 12 Modules/arraymodule.c 2 Objects/bytearrayobject.c 10 Objects/bytesobject.c 10 Objects/listobject.c 2 Objects/rangeobject.c 31 Objects/tupleobject.c 4 Objects/unicodeobject.c 10

line wrap: on

line diff

--- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -380,6 +380,18 @@ class RangeTest(unittest.TestCase): self.assertEqual(list(it), data[1:]) def test_exhausted_iterator_pickling(self):

+

--- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2798,6 +2798,8 @@ arrayiter_setstate(arrayiterobject *it, return NULL; if (index < 0) index = 0;

--- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -3043,9 +3043,13 @@ bytearrayiter_setstate(bytesiterobject * Py_ssize_t index = PyLong_AsSsize_t(state); if (index == -1 && PyErr_Occurred()) return NULL;

--- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2996,9 +2996,13 @@ striter_setstate(striterobject *it, PyOb Py_ssize_t index = PyLong_AsSsize_t(state); if (index == -1 && PyErr_Occurred()) return NULL;

--- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2803,6 +2803,8 @@ listiter_setstate(listiterobject *it, Py if (it->it_seq != NULL) { if (index < 0) index = 0;

--- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1000,10 +1000,11 @@ rangeiter_setstate(rangeiterobject *r, P long index = PyLong_AsLong(state); if (index == -1 && PyErr_Occurred()) return NULL;

+

--- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -998,8 +998,8 @@ tupleiter_setstate(tupleiterobject *it, if (it->it_seq != NULL) { if (index < 0) index = 0;

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14420,9 +14420,13 @@ unicodeiter_setstate(unicodeiterobject * Py_ssize_t index = PyLong_AsSsize_t(state); if (index == -1 && PyErr_Occurred()) return NULL;