diff options
author | Zackery Spytz <zspytz@gmail.com> | 2024-01-08 10:33:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 10:33:34 (GMT) |
commit | 73c93265634257b1488262097e024c1727260cfd (patch) | |
tree | 356a9ae1cf8d5019b3bf2dad352c80c750394fdf /Modules/_io | |
parent | e5d0316f35a62df05e1b196689f6998662631836 (diff) | |
download | cpython-73c93265634257b1488262097e024c1727260cfd.zip cpython-73c93265634257b1488262097e024c1727260cfd.tar.gz cpython-73c93265634257b1488262097e024c1727260cfd.tar.bz2 |
gh-80109: Fix io.TextIOWrapper dropping the internal buffer during write() (GH-22535)
io.TextIOWrapper was dropping the internal decoding buffer
during read() and write() calls.
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 4507930..e93c3e0 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1762,8 +1762,10 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) } } - textiowrapper_set_decoded_chars(self, NULL); - Py_CLEAR(self->snapshot); + if (self->snapshot != NULL) { + textiowrapper_set_decoded_chars(self, NULL); + Py_CLEAR(self->snapshot); + } if (self->decoder) { ret = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset)); @@ -1999,8 +2001,10 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) if (result == NULL) goto fail; - textiowrapper_set_decoded_chars(self, NULL); - Py_CLEAR(self->snapshot); + if (self->snapshot != NULL) { + textiowrapper_set_decoded_chars(self, NULL); + Py_CLEAR(self->snapshot); + } return result; } else { |