components/python/python27/patches/10-closerange.patch
branchs11-update
changeset 3367 ed5024e47b53
parent 3366 dba288608e69
child 3368 006337635e91
equal deleted inserted replaced
3366:dba288608e69 3367:ed5024e47b53
     1 --- Python-2.7.1/Modules/posixmodule.c	Fri Nov 26 09:35:50 2010
       
     2 +++ Python-2.7.1/Modules/posixmodule.c	Fri Nov  4 09:41:24 2011
       
     3 @@ -6442,16 +6442,34 @@
       
     4  "closerange(fd_low, fd_high)\n\n\
       
     5  Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
       
     6  
       
     7 +static int
       
     8 +close_func(void *lohi, int fd)
       
     9 +{
       
    10 +    int lo = ((int *)lohi)[0];
       
    11 +    int hi = ((int *)lohi)[1];
       
    12 +
       
    13 +    if (fd >= hi)
       
    14 +        return (1);
       
    15 +    else if (fd >= lo)
       
    16 +        close(fd);
       
    17 +
       
    18 +    return (0);
       
    19 +}
       
    20 +
       
    21  static PyObject *
       
    22  posix_closerange(PyObject *self, PyObject *args)
       
    23  {
       
    24      int fd_from, fd_to, i;
       
    25 +    int lohi[2];
       
    26 +
       
    27      if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
       
    28          return NULL;
       
    29      Py_BEGIN_ALLOW_THREADS
       
    30 -    for (i = fd_from; i < fd_to; i++)
       
    31 -        if (_PyVerify_fd(i))
       
    32 -            close(i);
       
    33 +
       
    34 +    lohi[0] = fd_from;
       
    35 +    lohi[1] = fd_to;
       
    36 +    fdwalk(close_func, lohi);
       
    37 +
       
    38      Py_END_ALLOW_THREADS
       
    39      Py_RETURN_NONE;
       
    40  }