summaryrefslogtreecommitdiffstats
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-02-18 00:35:40 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-02-18 00:35:40 (GMT)
commit5a8e5796f17715ff6214cec13845006bc1a8bc9f (patch)
tree4ec9ea0346ee383ae8ebffa8f7b9d54b82455182 /Modules/selectmodule.c
parent5afffeab73948617b6e0c0bd20c8ff5119a52e6d (diff)
downloadcpython-5a8e5796f17715ff6214cec13845006bc1a8bc9f.zip
cpython-5a8e5796f17715ff6214cec13845006bc1a8bc9f.tar.gz
cpython-5a8e5796f17715ff6214cec13845006bc1a8bc9f.tar.bz2
Close #20656: Fix select.select() on OpenBSD 64-bit
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 8f8f606..c92bd0f 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -212,11 +212,18 @@ select_select(PyObject *self, PyObject *args)
return NULL;
}
else {
-#ifdef MS_WINDOWS
+ /* On OpenBSD 5.4, timeval.tv_sec is a long.
+ * Example: long is 64-bit, whereas time_t is 32-bit. */
time_t sec;
- if (_PyTime_ObjectToTimeval(tout, &sec, &tv.tv_usec,
+ /* 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) {
@@ -225,16 +232,11 @@ select_select(PyObject *self, PyObject *args)
return NULL;
}
#endif
- tv.tv_sec = (long)sec;
#else
- /* 64-bit OS X has struct timeval.tv_usec as an int (and thus still 4
- bytes as required), but no longer defined by a long. */
- long tv_usec;
- if (_PyTime_ObjectToTimeval(tout, &tv.tv_sec, &tv_usec,
- _PyTime_ROUND_UP) == -1)
- return NULL;
- tv.tv_usec = tv_usec;
+ assert(sizeof(tv.tv_sec) >= sizeof(sec));
#endif
+ tv.tv_sec = sec;
+ tv.tv_usec = usec;
if (tv.tv_sec < 0) {
PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
return NULL;