bpo-44687: Ensure BufferedReader objects with unread buffers can peek even when the underlying file is closed (GH-28457)

This commit is contained in:
AngstyDuck 2021-10-02 04:11:08 +08:00 committed by GitHub
parent cd760ceb67
commit a450398933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -0,0 +1 @@
:meth:`BufferedReader.peek` no longer raises :exc:`ValueError` when the entire file has already been buffered.

View File

@ -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;