components/python/python34/patches/11-closerange.patch
author Girish Moodalbail <Girish.Moodalbail@oracle.COM>
Tue, 02 Jun 2015 12:43:22 -0600
changeset 4389 a44bb9a2917e
parent 3869 eb4c6284602f
child 5229 b7b91ddbbdce
permissions -rw-r--r--
21086485 neutron-l3-agent service should not report online if trace dump happened 21157386 dhcp & metadata agents trace dump due to report state failure

This patch uses fdwalk(3c) to close file descriptors; as that function is not
widely implemented, this is unsuitable for upstream.

--- Python-3.4.3/Modules/posixmodule.c.~1~	2015-02-25 03:27:46.000000000 -0800
+++ Python-3.4.3/Modules/posixmodule.c	2015-02-25 08:22:50.773678769 -0800
@@ -7809,16 +7809,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++)
-        if (_PyVerify_fd(i))
-            close(i);
+
+    lohi[0] = fd_from;
+    lohi[1] = fd_to;
+    fdwalk(close_func, lohi);
+
     Py_END_ALLOW_THREADS
     Py_RETURN_NONE;
 }