components/python/python26/patches/Python26-25-closerange.patch
author Danek Duvall <danek.duvall@oracle.com>
Fri, 04 Nov 2011 10:38:12 -0700
changeset 578 4f51372decaf
child 841 1a62cefa636d
permissions -rw-r--r--
7053223 python needs lint libraries 7097702 python _close_fds from subprocess.py can call close 2 billion times 7103310 os.mknod() not available

--- Python-2.6.4/Modules/posixmodule.c	Wed Sep 16 13:06:36 2009
+++ Python-2.6.4/Modules/posixmodule.c	Thu Nov  3 17:39:15 2011
@@ -6295,15 +6297,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;
 }