diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-06-24 07:23:47 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-06-24 07:23:47 (GMT) |
commit | 990a5feba77de7fc5fd5ad5a16f61dc93667f63e (patch) | |
tree | b0fdb65c20e4a233f59a60c4aa2081949a9cf441 /Modules/_io/iobase.c | |
parent | 80d440aee198abc4077f7c30ecbf0a14e42c6eea (diff) | |
parent | 5135992164f4c0df8d18d3b486431b28214db16b (diff) | |
download | cpython-990a5feba77de7fc5fd5ad5a16f61dc93667f63e.zip cpython-990a5feba77de7fc5fd5ad5a16f61dc93667f63e.tar.gz cpython-990a5feba77de7fc5fd5ad5a16f61dc93667f63e.tar.bz2 |
Fixes issue #12268: File readline, readlines and read() or readall() methods
no longer lose data when an underlying read system call is interrupted.
IOError is no longer raised due to a read system call returning EINTR
from within these methods.
Diffstat (limited to 'Modules/_io/iobase.c')
-rw-r--r-- | Modules/_io/iobase.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index b30bbb6..dd052ae 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -474,11 +474,15 @@ iobase_readline(PyObject *self, PyObject *args) PyObject *b; if (has_peek) { - _Py_IDENTIFIER(peek); PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1); - - if (readahead == NULL) + if (readahead == NULL) { + /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() + when EINTR occurs so we needn't do it ourselves. */ + if (_PyIO_trap_eintr()) { + continue; + } goto fail; + } if (!PyBytes_Check(readahead)) { PyErr_Format(PyExc_IOError, "peek() should have returned a bytes object, " @@ -511,8 +515,14 @@ iobase_readline(PyObject *self, PyObject *args) } b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead); - if (b == NULL) + if (b == NULL) { + /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() + when EINTR occurs so we needn't do it ourselves. */ + if (_PyIO_trap_eintr()) { + continue; + } goto fail; + } if (!PyBytes_Check(b)) { PyErr_Format(PyExc_IOError, "read() should have returned a bytes object, " @@ -827,6 +837,11 @@ rawiobase_readall(PyObject *self, PyObject *args) PyObject *data = _PyObject_CallMethodId(self, &PyId_read, "i", DEFAULT_BUFFER_SIZE); if (!data) { + /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() + when EINTR occurs so we needn't do it ourselves. */ + if (_PyIO_trap_eintr()) { + continue; + } Py_DECREF(chunks); return NULL; } |