components/python/python35/patches/11-closerange.patch
author John Beck <John.Beck@Oracle.COM>
Tue, 29 Sep 2015 14:11:08 -0700
changeset 4912 0b79e9575718
child 5184 6c2a9525f3a4
permissions -rw-r--r--
PSARC 2015/414 Python 3.5 21918688 Python 3.5

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

--- Python-3.5.0rc2/Modules/posixmodule.c.~1~	2015-08-25 10:19:14.000000000 -0700
+++ Python-3.5.0rc2/Modules/posixmodule.c	2015-09-02 12:31:54.885953202 -0700
@@ -7781,6 +7781,19 @@
     Py_RETURN_NONE;
 }
 
+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);
+}
 
 /*[clinic input]
 os.closerange
@@ -7797,11 +7810,13 @@
 /*[clinic end generated code: output=70e6adb95220ba96 input=5855a3d053ebd4ec]*/
 {
     int i;
+    int lohi[2];
+
     Py_BEGIN_ALLOW_THREADS
     _Py_BEGIN_SUPPRESS_IPH
-    for (i = fd_low; i < fd_high; i++)
-        if (_PyVerify_fd(i))
-            close(i);
+    lohi[0] = fd_low;
+    lohi[1] = fd_high;
+    fdwalk(close_func, lohi);
     _Py_END_SUPPRESS_IPH
     Py_END_ALLOW_THREADS
     Py_RETURN_NONE;