diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-10-01 20:30:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-01 20:30:15 (GMT) |
commit | 2221207f44c2abd34406ee590e6b13afaca53ee8 (patch) | |
tree | c19226b744d99112cf5140da23746a303717e123 /Modules | |
parent | 6df8c327532627d6a99991993c52e8e4a9b34968 (diff) | |
download | cpython-2221207f44c2abd34406ee590e6b13afaca53ee8.zip cpython-2221207f44c2abd34406ee590e6b13afaca53ee8.tar.gz cpython-2221207f44c2abd34406ee590e6b13afaca53ee8.tar.bz2 |
bpo-44687: Ensure BufferedReader objects with unread buffers can peek even when the underlying file is closed (GH-28457)
(cherry picked from commit a450398933d265011e1e8eae7f771b70f97945fb)
Co-authored-by: AngstyDuck <solsticedante@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/bufferedio.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 5984d34..ba966f5 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -341,11 +341,10 @@ _enter_buffered_busy(buffered *self) : buffered_closed(self))) #define CHECK_CLOSED(self, error_msg) \ - if (IS_CLOSED(self)) { \ + if (IS_CLOSED(self) & (Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t) == 0)) { \ PyErr_SetString(PyExc_ValueError, error_msg); \ return NULL; \ - } - + } \ #define VALID_READ_BUFFER(self) \ (self->readable && self->read_end != -1) @@ -530,6 +529,9 @@ buffered_close(buffered *self, PyObject *args) Py_CLEAR(res); } + self->read_end = 0; + self->pos = 0; + end: LEAVE_BUFFERED(self) return res; |