Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
lawrence-danna-apple committed Jul 21, 2020
commit 03dd9af5a45188d77169f07f595f01b3331ad4b3
212 changes: 111 additions & 101 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9289,64 +9289,69 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
int flags)
/*[clinic end generated code: output=26fc9c6e58e7ada5 input=4173919dc1f7ed99]*/
{
if (HAVE_PREADV_RUNTIME) {
Py_ssize_t cnt, n;
int async_err = 0;
struct iovec *iov;
Py_buffer *buf;
/* preadv method will be deleted if preadv is not available */
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif

if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"preadv2() arg 2 must be a sequence");
return -1;
}
Py_ssize_t cnt, n;
int async_err = 0;
struct iovec *iov;
Py_buffer *buf;

cnt = PySequence_Size(buffers);
if (cnt < 0) {
return -1;
}
if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"preadv2() arg 2 must be a sequence");
return -1;
}

#ifndef HAVE_PREADV2
if(flags != 0) {
argument_unavailable_error("preadv2", "flags");
return -1;
}
#endif
cnt = PySequence_Size(buffers);
if (cnt < 0) {
return -1;
}

if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0) {
return -1;
}
#ifdef HAVE_PREADV2
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
n = preadv2(fd, iov, cnt, offset, flags);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#else
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
n = preadv(fd, iov, cnt, offset);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#endif
#ifndef HAVE_PREADV2
if(flags != 0) {
argument_unavailable_error("preadv2", "flags");
return -1;
}
#endif

iov_cleanup(iov, buf, cnt);
if (n < 0) {
if (!async_err) {
posix_error();
}
return -1;
}
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0) {
return -1;
}
#ifdef HAVE_PREADV2
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
n = preadv2(fd, iov, cnt, offset, flags);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#else
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
n = preadv(fd, iov, cnt, offset);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#endif

return n;
} else {
PyErr_SetString(PyExc_NotImplementedError, "preadv is not available");
iov_cleanup(iov, buf, cnt);
if (n < 0) {
if (!async_err) {
posix_error();
}
return -1;
}

return n;

#if __clang__
#pragma clang diagnostic pop
#endif
}
#endif /* HAVE_PREADV */

Expand Down Expand Up @@ -9889,65 +9894,70 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
int flags)
/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=35358c327e1a2a8e]*/
{
if (HAVE_PWRITEV_RUNTIME) {
Py_ssize_t cnt;
Py_ssize_t result;
int async_err = 0;
struct iovec *iov;
Py_buffer *buf;
/* pwritev method will be deleted if preadv is not available */
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif

if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"pwritev() arg 2 must be a sequence");
return -1;
}
Py_ssize_t cnt;
Py_ssize_t result;
int async_err = 0;
struct iovec *iov;
Py_buffer *buf;

cnt = PySequence_Size(buffers);
if (cnt < 0) {
return -1;
}
if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"pwritev() arg 2 must be a sequence");
return -1;
}

#ifndef HAVE_PWRITEV2
if(flags != 0) {
argument_unavailable_error("pwritev2", "flags");
return -1;
}
#endif
cnt = PySequence_Size(buffers);
if (cnt < 0) {
return -1;
}

if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) {
return -1;
}
#ifdef HAVE_PWRITEV2
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
result = pwritev2(fd, iov, cnt, offset, flags);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#else
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
result = pwritev(fd, iov, cnt, offset);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#endif
#ifndef HAVE_PWRITEV2
if(flags != 0) {
argument_unavailable_error("pwritev2", "flags");
return -1;
}
#endif

iov_cleanup(iov, buf, cnt);
if (result < 0) {
if (!async_err) {
posix_error();
}
return -1;
}
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) {
return -1;
}
#ifdef HAVE_PWRITEV2
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
result = pwritev2(fd, iov, cnt, offset, flags);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#else
do {
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
result = pwritev(fd, iov, cnt, offset);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
#endif

return result;
} else {
PyErr_SetString(PyExc_NotImplementedError, "preadv is not available");
iov_cleanup(iov, buf, cnt);
if (result < 0) {
if (!async_err) {
posix_error();
}
return -1;
}

return result;

#if __clang__
#pragma clang diagnostic pop
#endif
}
#endif /* HAVE_PWRITEV */

Expand Down