[Python-checkins] cpython: Issue #23517: Try to fix test_time on "x86 Ubuntu Shared 3.x" buildbot

victor.stinner python-checkins at python.org
Wed Sep 2 12:01:42 CEST 2015


https://hg.python.org/cpython/rev/df074eb2a5be
changeset:   97574:df074eb2a5be
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Sep 02 11:58:56 2015 +0200
summary:
  Issue #23517: Try to fix test_time on "x86 Ubuntu Shared 3.x" buildbot

files:
  Python/pytime.c |  17 ++++++++++-------
  1 files changed, 10 insertions(+), 7 deletions(-)


diff --git a/Python/pytime.c b/Python/pytime.c
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -64,11 +64,13 @@
 static double
 _PyTime_RoundHalfUp(double x)
 {
-    if (x >= 0.0)
-        x = floor(x + 0.5);
+    /* volatile avoids optimization changing how numbers are rounded */
+    volatile double d = x;
+    if (d >= 0.0)
+        d = floor(d + 0.5);
     else
-        x = ceil(x - 0.5);
-    return x;
+        d = ceil(d - 0.5);
+    return d;
 }
 
 
@@ -77,7 +79,7 @@
                             double denominator, _PyTime_round_t round)
 {
     double intpart, err;
-    /* volatile avoids unsafe optimization on float enabled by gcc -O3 */
+    /* volatile avoids optimization changing how numbers are rounded */
     volatile double floatpart;
 
     floatpart = modf(d, &intpart);
@@ -134,7 +136,8 @@
 _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round)
 {
     if (PyFloat_Check(obj)) {
-        double d, intpart, err;
+        /* volatile avoids optimization changing how numbers are rounded */
+        volatile double d, intpart, err;
 
         d = PyFloat_AsDouble(obj);
         if (round == _PyTime_ROUND_HALF_UP)
@@ -255,7 +258,7 @@
 _PyTime_FromFloatObject(_PyTime_t *t, double value, _PyTime_round_t round,
                         long to_nanoseconds)
 {
-    /* volatile avoids unsafe optimization on float enabled by gcc -O3 */
+    /* volatile avoids optimization changing how numbers are rounded */
     volatile double d, err;
 
     /* convert to a number of nanoseconds */

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list