summaryrefslogtreecommitdiffstats
path: root/Modules/_io/iobase.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2012-06-24 06:55:39 (GMT)
committerGregory P. Smith <greg@krypto.org>2012-06-24 06:55:39 (GMT)
commit5135992164f4c0df8d18d3b486431b28214db16b (patch)
tree7bc3060d22ad740bf2bf795caae1c6a46232f6e7 /Modules/_io/iobase.c
parent8150492f11f17e2a09f7deb7af706536bc326c98 (diff)
downloadcpython-5135992164f4c0df8d18d3b486431b28214db16b.zip
cpython-5135992164f4c0df8d18d3b486431b28214db16b.tar.gz
cpython-5135992164f4c0df8d18d3b486431b28214db16b.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.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 35c7cdd..2bba1bf 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -482,8 +482,14 @@ iobase_readline(PyObject *self, PyObject *args)
if (has_peek) {
PyObject *readahead = PyObject_CallMethod(self, "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, "
@@ -516,8 +522,14 @@ iobase_readline(PyObject *self, PyObject *args)
}
b = PyObject_CallMethod(self, "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, "
@@ -826,6 +838,11 @@ rawiobase_readall(PyObject *self, PyObject *args)
PyObject *data = PyObject_CallMethod(self, "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;
}