Message137927
You don't check that 0 <= fd (e.g. oss.close()).
The select has a specific code for Visual Studio (don't check v < FD_SETSIZE):
#if defined(_MSC_VER)
max = 0; /* not used for Win32 */
#else /* !_MSC_VER */
if (v < 0 || v >= FD_SETSIZE) {
PyErr_SetString(PyExc_ValueError,
"filedescriptor out of range in select()");
goto finally;
}
if (v > max)
max = v;
#endif /* _MSC_VER */
Python has a _PyVerify_fd() function. We might write a similar function/macro to check if a file descriptor can be used in a file descriptor set. FD_SET() is used in the oss, readline, socket and _ssl modules. The socket module has a IS_SELECTABLE() macro:
#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)
/* 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)
#endif
Note: do you really use the OSS module? On which OS? :) |
|
Date |
User |
Action |
Args |
2011-06-08 21:53:07 | vstinner | set | recipients:
+ vstinner, pitrou, neologix |
2011-06-08 21:53:06 | vstinner | set | messageid: <1307569986.96.0.534178412085.issue12287@psf.upfronthosting.co.za> |
2011-06-08 21:53:06 | vstinner | link | issue12287 messages |
2011-06-08 21:53:06 | vstinner | create | |
|