Commit Graph

75 Commits

Author SHA1 Message Date
Victor Stinner e0a0afdf70 Merge 3.5 (pytime) 2015-11-10 12:11:52 +01:00
Victor Stinner c379ade1bb pytime.c: rename pygettimeofday_new() to pygettimeofday()
I forgot to rename it in my previous refactoring of pytime.c.
2015-11-10 12:11:39 +01:00
Serhiy Storchaka fad85aadb0 Issue #25558: Use compile-time asserts. 2015-11-07 15:42:38 +02:00
Victor Stinner b7a8af20ff Fix _PyTime_AsTimevalStruct_impl() on OpenBSD
On the x86 OpenBSD 5.8 buildbot, the integer overflow check is ignored. Copy
the tv_sec variable into a Py_time_t variable instead of "simply" casting it to
Py_time_t, to fix the integer overflow check.
2015-10-01 08:44:03 +02:00
Victor Stinner c29f399e7e Backout change 28d3bcb1bad6: "Try to fix _PyTime_AsTimevalStruct_impl() on
OpenBSD", I'm not sure that the change was really needed. I read the test
result of an old build because the OpenBSD was 100 builds late.
2015-09-30 22:50:12 +02:00
Victor Stinner 2bfed53b88 Try to fix _PyTime_AsTimevalStruct_impl() on OpenBSD
It looks like the check for integer overflow doesn't work on x86 OpenBSD 5.8.
2015-09-29 13:41:46 +02:00
Victor Stinner ec26f83f2e Issue #25155: Fix _PyTime_Divide() rounding
_PyTime_Divide() rounding was wrong: copy code from Python default which has
now much better unit tests.
2015-09-18 14:21:14 +02:00
Victor Stinner 9a8b177e60 Issue #25155: Add _PyTime_AsTimevalTime_t() function
On Windows, the tv_sec field of the timeval structure has the type C long,
whereas it has the type C time_t on all other platforms. A C long has a size of
32 bits (signed inter, 1 bit for the sign, 31 bits for the value) which is not
enough to store an Epoch timestamp after the year 2038.

Add the _PyTime_AsTimevalTime_t() function written for datetime.datetime.now():
convert a _PyTime_t timestamp to a (secs, us) tuple where secs type is time_t.
It allows to support dates after the year 2038 on Windows.

Enhance also _PyTime_AsTimeval_impl() to detect overflow on the number of
seconds when rounding the number of microseconds.
2015-09-18 13:36:17 +02:00
Victor Stinner 1e2b6882fc Issue #25155: Add _PyTime_AsTimevalTime_t() function
On Windows, the tv_sec field of the timeval structure has the type C long,
whereas it has the type C time_t on all other platforms. A C long has a size of
32 bits (signed inter, 1 bit for the sign, 31 bits for the value) which is not
enough to store an Epoch timestamp after the year 2038.

Add the _PyTime_AsTimevalTime_t() function written for datetime.datetime.now():
convert a _PyTime_t timestamp to a (secs, us) tuple where secs type is time_t.
It allows to support dates after the year 2038 on Windows.

Enhance also _PyTime_AsTimeval_impl() to detect overflow on the number of
seconds when rounding the number of microseconds.
2015-09-18 13:23:02 +02:00
Victor Stinner 51b9398444 pytime: oops, fix typos on Windows 2015-09-10 16:00:06 +02:00
Victor Stinner c60542b12b pytime: add _PyTime_check_mul_overflow() macro to avoid undefined behaviour
Overflow test in test_FromSecondsObject() fails on FreeBSD 10.0 buildbot which
uses clang. clang implements more aggressive optimization which gives
different result than GCC on undefined behaviours.

Check if a multiplication will overflow, instead of checking if a
multiplicatin had overflowed, to avoid undefined behaviour.

Add also debug information if the test on overflow fails.
2015-09-10 15:55:07 +02:00
Victor Stinner ff0ed3e71c New try to fix test_time.test_AsSecondsDouble() on x86 buildbots.
Use volatile keyword in _PyTime_AsSecondsDouble()
2015-09-10 13:25:17 +02:00
Victor Stinner 1efbebaac2 Try to fix test_time.test_AsSecondsDouble() on "x86 Gentoo Non-Debug with X 3.x" buildbot
Use volatile keyword in _PyTime_Round()
2015-09-10 11:48:00 +02:00
Victor Stinner 9c72f9b30a Fix test_time on Windows
* Filter values which would overflow on conversion to the C long type
  (for timeval.tv_sec).
