Repository navigation
Commit df0ee5a
* gh-160324: Keep `io.StringIO` state after `MemoryError` (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>
* Avoid _PyUnicodeWriter_SetBuffer() and _PyUnicode_ResizeCompact()
They do not exist in 3.14. Use PyUnicode_Resize(), which leaves the
buffer unchanged on failure, and update the writer fields directly.
* Do not copy the intermediate string in make_intermediate()
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.
---------
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 576f556 commit df0ee5a
3 files changed
Lines changed: 98 additions & 18 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules/_io
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1067 | 1067 | | |
1068 | 1068 | | |
1069 | 1069 | | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1070 | 1103 | | |
1071 | 1104 | | |
1072 | 1105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
132 | 156 | | |
133 | 157 | | |
134 | 158 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
139 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
140 | 168 | | |
141 | | - | |
142 | | - | |
143 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
144 | 174 | | |
145 | 175 | | |
146 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
147 | 182 | | |
| 183 | + | |
148 | 184 | | |
149 | 185 | | |
150 | | - | |
151 | 186 | | |
152 | 187 | | |
153 | 188 | | |
| |||
160 | 195 | | |
161 | 196 | | |
162 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
163 | 206 | | |
164 | 207 | | |
165 | 208 | | |
166 | 209 | | |
167 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
168 | 213 | | |
| 214 | + | |
169 | 215 | | |
170 | | - | |
171 | | - | |
172 | | - | |
| 216 | + | |
173 | 217 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 218 | + | |
178 | 219 | | |
179 | 220 | | |
| 221 | + | |
180 | 222 | | |
181 | 223 | | |
182 | 224 | | |
| |||
344 | 386 | | |
345 | 387 | | |
346 | 388 | | |
347 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
348 | 392 | | |
349 | 393 | | |
350 | 394 | | |
| |||
0 commit comments