[Python-checkins] cpython: Issue #22117: Fix _PyTime_GetMonotonicClock() and
victor.stinner
python-checkins at python.org
Sat Mar 28 05:27:06 CET 2015
https://hg.python.org/cpython/rev/0850452048ec
changeset: 95240:0850452048ec
user: Victor Stinner <victor.stinner at gmail.com>
date: Sat Mar 28 05:24:19 2015 +0100
summary:
Issue #22117: Fix _PyTime_GetMonotonicClock() and
_PyTime_GetSystemClockWithInfo() to not raise an exception and return 0 on
error (it should never occur)
files:
Python/pytime.c | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/Python/pytime.c b/Python/pytime.c
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -279,36 +279,41 @@
#ifdef HAVE_CLOCK_GETTIME
static int
-_PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts)
+_PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts, int raise)
{
_PyTime_t t;
+ int res = 0;
+
t = (_PyTime_t)ts->tv_sec * SEC_TO_NS;
if (t / SEC_TO_NS != ts->tv_sec) {
- _PyTime_overflow();
- return -1;
+ if (raise)
+ _PyTime_overflow();
+ res = -1;
}
t += ts->tv_nsec;
*tp = t;
- return 0;
+ return res;
}
#else
static int
-_PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv)
+_PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv, int raise)
{
_PyTime_t t;
+ int res = 0;
t = (_PyTime_t)tv->tv_sec * SEC_TO_NS;
if (t / SEC_TO_NS != tv->tv_sec) {
- _PyTime_overflow();
- return -1;
+ if (raise)
+ _PyTime_overflow();
+ res = -1;
}
t += (_PyTime_t)tv->tv_usec * US_TO_NS;
*tp = t;
- return 0;
+ return res;
}
#endif
@@ -532,7 +537,7 @@
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
- if (_PyTime_FromTimespec(tp, &ts) < 0)
+ if (_PyTime_FromTimespec(tp, &ts, raise) < 0)
return -1;
if (info) {
@@ -558,7 +563,7 @@
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
- if (_PyTime_FromTimeval(tp, &tv) < 0)
+ if (_PyTime_FromTimeval(tp, &tv, raise) < 0)
return -1;
if (info) {
@@ -674,7 +679,7 @@
}
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
}
- if (_PyTime_FromTimespec(tp, &ts) < 0)
+ if (_PyTime_FromTimespec(tp, &ts, raise) < 0)
return -1;
#endif
#ifdef Py_DEBUG
@@ -691,8 +696,11 @@
{
_PyTime_t t;
if (pymonotonic_new(&t, NULL, 0) < 0) {
- /* cannot happen, _PyTime_Init() checks that pymonotonic_new() works */
+ /* should not happen, _PyTime_Init() checked that monotonic clock at
+ startup */
assert(0);
+
+ /* use a fixed value instead of a random value from the stack */
t = 0;
}
return t;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list