* Adjust also the message of OverflowError on PyTime conversions
* test_time: add debug information if a timestamp conversion fails
2015-09-10 09:10:14 +02:00
Victor Stinner 3e2c8d84c6 test_time: rewrite PyTime API rounding tests
Drop all hardcoded tests. Instead, reimplement each function in Python, usually
using decimal.Decimal for the rounding mode.

Add much more values to the dataset. Test various timestamp units from
picroseconds to seconds, in integer and float.

Enhance also _PyTime_AsSecondsDouble().
2015-09-09 22:32:48 +02:00
Victor Stinner 9ae47dfbd9 pytime: add _PyTime_Round() helper to factorize code 2015-09-09 22:28:58 +02:00
Victor Stinner ce6aa749b4 Make _PyTime_RoundHalfEven() private again 2015-09-09 22:28:09 +02:00
Victor Stinner 7667f58151 Issue #23517: fromtimestamp() and utcfromtimestamp() methods of
datetime.datetime now round microseconds to nearest with ties going to nearest
even integer (ROUND_HALF_EVEN), as round(float), instead of rounding towards
-Infinity (ROUND_FLOOR).

pytime API: replace _PyTime_ROUND_HALF_UP with _PyTime_ROUND_HALF_EVEN. Fix
also _PyTime_Divide() for negative numbers.

_PyTime_AsTimeval_impl() now reuses _PyTime_Divide() instead of reimplementing
rounding modes.
2015-09-09 01:02:23 +02:00
Victor Stinner adfefa527a Issue #23517: Fix implementation of the ROUND_HALF_UP rounding mode in
datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp().
microseconds sign should be kept before rounding.
2015-09-04 23:57:25 +02:00
Victor Stinner 5786aef382 Don't abuse volatile keyword in pytime.c
Only use it on the most important number. This change fixes also a compiler
warning on modf().
2015-09-03 16:33:16 +02:00
Victor Stinner 29ee6745af Enhance _PyTime_AsTimespec()
Ensure that the tv_nsec field is set, even if the function fails
with an overflow.
2015-09-03 16:25:45 +02:00
Victor Stinner 5a682c9ca5 Merge 3.5 (monotonic) 2015-09-03 00:15:23 +02:00
Victor Stinner 5ad5821d09 oops, rename pymonotonic_new() to pymonotonic()
I was not supposed to commit the function with the name pymonotonic_new(). I
forgot to rename it.
2015-09-03 00:14:58 +02:00
Victor Stinner c3c616c3d1 Issue #24707: Remove assertion in monotonic clock
Don't check anymore at runtime that the monotonic clock doesn't go backward.
Yes, it happens. It occurs sometimes each month on a Debian buildbot slave
running in a VM.

The problem is that Python cannot do anything useful if a monotonic clock goes
backward. It was decided in the PEP 418 to not fix the system, but only expose
the clock provided by the OS.
2015-09-03 00:13:46 +02:00
Victor Stinner 2ec558739e Issue #23517: datetime.timedelta constructor now rounds microseconds to nearest
with ties going away from zero (ROUND_HALF_UP), as Python 2 and Python older
than 3.3, instead of rounding to nearest with ties going to nearest even
integer (ROUND_HALF_EVEN).
2015-09-02 19:16:07 +02:00
Victor Stinner 24b822e21e Issue #23517: Try to fix test_time on "x86 Ubuntu Shared 3.x" buildbot 2015-09-02 11:58:56 +02:00
Victor Stinner 67edcc905d Issue #23517: Fix _PyTime_ObjectToDenominator()
* initialize numerator on overflow error ensure that numerator is smaller than
* denominator.
2015-09-02 10:37:46 +02:00
Victor Stinner 744742320f Issue #23517: Add "half up" rounding mode to the _PyTime API 2015-09-02 01:43:56 +02:00
Victor Stinner bbdda21a7a Move assertion inside _PyTime_ObjectToTimeval()
Change also _PyTime_FromSeconds() assertion to ensure that the _PyTime_t type
is used.
2015-09-02 00:50:43 +02:00
Victor Stinner 53e137c8dd Refactor pytime.c
Move code to convert double timestamp to subfunctions.
2015-09-02 00:49:16 +02:00
Victor Stinner 13019fdef3 Issue #22117: Add a new _PyTime_FromSeconds() function
Fix also _Py_InitializeEx_Private(): initialize time before initializing
import, import_init() uses the _PyTime API (for thread locks).
2015-04-03 13:10:54 +02:00
Victor Stinner 62d1c70eff Issue #22117, issue #23485: Fix _PyTime_AsMilliseconds() and
_PyTime_AsMicroseconds() rounding.

