]> granicus.if.org Git - python/commitdiff
New try to fix test_time.test_AsSecondsDouble() on x86 buildbots.
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 10 Sep 2015 11:25:17 +0000 (13:25 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 10 Sep 2015 11:25:17 +0000 (13:25 +0200)
Use volatile keyword in _PyTime_AsSecondsDouble()

Python/pytime.c

index 9470636fdc7e32bbe2358e26685583a13f4d0527..c82d5985b4783daf127c02fecdf9e3512c079e50 100644 (file)
@@ -332,16 +332,21 @@ _PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t roun
 double
 _PyTime_AsSecondsDouble(_PyTime_t t)
 {
+    /* volatile avoids optimization changing how numbers are rounded */
+    volatile double d;
+
     if (t % SEC_TO_NS == 0) {
         _PyTime_t secs;
         /* Divide using integers to avoid rounding issues on the integer part.
            1e-9 cannot be stored exactly in IEEE 64-bit. */
         secs = t / SEC_TO_NS;
-        return (double)secs;
+        d = (double)secs;
     }
     else {
-        return (double)t / 1e9;
+        d = (double)t;
+        d /= 1e9;
     }
+    return d;
 }
 
 PyObject *