-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. #9051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lib/test/test_ordered_dict.py
Outdated
('values', [v for k, v in pairs[:1]]), | ||
('items', pairs[:1]), | ||
) | ||
for method_name, items in expected: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems items
is not used.
Lib/test/test_ordered_dict.py
Outdated
next(it) | ||
p = pickle.dumps(it, i) | ||
unpickled = pickle.loads(p) | ||
self.assertEqual(list(it), list(unpickled)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not enough. The state includes a reference to the result tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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