]> granicus.if.org Git - python/commitdiff
Issue #14180: Fix the select module to handle correctly the Windows timeval
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Mar 2012 23:20:51 +0000 (00:20 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Mar 2012 23:20:51 +0000 (00:20 +0100)
structure. timeval.tv_sec is a long on Windows, not time_t.

Modules/selectmodule.c

index 19d9d3b9f64b3121336eed316ba4640a8302c8f0..9cb7481f24ef7bac8087a1d772e2d27c5ebfc700 100644 (file)
@@ -223,10 +223,23 @@ select_select(PyObject *self, PyObject *args)
         return NULL;
     }
     else {
-        long usec;
-        if (_PyTime_ObjectToTimeval(tout, &tv.tv_sec, &usec) == -1)
+#ifdef MS_WINDOWS
+        time_t sec;
+        if (_PyTime_ObjectToTimeval(tout, &sec, &tv.tv_usec) == -1)
+            return NULL;
+        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");
             return NULL;
-        tv.tv_usec = usec;
+        }
+#endif
+        tv.tv_sec = (long)sec;
+#else
+        if (_PyTime_ObjectToTimeval(tout, &tv.tv_sec, &tv.tv_usec) == -1)
+            return NULL;
+#endif
         if (tv.tv_sec < 0) {
             PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
             return NULL;