Add also unit tests.
2015-04-01 17:47:07 +02:00
Victor Stinner fa09beb150 Issue #23485: Add _PyTime_FromMillisecondsObject() function 2015-03-30 21:36:10 +02:00
Victor Stinner 45cff0c0e6 Issue #22117: Try to fix rounding in conversion from Python double to _PyTime_t
using the C volatile keyword.
2015-03-30 10:22:16 +02:00
Victor Stinner a695f83f0d Issue #22117: Remove _PyTime_ROUND_DOWN and _PyTime_ROUND_UP rounding methods
Use _PyTime_ROUND_FLOOR and _PyTime_ROUND_CEILING instead.
2015-03-30 03:57:14 +02:00
Victor Stinner bcdd777d3c Issue #22117: Add _PyTime_ROUND_CEILING rounding method for timestamps
Add also more tests for ROUNd_FLOOR.
2015-03-30 03:52:49 +02:00
Victor Stinner edddf991d9 Issue #22117: Add assertions to _PyTime_AsTimeval() and _PyTime_AsTimespec() to
check that microseconds and nanoseconds fits into the specified range.
2015-03-30 02:54:57 +02:00
Victor Stinner ea9c0dd2c2 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.
2015-03-30 02:51:13 +02:00
Victor Stinner f81f0f9c63 Issue #22117: Fix rounding and implement _PyTime_ROUND_FLOOR in:
- _PyTime_ObjectToTime_t()
- _PyTime_ObjectToTimespec()
- _PyTime_ObjectToTimeval()
2015-03-30 00:44:06 +02:00
Victor Stinner 1bd18ba9a7 Issue #22117: Cleanup pytime.c/.h 2015-03-30 00:25:38 +02:00
Victor Stinner 09e5cf28ae Issue #22117: Use the _PyTime_t API in _datetime.datetime() constructor
* Remove _PyTime_gettimeofday()
* Add _PyTime_GetSystemClock()
2015-03-30 00:09:18 +02:00
Victor Stinner cb0c60258b Issue #22117: Fix _PyTime_GetMonotonicClock() and
_PyTime_GetSystemClockWithInfo() to not raise an exception and return 0 on
error (it should never occur)
2015-03-28 05:24:19 +01:00
Victor Stinner 02937aab13 Issue #22117: Add the new _PyTime_ROUND_FLOOR rounding method for the datetime
module. time.clock_settime() now uses this rounding method instead of
_PyTime_ROUND_DOWN to handle correctly dates before 1970.
2015-03-28 05:02:39 +01:00
Victor Stinner b3b4544070 Issue #22117: Use the _PyTime_t API for time.clock_settime()
Remove also the now unused _PyTime_AddDouble() function.
2015-03-28 04:09:41 +01:00
Victor Stinner c337838af7 Issue #22117: Use the new _PyTime_t API in the select module 2015-03-28 05:07:51 +01:00
Victor Stinner f5faad2bf0 Issue #22117: The thread module uses the new _PyTime_t timestamp API
Add also a new _PyTime_AsMicroseconds() function.

threading.TIMEOUT_MAX is now be smaller: only 292 years instead of 292,271
years on 64-bit system for example. Sorry, your threads will hang a *little
bit* shorter. Call me if you want to ensure that your locks wait longer, I can
share some tricks with you.
2015-03-28 03:52:05 +01:00
Victor Stinner 95e9cef6f0 Issue #22117: Write unit tests for _PyTime_AsTimeval()
* _PyTime_AsTimeval() now ensures that tv_usec is always positive
* _PyTime_AsTimespec() now ensures that tv_nsec is always positive
* _PyTime_AsTimeval() now returns an integer on overflow instead of raising an
  exception
2015-03-28 01:26:47 +01:00
Victor Stinner 34dc0f46ae Issue #22117: The signal modules uses the new _PyTime_t API
* Add _PyTime_AsTimespec()
* Add unit tests for _PyTime_AsTimespec()
2015-03-27 18:19:03 +01:00
Victor Stinner a47b881d86 Issue #22117: time.time() now uses the new _PyTime_t API
* Add _PyTime_GetSystemClockWithInfo()
2015-03-27 18:16:17 +01:00
Victor Stinner 4bfb460d88 Issue #22117: time.monotonic() now uses the new _PyTime_t API
* Add _PyTime_FromNanoseconds()
* Add _PyTime_AsSecondsDouble()
* Add unit tests for _PyTime_AsSecondsDouble()
2015-03-27 22:27:24 +01:00