Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-25862: Fix an assertion failure in io.TextIOWrapper.tell(). #3918

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

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Oct 7, 2017

Calling read() can call Py_CLEAR(self->snapshot), but self->decoded_chars is not set to NULL in this case. This can cause an assertion failure in tell().

https://bugs.python.org/issue25862

@ZackerySpytz ZackerySpytz force-pushed the bpo-25862-assertion-failure branch from 33e3a5e to 5fd8540 Compare June 23, 2018 12:02
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR @ZackerySpytz. It fixes the original case. But there are other similar cases, and it would be nice to fix them in a single issue. It is enough to fix tell() after write(). Other cases look less rare and more complex. They can be fixed in separate PRs.

@@ -3549,6 +3549,13 @@ def test_reconfigure_newline(self):
expected = 'linesep' + os.linesep + 'LF\nLF\nCR\rCRLF\r\n'
self.assertEqual(txt.detach().getvalue().decode('ascii'), expected)

def test_issue25862(self):
# tell() shouldn't cause an assertion failure if called after read().
t = self.TextIOWrapper(self.BytesIO(b'test'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The encoding depends on the environment. This can affect the test. It is better to specify the encoding explicitly.

@ZackerySpytz ZackerySpytz force-pushed the bpo-25862-assertion-failure branch from eac030f to d00fa36 Compare June 29, 2018 00:02
@ZackerySpytz ZackerySpytz force-pushed the bpo-25862-assertion-failure branch from d00fa36 to 3066cf8 Compare June 29, 2018 03:20
@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.6 labels Jun 29, 2018
@serhiy-storchaka serhiy-storchaka merged commit 23db935 into python:master Jun 29, 2018
@miss-islington
Copy link
Contributor

Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 29, 2018
@bedevere-bot
Copy link

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

@miss-islington
Copy link
Contributor

Sorry, @ZackerySpytz and @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 23db935bcf258657682e66464bf8512def8af830 2.7

@miss-islington
Copy link
Contributor

Sorry, @ZackerySpytz and @serhiy-storchaka, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 23db935bcf258657682e66464bf8512def8af830 3.6

miss-islington added a commit that referenced this pull request Jun 29, 2018
ZackerySpytz added a commit to ZackerySpytz/cpython that referenced this pull request Jun 29, 2018
@bedevere-bot
Copy link

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

serhiy-storchaka pushed a commit that referenced this pull request Jun 29, 2018
ZackerySpytz added a commit to ZackerySpytz/cpython that referenced this pull request Jun 29, 2018
@bedevere-bot
Copy link

GH-8013 is a backport of this pull request to the 2.7 branch.

serhiy-storchaka pushed a commit that referenced this pull request Jun 29, 2018
@ZackerySpytz ZackerySpytz deleted the bpo-25862-assertion-failure branch June 30, 2018 17:18
@serhiy-storchaka serhiy-storchaka removed their assignment Dec 6, 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.

5 participants