@@ -206,38 +206,17 @@ select_select(PyObject *self, PyObject *args)
206206
207207 if (tout == Py_None )
208208 tvp = (struct timeval * )0 ;
209- else if (!PyNumber_Check (tout )) {
210- PyErr_SetString (PyExc_TypeError ,
211- "timeout must be a float or None" );
212- return NULL ;
213- }
214209 else {
215- /* On OpenBSD 5.4, timeval.tv_sec is a long.
216- * Example: long is 64-bit, whereas time_t is 32-bit. */
217- time_t sec ;
218- /* On OS X 64-bit, timeval.tv_usec is an int (and thus still 4
219- bytes as required), but no longer defined by a long. */
220- long usec ;
221- if (_PyTime_ObjectToTimeval (tout , & sec , & usec ,
222- _PyTime_ROUND_UP ) == -1 )
223- return NULL ;
224- #ifdef MS_WINDOWS
225- /* On Windows, timeval.tv_sec is a long (32 bit),
226- * whereas time_t can be 64-bit. */
227- assert (sizeof (tv .tv_sec ) == sizeof (long ));
228- #if SIZEOF_TIME_T > SIZEOF_LONG
229- if (sec > LONG_MAX ) {
230- PyErr_SetString (PyExc_OverflowError ,
231- "timeout is too large" );
210+ _PyTime_t ts ;
211+
212+ if (_PyTime_FromSecondsObject (& ts , tout , _PyTime_ROUND_UP ) < 0 ) {
213+ PyErr_SetString (PyExc_TypeError ,
214+ "timeout must be a float or None" );
232215 return NULL ;
233216 }
234- #endif
235- tv .tv_sec = (long )sec ;
236- #else
237- assert (sizeof (tv .tv_sec ) >= sizeof (sec ));
238- tv .tv_sec = sec ;
239- #endif
240- tv .tv_usec = usec ;
217+
218+ if (_PyTime_AsTimeval (ts , & tv , _PyTime_ROUND_UP ) == -1 )
219+ return NULL ;
241220 if (tv .tv_sec < 0 ) {
242221 PyErr_SetString (PyExc_ValueError , "timeout must be non-negative" );
243222 return NULL ;
@@ -2032,9 +2011,18 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
20322011 if (otimeout == Py_None || otimeout == NULL ) {
20332012 ptimeoutspec = NULL ;
20342013 }
2035- else if (PyNumber_Check (otimeout )) {
2036- if (_PyTime_ObjectToTimespec (otimeout , & timeout .tv_sec ,
2037- & timeout .tv_nsec , _PyTime_ROUND_UP ) == -1 )
2014+ else {
2015+ _PyTime_t ts ;
2016+
2017+ if (_PyTime_FromSecondsObject (& ts , otimeout , _PyTime_ROUND_UP ) < 0 ) {
2018+ PyErr_Format (PyExc_TypeError ,
2019+ "timeout argument must be an number "
2020+ "or None, got %.200s" ,
2021+ Py_TYPE (otimeout )-> tp_name );
2022+ return NULL ;
2023+ }
2024+
2025+ if (_PyTime_AsTimespec (ts , & timeout ) == -1 )
20382026 return NULL ;
20392027
20402028 if (timeout .tv_sec < 0 ) {
@@ -2044,13 +2032,6 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
20442032 }
20452033 ptimeoutspec = & timeout ;
20462034 }
2047- else {
2048- PyErr_Format (PyExc_TypeError ,
2049- "timeout argument must be an number "
2050- "or None, got %.200s" ,
2051- Py_TYPE (otimeout )-> tp_name );
2052- return NULL ;
2053- }
20542035
20552036 if (ch != NULL && ch != Py_None ) {
20562037 it = PyObject_GetIter (ch );
0 commit comments