8000 bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. by sir-sigurd · Pull Request #9051 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 4 commits into from
Oct 20, 2018

Conversation

sir-sigurd
Copy link
Contributor
@sir-sigurd sir-sigurd commented Sep 4, 2018

('values', [v for k, v in pairs[:1]]),
('items', pairs[:1]),
)
for method_name, items in expected:
Copy link
Member

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.

next(it)
p = pickle.dumps(it, i)
unpickled = pickle.loads(p)
self.assertEqual(list(it), list(unpickled))
Copy link
Member

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);
Copy link
Member

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.

8000

Copy link
Contributor Author

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.

@vstinner
Copy link
Member

@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?

@serhiy-storchaka serhiy-storchaka merged commit a5259fb into python:master Oct 20, 2018
@miss-islington
Copy link
Contributor

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.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-9996 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 20, 2018
…ing. (pythonGH-9051)

(cherry picked from commit a5259fb)

Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
@bedevere-bot
Copy link

GH-9997 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 20, 2018
…ing. (pythonGH-9051)

(cherry picked from commit a5259fb)

Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
miss-islington added a commit that referenced this pull request Oct 20, 2018
…ing. (GH-9051)

(cherry picked from commit a5259fb)

Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
miss-islington added a commit that referenced this pull request Oct 20, 2018
…ing. (GH-9051)

(cherry picked from commit a5259fb)

Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
@sir-sigurd sir-sigurd deleted the odictiter-reduce branch October 20, 2018 10:11
@serhiy-storchaka serhiy-storchaka removed their assignment Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0