[Python-checkins] cpython: Issue #22117: Replace usage of _PyTime_ROUND_UP with _PyTime_ROUND_CEILING

victor.stinner python-checkins at python.org
Mon Mar 30 03:59:21 CEST 2015


https://hg.python.org/cpython/rev/0a8015a4ff97
changeset: 95273:0a8015a4ff97
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Mar 30 03:49:14 2015 +0200
summary:
 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.
files:
 Modules/_ssl.c | 4 ++--
 Modules/_threadmodule.c | 7 ++++---
 Modules/selectmodule.c | 7 ++++---
 Modules/signalmodule.c | 3 ++-
 Modules/socketmodule.c | 13 +++++++------
 Modules/timemodule.c | 6 +++---
 6 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1637,7 +1637,7 @@
 
 /* s->sock_timeout is in seconds, timeout in ms */
 timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
- _PyTime_ROUND_UP);
+ _PyTime_ROUND_CEILING);
 
 PySSL_BEGIN_ALLOW_THREADS
 rc = poll(&pollfd, 1, timeout);
@@ -1651,7 +1651,7 @@
 if (!_PyIsSelectable_fd(s->sock_fd))
 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_SET(s->sock_fd, &fds);
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -59,7 +59,7 @@
 endtime = _PyTime_GetMonotonicClock() + timeout;
 
 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 */
 r = PyThread_acquire_lock_timed(lock, 0, 0);
@@ -110,7 +110,8 @@
 return -1;
 
 if (timeout_obj
- && _PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
+ && _PyTime_FromSecondsObject(timeout,
+ timeout_obj, _PyTime_ROUND_CEILING) < 0)
 return -1;
 
 if (!blocking && *timeout != unset_timeout ) {
@@ -128,7 +129,7 @@
 else if (*timeout != unset_timeout) {
 _PyTime_t microseconds;
 
- microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_UP);
+ microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
 if (microseconds >= PY_TIMEOUT_MAX) {
 PyErr_SetString(PyExc_OverflowError,
 "timeout value is too large");
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -209,13 +209,13 @@
 else {
 _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,
 "timeout must be a float or None");
 return NULL;
 }
 
- if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_UP) == -1)
+ if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_CEILING) == -1)
 return NULL;
 if (tv.tv_sec < 0) {
 PyErr_SetString(PyExc_ValueError, "timeout must be non-negative");
@@ -2014,7 +2014,8 @@
 else {
 _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,
 "timeout argument must be an number "
 "or None, got %.200s",
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -977,7 +977,8 @@
 &signals, &timeout_obj))
 return NULL;
 
- if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
+ if (_PyTime_FromSecondsObject(&timeout,
+ timeout_obj, _PyTime_ROUND_CEILING) < 0)
 return NULL;
 
 if (timeout < 0) {
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -633,7 +633,7 @@
 pollfd.events = writing ? POLLOUT : POLLIN;
 
 /* 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);
 timeout_int = (int)timeout;
 
@@ -641,7 +641,7 @@
 n = poll(&pollfd, 1, timeout_int);
 Py_END_ALLOW_THREADS;
 #else
- _PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_UP);
+ _PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_CEILING);
 
 FD_ZERO(&fds);
 FD_SET(s->sock_fd, &fds);
@@ -2191,7 +2191,8 @@
 return 0;
 }
 
- if (_PyTime_FromSecondsObject(timeout, timeout_obj, _PyTime_ROUND_UP) < 0)
+ if (_PyTime_FromSecondsObject(timeout,
+ timeout_obj, _PyTime_ROUND_CEILING) < 0)
 return -1;
 
 if (*timeout < 0) {
@@ -2200,10 +2201,10 @@
 }
 
 #ifdef MS_WINDOWS
- overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_UP) < 0);
+ overflow = (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_CEILING) < 0);
 #endif
 #ifndef HAVE_POLL
- timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_UP);
+ timeout = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_CEILING);
 overflow = (timeout > INT_MAX);
 #endif
 if (overflow) {
@@ -2452,7 +2453,7 @@
 struct timeval tv;
 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
 FD_ZERO(&fds);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -221,7 +221,7 @@
 time_sleep(PyObject *self, PyObject *obj)
 {
 _PyTime_t secs;
- if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_UP))
+ if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
 return NULL;
 if (secs < 0) {
 PyErr_SetString(PyExc_ValueError,
@@ -1405,7 +1405,7 @@
 
 do {
 #ifndef MS_WINDOWS
- if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_UP) < 0)
+ if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_CEILING) < 0)
 return -1;
 
 Py_BEGIN_ALLOW_THREADS
@@ -1420,7 +1420,7 @@
 return -1;
 }
 #else
- millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_UP);
+ millisecs = _PyTime_AsMilliseconds(secs, _PyTime_ROUND_CEILING);
 if (millisecs > (double)ULONG_MAX) {
 PyErr_SetString(PyExc_OverflowError,
 "sleep length is too large");
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /