Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 869e177

Browse files
committed
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.
1 parent bcdd777 commit 869e177

6 files changed

Lines changed: 22 additions & 18 deletions

File tree

Modules/_ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
16371637

16381638
/* s->sock_timeout is in seconds, timeout in ms */
16391639
timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
1640-
_PyTime_ROUND_UP);
1640+
_PyTime_ROUND_CEILING);
16411641

16421642
PySSL_BEGIN_ALLOW_THREADS
16431643
rc = poll(&pollfd, 1, timeout);
@@ -1651,7 +1651,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
16511651
if (!_PyIsSelectable_fd(s->sock_fd))
16521652
return SOCKET_TOO_LARGE_FOR_SELECT;
16531653

1654-
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
1654+
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_CEILING);
16551655

16561656
FD_ZERO(&fds);
16571657
FD_SET(s->sock_fd, &fds);

Modules/_threadmodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
5959
endtime = _PyTime_GetMonotonicClock() + timeout;
6060

6161
do {
62-
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_UP);
62+
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
6363

6464
/* first a simple non-blocking try without releasing the GIL */
6565
r = PyThread_acquire_lock_timed(lock, 0, 0);
@@ -110,7 +110,8 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
110110
return -1;
111111

112112
if (timeout_obj
113-
&& _PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
113+
&& _PyTime_FromSecondsObject(timeout,
114+
timeout_obj, _PyTime_ROUND_CEILING) < 0)
114115
return -1;
115116

116117
if (!blocking && *timeout != unset_timeout ) {
@@ -128,7 +129,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
128129
else if (*timeout != unset_timeout) {
129130
_PyTime_t microseconds;
130131

131-
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_UP);
132+
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
132133
if (microseconds >= PY_TIMEOUT_MAX) {
133134
PyErr_SetString(PyExc_OverflowError,
134135
"timeout value is too large");

Modules/selectmodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ select_select(PyObject *self, PyObject *args)
209209
else {
210210
_PyTime_t ts;
211211

212-
if (_PyTime_FromSecondsObject(&ts, tout, _PyTime_ROUND_UP) < 0) {
212+
if (_PyTime_FromSecondsObject(&ts, tout, _PyTime_ROUND_CEILING) < 0) {
213213
PyErr_SetString(PyExc_TypeError,
214214
"timeout must be a float or None");
215215
return NULL;
216216
}
217217

218-
if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_UP) == -1)
218+
if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_CEILING) == -1)
219219
return NULL;
220220
if (tv.tv_sec < 0) {
221221
PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
@@ -2014,7 +2014,8 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
20142014
else {
20152015
_PyTime_t ts;
20162016

2017-
if (_PyTime_FromSecondsObject(&ts, otimeout, _PyTime_ROUND_UP) < 0) {
2017+
if (_PyTime_FromSecondsObject(&ts,
2018+
otimeout, _PyTime_ROUND_CEILING) < 0) {
20182019
PyErr_Format(PyExc_TypeError,
20192020
"timeout argument must be an number "
20202021
"or None, got %.200s",

Modules/signalmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ signal_sigtimedwait(PyObject *self, PyObject *args)
977977
&signals, &timeout_obj))
978978
return NULL;
979979

980-
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
980+
if (_PyTime_FromSecondsObject(&timeout,
981+
timeout_obj, _PyTime_ROUND_CEILING) < 0)
981982
return NULL;
982983

983984
if (timeout < 0) {

Modules/socketmodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,15 @@ internal_select_ex(PySocketSockObject *s, int writing, _PyTime_t interval)
633633
pollfd.events = writing ? POLLOUT : POLLIN;
634634

635635
/* s->sock_timeout is in seconds, timeout in ms */
636-
timeout = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_UP);
636+
timeout = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_CEILING);
637637
assert(timeout <= INT_MAX);
638638
timeout_int = (int)timeout;
639639

640640
Py_BEGIN_ALLOW_THREADS;
641641
n = poll(&pollfd, 1, timeout_int);
642642
Py_END_ALLOW_THREADS;
643643
#else
644-
_PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_UP);
644+
_PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_CEILING);
645645

646646
FD_ZERO(&fds);
647647
FD_SET(s->sock_fd, &fds);
@@ -2191,7 +2191,8 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
21912191
return 0;
21922192
}
21932193

2194-
if (_PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
2194+
if (_PyTime_FromSecondsObject(timeout,
2195+
timeout_obj, _PyTime_ROUND_CEILING) < 0)
21952196
return -1;
21962197

21972198
if (*timeout < 0) {
@@ -2200,10 +2201,10 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
22002201
}
22012202

22022203
#ifdef MS_WINDOWS
2203-
overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_UP) < 0);
2204+
overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_CEILING) < 0);
22042205
#endif
22052206
#ifndef HAVE_POLL
2206-
timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_UP);
2207+
timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_CEILING);
22072208
overflow = (timeout > INT_MAX);
22082209
#endif
22092210
if (overflow) {
@@ -2452,7 +2453,7 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
24522453
struct timeval tv;
24532454
int conv;
24542455

2455-
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
2456+
_PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_CEILING);
24562457

24572458
Py_BEGIN_ALLOW_THREADS
24582459
FD_ZERO(&fds);

Modules/timemodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static PyObject *
221221
time_sleep(PyObject *self, PyObject *obj)
222222
{
223223
_PyTime_t secs;
224-
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_UP))
224+
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
225225
return NULL;
226226
if (secs < 0) {
227227
PyErr_SetString(PyExc_ValueError,
@@ -1405,7 +1405,7 @@ pysleep(_PyTime_t secs)
14051405

14061406
do {
14071407
#ifndef MS_WINDOWS
1408-
if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_UP) < 0)
1408+
if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_CEILING) < 0)
14091409
return -1;
14101410

14111411
Py_BEGIN_ALLOW_THREADS
@@ -1420,7 +1420,7 @@ pysleep(_PyTime_t secs)
14201420
return -1;
14211421
}
14221422
#else
1423-
millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_UP);
1423+
millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_CEILING);
14241424
if (millisecs > (double)ULONG_MAX) {
14251425
PyErr_SetString(PyExc_OverflowError,
14261426
"sleep length is too large");

0 commit comments

Comments
 (0)