This patch uses fdwalk(3c) to close file descriptors; as that function is not
widely implemented, this is unsuitable for upstream.
--- Python-3.5.2/Modules/posixmodule.c.~1~ 2016-06-25 14:38:38.000000000 -0700
+++ Python-3.5.2/Modules/posixmodule.c 2016-07-08 06:58:01.808943682 -0700
@@ -7779,6 +7779,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]
@@ -7795,11 +7808,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;