diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-02-09 10:36:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 10:36:12 (GMT) |
commit | 846fd721d518dda88a7d427ec3d2c03c45d9fa90 (patch) | |
tree | 4c6b5f8e5dcc88646b945c1532e1be8835399eec /Modules/_io | |
parent | c968dc7ff3041137bb702436ff944692dede1ad1 (diff) | |
download | cpython-846fd721d518dda88a7d427ec3d2c03c45d9fa90.zip cpython-846fd721d518dda88a7d427ec3d2c03c45d9fa90.tar.gz cpython-846fd721d518dda88a7d427ec3d2c03c45d9fa90.tar.bz2 |
gh-115059: Flush the underlying write buffer in io.BufferedRandom.read1() (GH-115163)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bufferedio.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index f02207a..8ebe9ec 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -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) |