mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
select_select(): Closing bug #448351 the easy way, i.e. by changing
the "#ifdef MS_WINDOWS" to "#ifdef SELECT_USES_HEAP" and by setting SELECT_USES_HEAP when FD_SETSIZE > 1024. The indirection seems useful since this subtly changes the path that "normal" Windows programs take (where Timmie sez FD_SETSIZE = 512). If that's a problem for Windows, he has only one place to change.
This commit is contained in:
parent
c019ecb7fe
commit
b44740f741
1 changed files with 21 additions and 8 deletions
|
@ -181,18 +181,31 @@ set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 3])
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef SELECT_USES_HEAP
|
||||||
|
#if FD_SETSIZE > 1024
|
||||||
|
#define SELECT_USES_HEAP
|
||||||
|
#endif /* FD_SETSIZE > 1024 */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
select_select(PyObject *self, PyObject *args)
|
select_select(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
#ifdef MS_WINDOWS
|
#ifdef SELECT_USES_HEAP
|
||||||
/* This would be an awful lot of stack space on Windows! */
|
/* This would be an awful lot of stack space on Windows! */
|
||||||
pylist *rfd2obj, *wfd2obj, *efd2obj;
|
pylist *rfd2obj, *wfd2obj, *efd2obj;
|
||||||
#else
|
#else /* !SELECT_USES_HEAP */
|
||||||
|
/* XXX: Why, oh why does this add 3?! As far as anyone can tell,
|
||||||
|
* it should only add 1 for the sentinel.
|
||||||
|
*
|
||||||
|
* XXX: All this should probably be implemented as follows:
|
||||||
|
* - find the highest descriptor we're interested in
|
||||||
|
* - add one
|
||||||
|
* - that's the size
|
||||||
|
* See: Stevens, APitUE, $12.5.1
|
||||||
|
*/
|
||||||
pylist rfd2obj[FD_SETSIZE + 3];
|
pylist rfd2obj[FD_SETSIZE + 3];
|
||||||
pylist wfd2obj[FD_SETSIZE + 3];
|
pylist wfd2obj[FD_SETSIZE + 3];
|
||||||
pylist efd2obj[FD_SETSIZE + 3];
|
pylist efd2obj[FD_SETSIZE + 3];
|
||||||
#endif
|
#endif /* SELECT_USES_HEAP */
|
||||||
PyObject *ifdlist, *ofdlist, *efdlist;
|
PyObject *ifdlist, *ofdlist, *efdlist;
|
||||||
PyObject *ret = NULL;
|
PyObject *ret = NULL;
|
||||||
PyObject *tout = Py_None;
|
PyObject *tout = Py_None;
|
||||||
|
@ -237,7 +250,7 @@ select_select(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef SELECT_USES_HEAP
|
||||||
/* Allocate memory for the lists */
|
/* Allocate memory for the lists */
|
||||||
rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
||||||
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
||||||
|
@ -248,7 +261,7 @@ select_select(PyObject *self, PyObject *args)
|
||||||
if (efd2obj) PyMem_DEL(efd2obj);
|
if (efd2obj) PyMem_DEL(efd2obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* SELECT_USES_HEAP */
|
||||||
/* Convert lists to fd_sets, and get maximum fd number
|
/* Convert lists to fd_sets, and get maximum fd number
|
||||||
* propagates the Python exception set in list2set()
|
* propagates the Python exception set in list2set()
|
||||||
*/
|
*/
|
||||||
|
@ -302,11 +315,11 @@ select_select(PyObject *self, PyObject *args)
|
||||||
reap_obj(rfd2obj);
|
reap_obj(rfd2obj);
|
||||||
reap_obj(wfd2obj);
|
reap_obj(wfd2obj);
|
||||||
reap_obj(efd2obj);
|
reap_obj(efd2obj);
|
||||||
#ifdef MS_WINDOWS
|
#ifdef SELECT_USES_HEAP
|
||||||
PyMem_DEL(rfd2obj);
|
PyMem_DEL(rfd2obj);
|
||||||
PyMem_DEL(wfd2obj);
|
PyMem_DEL(wfd2obj);
|
||||||
PyMem_DEL(efd2obj);
|
PyMem_DEL(efd2obj);
|
||||||
#endif
|
#endif /* SELECT_USES_HEAP */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue