diff -r e572a97a1bd1 Include/fileobject.h --- a/Include/fileobject.h Fri Jun 10 19:05:16 2011 +0100 +++ b/Include/fileobject.h Sat Jun 11 00:11:52 2011 +0200 @@ -44,6 +44,15 @@ #endif #endif /* Py_LIMITED_API */ +#ifdef HAVE_SELECT +/* A routine to check if a file descriptor can be select()-ed. */ +#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE + #define _PyIsSelectable_fd(FD) (1) +#else + #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE)) +#endif +#endif /* HAVE_SELECT */ + #ifdef __cplusplus } #endif diff -r e572a97a1bd1 Modules/_ssl.c --- a/Modules/_ssl.c Fri Jun 10 19:05:16 2011 +0100 +++ b/Modules/_ssl.c Sat Jun 11 00:11:52 2011 +0200 @@ -1022,10 +1022,8 @@ #endif /* Guard against socket too large for select*/ -#ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE - if (s->sock_fd >= FD_SETSIZE) + if (!_PyIsSelectable_fd(s->sock_fd)) return SOCKET_TOO_LARGE_FOR_SELECT; -#endif /* Construct the arguments to select */ tv.tv_sec = (int)s->sock_timeout; diff -r e572a97a1bd1 Modules/ossaudiodev.c --- a/Modules/ossaudiodev.c Fri Jun 10 19:05:16 2011 +0100 +++ b/Modules/ossaudiodev.c Sat Jun 11 00:11:52 2011 +0200 @@ -425,6 +425,11 @@ if (!PyArg_ParseTuple(args, "y#:write", &cp, &size)) return NULL; + if (!_PyIsSelectable_fd(self->fd)) { + PyErr_SetString(PyExc_ValueError, + "file descriptor out of range for select"); + return NULL; + } /* use select to wait for audio device to be available */ FD_ZERO(&write_set_fds); FD_SET(self->fd, &write_set_fds); diff -r e572a97a1bd1 Modules/selectmodule.c --- a/Modules/selectmodule.c Fri Jun 10 19:05:16 2011 +0100 +++ b/Modules/selectmodule.c Sat Jun 11 00:11:52 2011 +0200 @@ -110,7 +110,7 @@ #if defined(_MSC_VER) max = 0; /* not used for Win32 */ #else /* !_MSC_VER */ - if (v < 0 || v >= FD_SETSIZE) { + if (!_PyIsSelectable_fd(v)) { PyErr_SetString(PyExc_ValueError, "filedescriptor out of range in select()"); goto finally; @@ -160,13 +160,6 @@ for (j = 0; fd2obj[j].sentinel >= 0; j++) { fd = fd2obj[j].fd; if (FD_ISSET(fd, set)) { -#ifndef _MSC_VER - if (fd > FD_SETSIZE) { - PyErr_SetString(PyExc_SystemError, - "filedescriptor out of range returned in select()"); - goto finally; - } -#endif o = fd2obj[j].obj; fd2obj[j].obj = NULL; /* transfer ownership */ diff -r e572a97a1bd1 Modules/socketmodule.c --- a/Modules/socketmodule.c Fri Jun 10 19:05:16 2011 +0100 +++ b/Modules/socketmodule.c Sat Jun 11 00:11:52 2011 +0200 @@ -469,18 +469,14 @@ #include #endif -#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE -/* Platform can select file descriptors beyond FD_SETSIZE */ -#define IS_SELECTABLE(s) 1 -#elif defined(HAVE_POLL) +#ifdef HAVE_POLL /* Instead of select(), we'll use poll() since poll() works on any fd. */ #define IS_SELECTABLE(s) 1 /* Can we call select() with this socket without a buffer overrun? */ #else -/* POSIX says selecting file descriptors beyond FD_SETSIZE - has undefined behaviour. If there's no timeout left, we don't have to - call select, so it's a safe, little white lie. */ -#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0) +/* If there's no timeout left, we don't have to call select, so it's a safe, + * little white lie. */ +#define IS_SELECTABLE(s) (_PyIsSelectable_fd((s)->sock_fd) || (s)->sock_timeout <= 0.0) #endif static PyObject*