Check Python version to determine proper timeout rounding mode
This commit is contained in:
@@ -327,13 +327,18 @@ PyObject* zts_py_select(PyObject* module, PyObject* rlist, PyObject* wlist, PyOb
|
|||||||
tvp = (struct timeval*)NULL;
|
tvp = (struct timeval*)NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0) {
|
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 5
|
||||||
|
_PyTime_round_t roundingMode = _PyTime_ROUND_CEILING;
|
||||||
|
#else
|
||||||
|
_PyTime_round_t roundingMode = _PyTime_ROUND_UP;
|
||||||
|
#endif
|
||||||
|
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, roundingMode) < 0) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "timeout must be a float or None");
|
PyErr_SetString(PyExc_TypeError, "timeout must be a float or None");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_UP) == -1) {
|
if (_PyTime_AsTimeval(timeout, &tv, roundingMode) == -1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tv.tv_sec < 0) {
|
if (tv.tv_sec < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user