diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-08 14:26:12 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-08 14:26:12 (GMT) |
commit | 149e540adf47ccd57ac36afe265b7740a9dd74fc (patch) | |
tree | 398a86594984dcd1df3877b11e9b82938a6fdd75 /Modules/posixmodule.c | |
parent | e4314e05d5d96eed8a3f25db779f853fc5514969 (diff) | |
parent | 57ddf78b6b18d9da6f466b4e6da0437c3271196e (diff) | |
download | cpython-149e540adf47ccd57ac36afe265b7740a9dd74fc.zip cpython-149e540adf47ccd57ac36afe265b7740a9dd74fc.tar.gz cpython-149e540adf47ccd57ac36afe265b7740a9dd74fc.tar.bz2 |
(Merge 3.3) Issue #20113: os.readv() and os.writev() now raise an OSError
exception on error instead of returning -1.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3a66316..f9dc735 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8011,14 +8011,14 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type) *iov = PyMem_New(struct iovec, cnt); if (*iov == NULL) { PyErr_NoMemory(); - return total; + return -1; } *buf = PyMem_New(Py_buffer, cnt); if (*buf == NULL) { PyMem_Del(*iov); PyErr_NoMemory(); - return total; + return -1; } for (i = 0; i < cnt; i++) { @@ -8043,7 +8043,7 @@ fail: PyBuffer_Release(&(*buf)[j]); } PyMem_Del(*buf); - return 0; + return -1; } static void @@ -8083,7 +8083,7 @@ posix_readv(PyObject *self, PyObject *args) } cnt = PySequence_Size(seq); - if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_WRITABLE)) + if (iov_setup(&iov, &buf, seq, cnt, PyBUF_WRITABLE) < 0) return NULL; Py_BEGIN_ALLOW_THREADS @@ -8091,6 +8091,9 @@ posix_readv(PyObject *self, PyObject *args) Py_END_ALLOW_THREADS iov_cleanup(iov, buf, cnt); + if (n < 0) + return posix_error(); + return PyLong_FromSsize_t(n); } #endif @@ -8216,8 +8219,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) Py_ssize_t i = 0; /* Avoid uninitialized warning */ sf.hdr_cnt = PySequence_Size(headers); if (sf.hdr_cnt > 0 && - !(i = iov_setup(&(sf.headers), &hbuf, - headers, sf.hdr_cnt, PyBUF_SIMPLE))) + (i = iov_setup(&(sf.headers), &hbuf, + headers, sf.hdr_cnt, PyBUF_SIMPLE)) < 0) return NULL; #ifdef __APPLE__ sbytes += i; @@ -8233,8 +8236,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) Py_ssize_t i = 0; /* Avoid uninitialized warning */ sf.trl_cnt = PySequence_Size(trailers); if (sf.trl_cnt > 0 && - !(i = iov_setup(&(sf.trailers), &tbuf, - trailers, sf.trl_cnt, PyBUF_SIMPLE))) + (i = iov_setup(&(sf.trailers), &tbuf, + trailers, sf.trl_cnt, PyBUF_SIMPLE)) < 0) return NULL; #ifdef __APPLE__ sbytes += i; @@ -8475,7 +8478,7 @@ posix_writev(PyObject *self, PyObject *args) } cnt = PySequence_Size(seq); - if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_SIMPLE)) { + if (iov_setup(&iov, &buf, seq, cnt, PyBUF_SIMPLE) < 0) { return NULL; } @@ -8484,6 +8487,9 @@ posix_writev(PyObject *self, PyObject *args) Py_END_ALLOW_THREADS iov_cleanup(iov, buf, cnt); + if (res < 0) + return posix_error(); + return PyLong_FromSsize_t(res); } #endif |