components/python/python26/patches/Python26-25-closerange.patch
changeset 578 4f51372decaf
child 841 1a62cefa636d
equal deleted inserted replaced
577:c13e8d244261 578:4f51372decaf
       
     1 --- Python-2.6.4/Modules/posixmodule.c	Wed Sep 16 13:06:36 2009
       
     2 +++ Python-2.6.4/Modules/posixmodule.c	Thu Nov  3 17:39:15 2011
       
     3 @@ -6295,15 +6297,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 -		close(i);
       
    32 +
       
    33 +	lohi[0] = fd_from;
       
    34 +	lohi[1] = fd_to;
       
    35 +	fdwalk(close_func, lohi);
       
    36 +
       
    37  	Py_END_ALLOW_THREADS
       
    38  	Py_RETURN_NONE;
       
    39  }