Skip to content

[3.14] gh-160324: Keep io.StringIO state after MemoryError (GH-160325) - #161042

Merged
gpshead merged 3 commits into
python:3.14from
miss-islington:backport-83b047e-3.14
Nov 9, 2026
Merged

gpshead merged 3 commits into
python:3.14from
miss-islington:backport-83b047e-3.14

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Allocate before consuming the accumulated writes in realize() and
make_intermediate(), and reset the size when the contents are lost,
so that later calls do not index outside the internal buffer.

Shrink the buffer of the accumulating writer before finishing it, so
that getvalue(), read() and the other methods leave the contents
unchanged when they fail with MemoryError instead of dropping them.

ANT-2026-MPHGX2FL
(cherry picked from commit 83b047e)

Co-authored-by: Gregory P. Smith 68491+gpshead@users.noreply.github.com

…GH-160325)

Allocate before consuming the accumulated writes in realize() and
make_intermediate(), and reset the size when the contents are lost,
so that later calls do not index outside the internal buffer.

Shrink the buffer of the accumulating writer before finishing it, so
that getvalue(), read() and the other methods leave the contents
unchanged when they fail with MemoryError instead of dropping them.

ANT-2026-MPHGX2FL
(cherry picked from commit 83b047e)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
They do not exist in 3.14. Use PyUnicode_Resize(), which leaves the
buffer unchanged on failure, and update the writer fields directly.
In 3.14, writing a string to a new PyUnicodeWriter copies it, so a
MemoryError there lost the contents of the StringIO.  Disable
overallocation for this write so the writer shares the string
(copy-on-write) instead, as it does in main.
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Nov 9, 2026
@gpshead
gpshead enabled auto-merge (squash) November 9, 2026 03:22
@gpshead
gpshead merged commit df0ee5a into python:3.14 Nov 9, 2026
53 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Nov 9, 2026
@miss-islington
miss-islington deleted the backport-83b047e-3.14 branch November 9, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants