Skip to content

Commit ff0ed3e

Browse files
committed
New try to fix test_time.test_AsSecondsDouble() on x86 buildbots.
Use volatile keyword in _PyTime_AsSecondsDouble()
1 parent 1efbeba commit ff0ed3e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Python/pytime.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,21 @@ _PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t roun
332332
double
333333
_PyTime_AsSecondsDouble(_PyTime_t t)
334334
{
335+
/* volatile avoids optimization changing how numbers are rounded */
336+
volatile double d;
337+
335338
if (t % SEC_TO_NS == 0) {
336339
_PyTime_t secs;
337340
/* Divide using integers to avoid rounding issues on the integer part.
338341
1e-9 cannot be stored exactly in IEEE 64-bit. */
339342
secs = t / SEC_TO_NS;
340-
return (double)secs;
343+
d = (double)secs;
341344
}
342345
else {
343-
return (double)t / 1e9;
346+
d = (double)t;
347+
d /= 1e9;
344348
}
349+
return d;
345350
}
346351

347352
PyObject *

0 commit comments

Comments
 (0)