mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-44687: Ensure BufferedReader objects with unread buffers can peek even when the underlying file is closed (GH-28457)
This commit is contained in:
parent
cd760ceb67
commit
a450398933
2 changed files with 6 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue