diff options
Diffstat (limited to 'Modules/selectmodule.c')
| -rw-r--r-- | Modules/selectmodule.c | 80 |
1 files changed, 26 insertions, 54 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index ffaf865df2..2c82ce7549 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -206,38 +206,17 @@ select_select(PyObject *self, PyObject *args) if (tout == Py_None) tvp = (struct timeval *)0; - else if (!PyNumber_Check(tout)) { - PyErr_SetString(PyExc_TypeError, - "timeout must be a float or None"); - return NULL; - } else { - /* On OpenBSD 5.4, timeval.tv_sec is a long. - * Example: long is 64-bit, whereas time_t is 32-bit. */ - time_t sec; - /* On OS X 64-bit, timeval.tv_usec is an int (and thus still 4 - bytes as required), but no longer defined by a long. */ - long usec; - if (_PyTime_ObjectToTimeval(tout, &sec, &usec, - _PyTime_ROUND_UP) == -1) - return NULL; -#ifdef MS_WINDOWS - /* On Windows, timeval.tv_sec is a long (32 bit), - * whereas time_t can be 64-bit. */ - assert(sizeof(tv.tv_sec) == sizeof(long)); -#if SIZEOF_TIME_T > SIZEOF_LONG - if (sec > LONG_MAX) { - PyErr_SetString(PyExc_OverflowError, - "timeout is too large"); + _PyTime_t ts; + + if (_PyTime_FromSecondsObject(&ts, tout, _PyTime_ROUND_UP) < 0) { + PyErr_SetString(PyExc_TypeError, + "timeout must be a float or None"); return NULL; } -#endif - tv.tv_sec = (long)sec; -#else - assert(sizeof(tv.tv_sec) >= sizeof(sec)); - tv.tv_sec = sec; -#endif - tv.tv_usec = usec; + + if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_UP) == -1) + return NULL; if (tv.tv_sec < 0) { PyErr_SetString(PyExc_ValueError, "timeout must be non-negative"); return NULL; @@ -718,14 +697,10 @@ static int devpoll_flush(devpollObject *self) size = sizeof(struct pollfd)*self->n_fds; self->n_fds = 0; - Py_BEGIN_ALLOW_THREADS - n = write(self->fd_devpoll, self->fds, size); - Py_END_ALLOW_THREADS - - if (n == -1 ) { - PyErr_SetFromErrno(PyExc_IOError); + n = _Py_write(self->fd_devpoll, self->fds, size); + if (n == -1) return -1; - } + if (n < size) { /* ** Data writed to /dev/poll is a binary data structure. It is not @@ -1013,7 +988,6 @@ newDevPollObject(void) struct pollfd *fds; struct rlimit limit; - Py_BEGIN_ALLOW_THREADS /* ** If we try to process more that getrlimit() ** fds, the kernel will give an error, so @@ -1021,18 +995,14 @@ newDevPollObject(void) ** value, because we can change rlimit() anytime. */ limit_result = getrlimit(RLIMIT_NOFILE, &limit); - if (limit_result != -1) - fd_devpoll = _Py_open("/dev/poll", O_RDWR); - Py_END_ALLOW_THREADS - if (limit_result == -1) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } - if (fd_devpoll == -1) { - PyErr_SetFromErrnoWithFilename(PyExc_IOError, "/dev/poll"); + + fd_devpoll = _Py_open("/dev/poll", O_RDWR); + if (fd_devpoll == -1) return NULL; - } fds = PyMem_NEW(struct pollfd, limit.rlim_cur); if (fds == NULL) { @@ -2041,9 +2011,18 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args) if (otimeout == Py_None || otimeout == NULL) { ptimeoutspec = NULL; } - else if (PyNumber_Check(otimeout)) { - if (_PyTime_ObjectToTimespec(otimeout, &timeout.tv_sec, - &timeout.tv_nsec, _PyTime_ROUND_UP) == -1) + else { + _PyTime_t ts; + + if (_PyTime_FromSecondsObject(&ts, otimeout, _PyTime_ROUND_UP) < 0) { + PyErr_Format(PyExc_TypeError, + "timeout argument must be an number " + "or None, got %.200s", + Py_TYPE(otimeout)->tp_name); + return NULL; + } + + if (_PyTime_AsTimespec(ts, &timeout) == -1) return NULL; if (timeout.tv_sec < 0) { @@ -2053,13 +2032,6 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args) } ptimeoutspec = &timeout; } - else { - PyErr_Format(PyExc_TypeError, - "timeout argument must be an number " - "or None, got %.200s", - Py_TYPE(otimeout)->tp_name); - return NULL; - } if (ch != NULL && ch != Py_None) { it = PyObject_GetIter(ch); |
