gh-115059: Flush the underlying write buffer in io.BufferedRandom.read1() (GH-115163)

This commit is contained in:
Serhiy Storchaka 2024-02-09 12:36:12 +02:00 • committed by GitHub
parent c968dc7ff3
commit 846fd721d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 0 deletions

View file

@ -1050,6 +1050,16 @@ _io__Buffered_read1_impl(buffered *self, Py_ssize_t n)
Py_DECREF(res);
return NULL;
}
/* Flush the write buffer if necessary */
if (self->writable) {
PyObject *r = buffered_flush_and_rewind_unlocked(self);
if (r == NULL) {
LEAVE_BUFFERED(self)
Py_DECREF(res);
return NULL;
}
Py_DECREF(r);
}
_bufferedreader_reset_buf(self);
r = _bufferedreader_raw_read(self, PyBytes_AS_STRING(res), n);
LEAVE_BUFFERED(self)