Steffen Daode Nurpmeso <sdao...@googlemail.com> added the comment:

Will this do?  Otherwise feel free to adjust the patch the way 
Python needs it, i'll learn from that, then, for possible future 
things.  (I need to go down now.)

On Mon, Feb 28, 2011 at 02:37:16PM +0000, Antoine Pitrou wrote:
> 
> Antoine Pitrou <pit...@free.fr> added the comment:
> 
> Your patch is not cleaned up. There are strange things like:
> 
> +            ret ^= ret;
> 
> (while would you xor an off_t?)
> 
> and
> 
> +        do {    off_t x = (*buf)[i].len;
> +                (*iov)[i].iov_len = x;
> +                ret += x;
> +        } while (0);

----------
keywords: +patch
Added file: http://bugs.python.org/file20946/issue11351.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11351>
_______________________________________
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5867,10 +5867,11 @@
 
 #ifdef HAVE_SENDFILE
 #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
-static int
+static off_t
 iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int 
type)
 {
     int i, j;
+    off_t len, ret = 0;
     *iov = PyMem_New(struct iovec, cnt);
     if (*iov == NULL) {
         PyErr_NoMemory();
@@ -5880,7 +5881,7 @@
     if (*buf == NULL) {
         PyMem_Del(*iov);
         PyErr_NoMemory();
-        return 0;
+        return ret;
     }
 
     for (i = 0; i < cnt; i++) {
@@ -5889,14 +5890,17 @@
             PyMem_Del(*iov);
             for (j = 0; j < i; j++) {
                 PyBuffer_Release(&(*buf)[j]);
-           }
+            }
             PyMem_Del(*buf);
-            return 0;
+            ret = 0;
+            return ret;
         }
         (*iov)[i].iov_base = (*buf)[i].buf;
-        (*iov)[i].iov_len = (*buf)[i].len;
-    }
-    return 1;
+        len = (*buf)[i].len;
+        (*iov)[i].iov_len = len;
+        ret += len;
+    }
+    return ret;
 }
 
 static void
@@ -5954,10 +5958,15 @@
                 "sendfile() headers must be a sequence or None");
             return NULL;
         } else {
+            off_t i = 0; /* 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 +5975,15 @@
                 "sendfile() trailers must be a sequence or None");
             return NULL;
         } else {
+            off_t i = 0; /* 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
         }
     }
 
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to