summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-30 00:51:13 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-30 00:51:13 (GMT)
commitea9c0dd2c27884691f0a0af983fd41d4d818e93f (patch)
treea8da8821f8fa7c484073538e41b8eb72de384b81 /Modules
parent160e819a1d0a01fe79b66bf398c925c0dac0ded1 (diff)
downloadcpython-ea9c0dd2c27884691f0a0af983fd41d4d818e93f.zip
cpython-ea9c0dd2c27884691f0a0af983fd41d4d818e93f.tar.gz
cpython-ea9c0dd2c27884691f0a0af983fd41d4d818e93f.tar.bz2
Issue #22117: Fix usage of _PyTime_AsTimeval()
Add _PyTime_AsTimeval_noraise() function. Call it when it's not possible (or not useful) to raise a Python exception on overflow.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ssl.c4
-rw-r--r--Modules/_testcapimodule.c5
-rw-r--r--Modules/socketmodule.c8
-rw-r--r--Modules/timemodule.c5
4 files changed, 5 insertions, 17 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 54f5d14..217c77c 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1651,9 +1651,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
if (!_PyIsSelectable_fd(s->sock_fd))
return SOCKET_TOO_LARGE_FOR_SELECT;
- /* conversion was already checked for overflow when
- the timeout was set */
- (void)_PyTime_AsTimeval(s->sock_timeout, &tv, _PyTime_ROUND_UP);
+ _PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
FD_ZERO(&fds);
FD_SET(s->sock_fd, &fds);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 9abb7cc..128ba09 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3427,11 +3427,8 @@ test_PyTime_AsTimeval(PyObject *self, PyObject *args)
if (check_time_rounding(round) < 0)
return NULL;
t = _PyTime_FromNanoseconds(ns);
- if (_PyTime_AsTimeval(t, &tv, round) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "timeout doesn't fit into C timeval");
+ if (_PyTime_AsTimeval(t, &tv, round) < 0)
return NULL;
- }
seconds = PyLong_FromLong((PY_LONG_LONG)tv.tv_sec);
if (seconds == NULL)
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 93dcd41..513405e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -641,9 +641,7 @@ internal_select_ex(PySocketSockObject *s, int writing, _PyTime_t interval)
n = poll(&pollfd, 1, timeout_int);
Py_END_ALLOW_THREADS;
#else
- /* conversion was already checked for overflow when
- the timeout was set */
- (void)_PyTime_AsTimeval(interval, &tv, _PyTime_ROUND_UP);
+ _PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_UP);
FD_ZERO(&fds);
FD_SET(s->sock_fd, &fds);
@@ -2454,9 +2452,7 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
struct timeval tv;
int conv;
- /* conversion was already checked for overflow when
- the timeout was set */
- (void)_PyTime_AsTimeval(s->sock_timeout, &tv, _PyTime_ROUND_UP);
+ _PyTime_AsTimeval_noraise(s->sock_timeout, &tv, _PyTime_ROUND_UP);
Py_BEGIN_ALLOW_THREADS
FD_ZERO(&fds);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 99e83cc..3ed3fb3 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -1405,11 +1405,8 @@ pysleep(_PyTime_t secs)
do {
#ifndef MS_WINDOWS
- if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_UP) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "delay doesn't fit into C timeval");
+ if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_UP) < 0)
return -1;
- }
Py_BEGIN_ALLOW_THREADS
err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout);