Issue #22117: Replace usage of _PyTime_ROUND_UP with _PyTime_ROUND_CEILING
All these functions only accept positive timeouts, so this change has no effect in practice.
This commit is contained in:
parent
bcdd777d3c
commit
869e1778c0
|
@ -1637,7 +1637,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
|
||||||
|
|
||||||
/* s->sock_timeout is in seconds, timeout in ms */
|
/* s->sock_timeout is in seconds, timeout in ms */
|
||||||
timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
|
timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
|
||||||
_PyTime_ROUND_UP);
|
_PyTime_ROUND_CEILING);
|
||||||
|
|
||||||
PySSL_BEGIN_ALLOW_THREADS
|
PySSL_BEGIN_ALLOW_THREADS
|
||||||
rc = poll(&pollfd, 1, timeout);
|
rc = poll(&pollfd, 1, timeout);
|
||||||
|
@ -1651,7 +1651,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
|
||||||
if (!_PyIsSelectable_fd(s->sock_fd))
|
if (!_PyIsSelectable_fd(s->sock_fd))
|
||||||
return SOCKET_TOO_LARGE_FOR_SELECT;
|
return SOCKET_TOO_LARGE_FOR_SELECT;
|
||||||
|
|
||||||
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
|
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_CEILING);
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(s->sock_fd, &fds);
|
FD_SET(s->sock_fd, &fds);
|
||||||
|
|
|
@ -59,7 +59,7 @@ acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
|
||||||
endtime = _PyTime_GetMonotonicClock() + timeout;
|
endtime = _PyTime_GetMonotonicClock() + timeout;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_UP);
|
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
|
||||||
|
|
||||||
/* first a simple non-blocking try without releasing the GIL */
|
/* first a simple non-blocking try without releasing the GIL */
|
||||||
r = PyThread_acquire_lock_timed(lock, 0, 0);
|
r = PyThread_acquire_lock_timed(lock, 0, 0);
|
||||||
|
@ -110,7 +110,8 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (timeout_obj
|
if (timeout_obj
|
||||||
&& _PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
|
&& _PyTime_FromSecondsObject(timeout,
|
||||||
|
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!blocking && *timeout != unset_timeout ) {
|
if (!blocking && *timeout != unset_timeout ) {
|
||||||
|
@ -128,7 +129,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
|
||||||
else if (*timeout != unset_timeout) {
|
else if (*timeout != unset_timeout) {
|
||||||
_PyTime_t microseconds;
|
_PyTime_t microseconds;
|
||||||
|
|
||||||
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_UP);
|
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
|
||||||
if (microseconds >= PY_TIMEOUT_MAX) {
|
if (microseconds >= PY_TIMEOUT_MAX) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"timeout value is too large");
|
"timeout value is too large");
|
||||||
|
|
|
@ -209,13 +209,13 @@ select_select(PyObject *self, PyObject *args)
|
||||||
else {
|
else {
|
||||||
_PyTime_t ts;
|
_PyTime_t ts;
|
||||||
|
|
||||||
if (_PyTime_FromSecondsObject(&ts, tout, _PyTime_ROUND_UP) < 0) {
|
if (_PyTime_FromSecondsObject(&ts, tout, _PyTime_ROUND_CEILING) < 0) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"timeout must be a float or None");
|
"timeout must be a float or None");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_UP) == -1)
|
if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_CEILING) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (tv.tv_sec < 0) {
|
if (tv.tv_sec < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
|
PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
|
||||||
|
@ -2014,7 +2014,8 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
|
||||||
else {
|
else {
|
||||||
_PyTime_t ts;
|
_PyTime_t ts;
|
||||||
|
|
||||||
if (_PyTime_FromSecondsObject(&ts, otimeout, _PyTime_ROUND_UP) < 0) {
|
if (_PyTime_FromSecondsObject(&ts,
|
||||||
|
otimeout, _PyTime_ROUND_CEILING) < 0) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"timeout argument must be an number "
|
"timeout argument must be an number "
|
||||||
"or None, got %.200s",
|
"or None, got %.200s",
|
||||||
|
|
|
@ -977,7 +977,8 @@ signal_sigtimedwait(PyObject *self, PyObject *args)
|
||||||
&signals, &timeout_obj))
|
&signals, &timeout_obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
|
if (_PyTime_FromSecondsObject(&timeout,
|
||||||
|
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (timeout < 0) {
|
if (timeout < 0) {
|
||||||
|
|
|
@ -633,7 +633,7 @@ internal_select_ex(PySocketSockObject *s, int writing, _PyTime_t interval)
|
||||||
pollfd.events = writing ? POLLOUT : POLLIN;
|
pollfd.events = writing ? POLLOUT : POLLIN;
|
||||||
|
|
||||||
/* s->sock_timeout is in seconds, timeout in ms */
|
/* s->sock_timeout is in seconds, timeout in ms */
|
||||||
timeout = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_UP);
|
timeout = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_CEILING);
|
||||||
assert(timeout <= INT_MAX);
|
assert(timeout <= INT_MAX);
|
||||||
timeout_int = (int)timeout;
|
timeout_int = (int)timeout;
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ internal_select_ex(PySocketSockObject *s, int writing, _PyTime_t interval)
|
||||||
n = poll(&pollfd, 1, timeout_int);
|
n = poll(&pollfd, 1, timeout_int);
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
#else
|
#else
|
||||||
_PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_UP);
|
_PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_CEILING);
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(s->sock_fd, &fds);
|
FD_SET(s->sock_fd, &fds);
|
||||||
|
@ -2191,7 +2191,8 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
|
if (_PyTime_FromSecondsObject(timeout,
|
||||||
|
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (*timeout < 0) {
|
if (*timeout < 0) {
|
||||||
|
@ -2200,10 +2201,10 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_UP) < 0);
|
overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_CEILING) < 0);
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_POLL
|
#ifndef HAVE_POLL
|
||||||
timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_UP);
|
timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_CEILING);
|
||||||
overflow = (timeout > INT_MAX);
|
overflow = (timeout > INT_MAX);
|
||||||
#endif
|
#endif
|
||||||
if (overflow) {
|
if (overflow) {
|
||||||
|
@ -2452,7 +2453,7 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int conv;
|
int conv;
|
||||||
|
|
||||||
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
|
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_CEILING);
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
|
|
|
@ -221,7 +221,7 @@ static PyObject *
|
||||||
time_sleep(PyObject *self, PyObject *obj)
|
time_sleep(PyObject *self, PyObject *obj)
|
||||||
{
|
{
|
||||||
_PyTime_t secs;
|
_PyTime_t secs;
|
||||||
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_UP))
|
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (secs < 0) {
|
if (secs < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
@ -1405,7 +1405,7 @@ pysleep(_PyTime_t secs)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#ifndef MS_WINDOWS
|
#ifndef MS_WINDOWS
|
||||||
if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_UP) < 0)
|
if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_CEILING) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
@ -1420,7 +1420,7 @@ pysleep(_PyTime_t secs)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_UP);
|
millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_CEILING);
|
||||||
if (millisecs > (double)ULONG_MAX) {
|
if (millisecs > (double)ULONG_MAX) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"sleep length is too large");
|
"sleep length is too large");
|
||||||
|
|
Loading…
Reference in New Issue