components/python/python34/patches/11-closerange.patch
author John Beck <John.Beck@Oracle.COM>
Mon, 19 May 2014 07:37:20 -0700
changeset 1907 446472de62e9
child 3869 eb4c6284602f
permissions -rw-r--r--
PSARC 2014/151 Python 3.4 15819724 SUNBT7202228 python 3.4 18756157 upgrade setuptools to 0.9.6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1907
446472de62e9 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
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     2
widely implemented, this is unsuitable for upstream.
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     3
446472de62e9 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
446472de62e9 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
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     6
@@ -7789,16 +7789,34 @@
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     7
 "closerange(fd_low, fd_high)\n\n\
446472de62e9 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.");
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     9
 
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    10
+static int
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    11
+close_func(void *lohi, int fd)
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    12
+{
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    13
+    int lo = ((int *)lohi)[0];
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    14
+    int hi = ((int *)lohi)[1];
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    15
+
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    16
+    if (fd >= hi)
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    17
+        return (1);
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    18
+    else if (fd >= lo)
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    19
+        close(fd);
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    20
+
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    21
+    return (0);
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    22
+}
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    23
+
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    24
 static PyObject *
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    25
 posix_closerange(PyObject *self, PyObject *args)
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    26
 {
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    27
     int fd_from, fd_to, i;
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    28
+    int lohi[2];
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    29
+
446472de62e9 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))
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    31
         return NULL;
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    32
     Py_BEGIN_ALLOW_THREADS
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    33
-    for (i = fd_from; i < fd_to; i++)
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    34
-        if (_PyVerify_fd(i))
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    35
-            close(i);
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    36
+
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    37
+    lohi[0] = fd_from;
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    38
+    lohi[1] = fd_to;
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    39
+    fdwalk(close_func, lohi);
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    40
+
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    41
     Py_END_ALLOW_THREADS
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    42
     Py_RETURN_NONE;
446472de62e9 PSARC 2014/151 Python 3.4
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    43
 }