mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue 11351 - apply patch by Steffen Daode Nurpmeso which should fix TestSendfile.test_headers failure on OSX.
This commit is contained in:
parent
de3dc0f66c
commit
acdad9a40b
1 changed files with 29 additions and 13 deletions
|
|
@ -5867,36 +5867,42 @@ posix_write(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
#ifdef HAVE_SENDFILE
|
#ifdef HAVE_SENDFILE
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||||
static int
|
static Py_ssize_t
|
||||||
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
|
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
Py_ssize_t blen, total = 0;
|
||||||
|
|
||||||
*iov = PyMem_New(struct iovec, cnt);
|
*iov = PyMem_New(struct iovec, cnt);
|
||||||
if (*iov == NULL) {
|
if (*iov == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return 0;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buf = PyMem_New(Py_buffer, cnt);
|
*buf = PyMem_New(Py_buffer, cnt);
|
||||||
if (*buf == NULL) {
|
if (*buf == NULL) {
|
||||||
PyMem_Del(*iov);
|
PyMem_Del(*iov);
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return 0;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
if (PyObject_GetBuffer(PySequence_GetItem(seq, i), &(*buf)[i],
|
if (PyObject_GetBuffer(PySequence_GetItem(seq, i),
|
||||||
type) == -1) {
|
&(*buf)[i], type) == -1) {
|
||||||
PyMem_Del(*iov);
|
PyMem_Del(*iov);
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
PyBuffer_Release(&(*buf)[j]);
|
PyBuffer_Release(&(*buf)[j]);
|
||||||
}
|
}
|
||||||
PyMem_Del(*buf);
|
PyMem_Del(*buf);
|
||||||
return 0;
|
total = 0;
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
(*iov)[i].iov_base = (*buf)[i].buf;
|
(*iov)[i].iov_base = (*buf)[i].buf;
|
||||||
(*iov)[i].iov_len = (*buf)[i].len;
|
blen = (*buf)[i].len;
|
||||||
|
(*iov)[i].iov_len = blen;
|
||||||
|
total += blen;
|
||||||
}
|
}
|
||||||
return 1;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -5954,10 +5960,15 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
"sendfile() headers must be a sequence or None");
|
"sendfile() headers must be a sequence or None");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
|
Py_ssize_t i = 0; /* Avoid uninitialized warning */
|
||||||
sf.hdr_cnt = PySequence_Size(headers);
|
sf.hdr_cnt = PySequence_Size(headers);
|
||||||
if (sf.hdr_cnt > 0 && !iov_setup(&(sf.headers), &hbuf,
|
if (sf.hdr_cnt > 0 &&
|
||||||
headers, sf.hdr_cnt, PyBUF_SIMPLE))
|
!(i = iov_setup(&(sf.headers), &hbuf,
|
||||||
|
headers, sf.hdr_cnt, PyBUF_SIMPLE)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
sbytes += i;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trailers != NULL) {
|
if (trailers != NULL) {
|
||||||
|
|
@ -5966,10 +5977,15 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
"sendfile() trailers must be a sequence or None");
|
"sendfile() trailers must be a sequence or None");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
|
Py_ssize_t i = 0; /* Avoid uninitialized warning */
|
||||||
sf.trl_cnt = PySequence_Size(trailers);
|
sf.trl_cnt = PySequence_Size(trailers);
|
||||||
if (sf.trl_cnt > 0 && !iov_setup(&(sf.trailers), &tbuf,
|
if (sf.trl_cnt > 0 &&
|
||||||
trailers, sf.trl_cnt, PyBUF_SIMPLE))
|
!(i = iov_setup(&(sf.trailers), &tbuf,
|
||||||
|
trailers, sf.trl_cnt, PyBUF_SIMPLE)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
sbytes += i;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue