1907
|
1 |
This patch uses fdwalk(3c) to close file descriptors; as that function is not
|
|
2 |
widely implemented, this is unsuitable for upstream.
|
|
3 |
|
|
4 |
--- Python-3.4.0/Modules/posixmodule.c.~1~ 2014-03-16 19:31:31.000000000 -0700
|
|
5 |
+++ Python-3.4.0/Modules/posixmodule.c 2014-03-17 13:31:33.433740698 -0700
|
|
6 |
@@ -7789,16 +7789,34 @@
|
|
7 |
"closerange(fd_low, fd_high)\n\n\
|
|
8 |
Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
|
|
9 |
|
|
10 |
+static int
|
|
11 |
+close_func(void *lohi, int fd)
|
|
12 |
+{
|
|
13 |
+ int lo = ((int *)lohi)[0];
|
|
14 |
+ int hi = ((int *)lohi)[1];
|
|
15 |
+
|
|
16 |
+ if (fd >= hi)
|
|
17 |
+ return (1);
|
|
18 |
+ else if (fd >= lo)
|
|
19 |
+ close(fd);
|
|
20 |
+
|
|
21 |
+ return (0);
|
|
22 |
+}
|
|
23 |
+
|
|
24 |
static PyObject *
|
|
25 |
posix_closerange(PyObject *self, PyObject *args)
|
|
26 |
{
|
|
27 |
int fd_from, fd_to, i;
|
|
28 |
+ int lohi[2];
|
|
29 |
+
|
|
30 |
if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
|
|
31 |
return NULL;
|
|
32 |
Py_BEGIN_ALLOW_THREADS
|
|
33 |
- for (i = fd_from; i < fd_to; i++)
|
|
34 |
- if (_PyVerify_fd(i))
|
|
35 |
- close(i);
|
|
36 |
+
|
|
37 |
+ lohi[0] = fd_from;
|
|
38 |
+ lohi[1] = fd_to;
|
|
39 |
+ fdwalk(close_func, lohi);
|
|
40 |
+
|
|
41 |
Py_END_ALLOW_THREADS
|
|
42 |
Py_RETURN_NONE;
|
|
43 |
}
|