[issue11351] Mac OS X os.sendfile()

Steffen Daode Nurpmeso report at bugs.python.org
Tue Mar 1 14:41:10 CET 2011


Steffen Daode Nurpmeso <sdaoden at googlemail.com> added the comment:

So this is fixed -2.patch supplemented only with 
PyArg_ParseTupleAndKeywords() fixed in a way that re-enables 
correct syntax highlighting.

----------
Added file: http://bugs.python.org/file20959/issue11351-4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11351>
_______________________________________
-------------- next part --------------
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5867,36 +5867,42 @@
 
 #ifdef HAVE_SENDFILE
 #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)
 {
     int i, j;
+    Py_ssize_t blen, total = 0;
+
     *iov = PyMem_New(struct iovec, cnt);
     if (*iov == NULL) {
         PyErr_NoMemory();
-        return 0;
-    }
+        return total;
+    }
+
     *buf = PyMem_New(Py_buffer, cnt);
     if (*buf == NULL) {
         PyMem_Del(*iov);
         PyErr_NoMemory();
-        return 0;
+        return total;
     }
 
     for (i = 0; i < cnt; i++) {
-        if (PyObject_GetBuffer(PySequence_GetItem(seq, i), &(*buf)[i],
-                type) == -1) {
+        if (PyObject_GetBuffer(PySequence_GetItem(seq, i),
+                               &(*buf)[i], type) == -1) {
             PyMem_Del(*iov);
             for (j = 0; j < i; j++) {
                 PyBuffer_Release(&(*buf)[j]);
-           }
+            }
             PyMem_Del(*buf);
-            return 0;
+            total = 0;
+            return total;
         }
         (*iov)[i].iov_base = (*buf)[i].buf;
-        (*iov)[i].iov_len = (*buf)[i].len;
-    }
-    return 1;
+        blen = (*buf)[i].len;
+        (*iov)[i].iov_len = blen;
+        total += blen;
+    }
+    return total;
 }
 
 static void
@@ -5939,14 +5945,17 @@
                                 "offset", "count",
                                 "headers", "trailers", "flags", NULL};
 
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict,
 #ifdef __APPLE__
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile",
-        keywords, &out, &in, _parse_off_t, &offset, _parse_off_t, &sbytes,
+                                     "iiO&O&|OOi:sendfile",
+                                     keywords, &out, &in, _parse_off_t,
+                                     &offset, _parse_off_t, &sbytes,
 #else
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile",
-        keywords, &out, &in, _parse_off_t, &offset, &len,
-#endif
-                &headers, &trailers, &flags))
+                                     "iiO&n|OOi:sendfile",
+                                     keywords, &out, &in,
+                                     _parse_off_t, &offset, &len,
+#endif
+                                     &headers, &trailers, &flags))
             return NULL;
     if (headers != NULL) {
         if (!PySequence_Check(headers)) {
@@ -5954,10 +5963,15 @@
                 "sendfile() headers must be a sequence or None");
             return NULL;
         } else {
+            Py_ssize_t i = 0; /* (Avoid uninitialized warning) */
             sf.hdr_cnt = PySequence_Size(headers);
-            if (sf.hdr_cnt > 0 && !iov_setup(&(sf.headers), &hbuf,
-                    headers, sf.hdr_cnt, PyBUF_SIMPLE))
+            if (sf.hdr_cnt > 0 &&
+                !(i = iov_setup(&(sf.headers), &hbuf,
+                                headers, sf.hdr_cnt, PyBUF_SIMPLE)))
                 return NULL;
+#ifdef __APPLE__
+            sbytes += i;
+#endif
         }
     }
     if (trailers != NULL) {
@@ -5966,10 +5980,15 @@
                 "sendfile() trailers must be a sequence or None");
             return NULL;
         } else {
+            Py_ssize_t i = 0; /* (Avoid uninitialized warning) */
             sf.trl_cnt = PySequence_Size(trailers);
-            if (sf.trl_cnt > 0 && !iov_setup(&(sf.trailers), &tbuf,
-                    trailers, sf.trl_cnt, PyBUF_SIMPLE))
+            if (sf.trl_cnt > 0 &&
+                !(i = iov_setup(&(sf.trailers), &tbuf,
+                                trailers, sf.trl_cnt, PyBUF_SIMPLE)))
                 return NULL;
+#ifdef __APPLE__
+            sbytes += i;
+#endif
         }
     }
 


More information about the Python-bugs-list mailing list