components/python/python27/patches/11-closerange.patch
author John Beck <John.Beck@Oracle.COM>
Mon, 06 Oct 2014 13:15:36 -0700
branchs11u2-sru
changeset 3379 e99da14b537a
permissions -rw-r--r--
PSARC 2014/183 Python 2.7.6 18251953 update Python 2.7 line to version 2.7.6 19004605 update Python 2.7 line to version 2.7.7 19308541 update Python 2.7 line to version 2.7.8 19284990 python 2.7.7 segfaults while under memory stress 17431625 64-bit python should use long rather than int for os.sysconf() return value 19164544 Python 2.7 test_tcl fails 19030238 Python 2.7 test_sysconfig fails - no module named _osx_support 19030198 Python 2.7 tests fail - import name error 19032456 more Python 2.7 tests failing with import errors 19022543 Python 2.7 test_lib2to3 fails
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3379
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     1
This patch uses fdwalk(3c) to close file descriptors; as that function is not
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     2
widely implemented, this is unsuitable for upstream.
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     3
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     4
--- Python-2.7.7/Modules/posixmodule.c.~1~	2014-05-31 11:58:40.000000000 -0700
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     5
+++ Python-2.7.7/Modules/posixmodule.c	2014-06-02 10:49:30.052826955 -0700
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     6
@@ -6607,16 +6607,34 @@
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     7
 "closerange(fd_low, fd_high)\n\n\
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     8
 Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     9
 
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    10
+static int
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    11
+close_func(void *lohi, int fd)
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    12
+{
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    13
+    int lo = ((int *)lohi)[0];
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    14
+    int hi = ((int *)lohi)[1];
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    15
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    16
+    if (fd >= hi)
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    17
+        return (1);
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    18
+    else if (fd >= lo)
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    19
+        close(fd);
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    20
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    21
+    return (0);
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    22
+}
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    23
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    24
 static PyObject *
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    25
 posix_closerange(PyObject *self, PyObject *args)
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    26
 {
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    27
     int fd_from, fd_to, i;
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    28
+    int lohi[2];
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    29
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    30
     if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    31
         return NULL;
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    32
     Py_BEGIN_ALLOW_THREADS
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    33
-    for (i = fd_from; i < fd_to; i++)
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    34
-        if (_PyVerify_fd(i))
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    35
-            close(i);
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    36
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    37
+    lohi[0] = fd_from;
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    38
+    lohi[1] = fd_to;
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    39
+    fdwalk(close_func, lohi);
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    40
+
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    41
     Py_END_ALLOW_THREADS
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    42
     Py_RETURN_NONE;
e99da14b537a PSARC 2014/183 Python 2.7.6
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    43
 }