components/python/python34/patches/11-closerange.patch
author John Beck <John.Beck@Oracle.COM>
Wed, 22 Oct 2014 15:26:11 -0700
branchs11-update
changeset 3785 6a3f91179f05
parent 3778 35735ffdda43
child 3869 eb4c6284602f
permissions -rw-r--r--
19877230 importing native module causes python 3.4 to fail further imports from .py files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3778
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     1
This patch uses fdwalk(3c) to close file descriptors; as that function is not
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     2
widely implemented, this is unsuitable for upstream.
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     3
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     4
--- Python-3.4.0/Modules/posixmodule.c.~1~	2014-03-16 19:31:31.000000000 -0700
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     5
+++ Python-3.4.0/Modules/posixmodule.c	2014-03-17 13:31:33.433740698 -0700
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     6
@@ -7789,16 +7789,34 @@
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     7
 "closerange(fd_low, fd_high)\n\n\
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     8
 Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     9
 
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    10
+static int
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    11
+close_func(void *lohi, int fd)
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    12
+{
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    13
+    int lo = ((int *)lohi)[0];
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    14
+    int hi = ((int *)lohi)[1];
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    15
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    16
+    if (fd >= hi)
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    17
+        return (1);
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    18
+    else if (fd >= lo)
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    19
+        close(fd);
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    20
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    21
+    return (0);
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    22
+}
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    23
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    24
 static PyObject *
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    25
 posix_closerange(PyObject *self, PyObject *args)
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    26
 {
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    27
     int fd_from, fd_to, i;
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    28
+    int lohi[2];
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    29
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    30
     if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    31
         return NULL;
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    32
     Py_BEGIN_ALLOW_THREADS
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    33
-    for (i = fd_from; i < fd_to; i++)
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    34
-        if (_PyVerify_fd(i))
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    35
-            close(i);
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    36
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    37
+    lohi[0] = fd_from;
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    38
+    lohi[1] = fd_to;
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    39
+    fdwalk(close_func, lohi);
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    40
+
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    41
     Py_END_ALLOW_THREADS
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    42
     Py_RETURN_NONE;
35735ffdda43 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    43
 }