bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling.#9051
Conversation
| ('values', [v for k, v in pairs[:1]]), | ||
| ('items', pairs[:1]), | ||
| ) | ||
| for method_name, items in expected: |
There was a problem hiding this comment.
Seems items is not used.
| next(it) | ||
| p = pickle.dumps(it, i) | ||
| unpickled = pickle.loads(p) | ||
| self.assertEqual(list(it), list(unpickled)) |
There was a problem hiding this comment.
This test will be passed if the original iterator is exhausted and an empty list is pickled.
I would test:
expected = list(meth())[1:]
self.assertEqual(list(it), expected)
self.assertEqual(list(it), expected)| return NULL; | ||
| /* copy the iterator state */ | ||
| odictiterobject tmp = *di; | ||
| Py_XINCREF(tmp.di_odict); |
There was a problem hiding this comment.
This is not enough. The state includes a reference to the result tuple.
There was a problem hiding this comment.
It looks like the problem wasn't caused by the result tuple.
|
@serhiy-storchaka: you approved this change, but then asked a question. It's unclear to me if you fully approved this change... @pablogsal: Would you mind to review it? |
|
Thanks @sir-sigurd for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
|
GH-9996 is a backport of this pull request to the 3.7 branch. |
…ing. (pythonGH-9051) (cherry picked from commit a5259fb) Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
|
GH-9997 is a backport of this pull request to the 3.6 branch. |
…ing. (pythonGH-9051) (cherry picked from commit a5259fb) Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
https://bugs.python.org/issue34574