author | John Beck <John.Beck@Oracle.COM> |
Tue, 22 Dec 2015 07:57:25 -0800 | |
changeset 5229 | b7b91ddbbdce |
parent 3869 | eb4c6284602f |
permissions | -rw-r--r-- |
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 |
||
3869
eb4c6284602f
20605341 update Python to 3.4.3
John Beck <John.Beck@Oracle.COM>
parents:
1907
diff
changeset
|
4 |
--- Python-3.4.3/Modules/posixmodule.c.~1~ 2015-02-25 03:27:46.000000000 -0800 |
eb4c6284602f
20605341 update Python to 3.4.3
John Beck <John.Beck@Oracle.COM>
parents:
1907
diff
changeset
|
5 |
+++ Python-3.4.3/Modules/posixmodule.c 2015-02-25 08:22:50.773678769 -0800 |
5229
b7b91ddbbdce
22456127 Upgrade Python 3.4 line to 3.4.4
John Beck <John.Beck@Oracle.COM>
parents:
3869
diff
changeset
|
6 |
@@ -7830,16 +7830,34 @@ |
1907 | 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 |
} |