components/python/python26/patches/Python26-25-closerange.patch
author John Beck <John.Beck@Oracle.COM>
Mon, 23 Sep 2013 15:04:26 -0700
branchs11-update
changeset 2773 8d29ec07e743
parent 841 1a62cefa636d
permissions -rw-r--r--
17457626 Python regression test_ssl fails due to missing certificate file

--- Python-2.6.8/Modules/posixmodule.c.orig	2012-05-14 06:31:28.561995103 -0700
+++ Python-2.6.8/Modules/posixmodule.c	2012-05-14 06:34:39.031503970 -0700
@@ -6378,15 +6378,34 @@
 "closerange(fd_low, fd_high)\n\n\
 Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
 
+static int
+close_func(void *lohi, int fd)
+{
+    int lo = ((int *)lohi)[0];
+    int hi = ((int *)lohi)[1];
+
+    if (fd >= hi)
+        return (1);
+    else if (fd >= lo)
+        close(fd);
+
+    return (0);
+}
+
 static PyObject *
 posix_closerange(PyObject *self, PyObject *args)
 {
     int fd_from, fd_to, i;
+    int lohi[2];
+
     if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
         return NULL;
     Py_BEGIN_ALLOW_THREADS
-    for (i = fd_from; i < fd_to; i++)
-        close(i);
+
+    lohi[0] = fd_from;
+    lohi[1] = fd_to;
+    fdwalk(close_func, lohi);
+
     Py_END_ALLOW_THREADS
     Py_RETURN_NONE;
 }