summaryrefslogtreecommitdiffstats
path: root/Python/pytime.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-110850: Add PyTime_t C API (GH-115215)Petr Viktorin2024-02-121-32/+70
| | | | | | | | | | | | * gh-110850: Add PyTime_t C API Add PyTime_t API: * PyTime_t type. * PyTime_MIN and PyTime_MAX constants. * PyTime_AsSecondsDouble(), PyTime_Monotonic(), PyTime_PerfCounter() and PyTime_GetSystemClock() functions. Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-112567: Add _PyTimeFraction C API (#112568)Victor Stinner2023-12-011-65/+85
| | | | | | | | | | | | | | | | | | | | | Use a fraction internally in the _PyTime API to reduce the risk of integer overflow: simplify the fraction using Greatest Common Divisor (GCD). The fraction API is used by time functions: perf_counter(), monotonic() and process_time(). For example, QueryPerformanceFrequency() usually returns 10 MHz on Windows 10 and newer. The fraction SEC_TO_NS / frequency = 1_000_000_000 / 10_000_000 can be simplified to 100 / 1. * Add _PyTimeFraction type. * Add functions: * _PyTimeFraction_Set() * _PyTimeFraction_Mul() * _PyTimeFraction_Resolution() * No longer check "numer * denom <= _PyTime_MAX" in _PyTimeFraction_Set(). _PyTimeFraction_Mul() uses _PyTime_Mul() which handles integer overflow.
* gh-108277: Add os.timerfd_create() function (#108382)Masaru Tsuchiyama2023-10-071-2/+12
| | | | | | | | Add wrapper for timerfd_create, timerfd_settime, and timerfd_gettime to os module. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-108765: Python.h no longer includes <sys/time.h> (#108775)Victor Stinner2023-09-021-0/+5
| | | | | | | | | Python.h no longer includes <time.h>, <sys/select.h> and <sys/time.h> standard header files. * Add <time.h> include to xxsubtype.c. * Add <sys/time.h> include to posixmodule.c and semaphore.c. * readline.c includes <sys/select.h> instead of <sys/time.h>. * resource.c no longer includes <time.h> and <sys/time.h>.
* gh-106316: Remove pytime.h header file (#106317)Victor Stinner2023-07-011-0/+1
| | | | | | | | | | | | | | | | | Remove the "cpython/pytime.h" header file: it only contained private functions. Move functions to the internal pycore_time.h header file. Move tests from _testcapi to _testinternalcapi. Rename also test methods to have the same name than tested C functions. No longer export these functions: * _PyTime_Add() * _PyTime_As100Nanoseconds() * _PyTime_FromMicrosecondsClamp() * _PyTime_FromTimespec() * _PyTime_FromTimeval() * _PyTime_GetPerfCounterWithInfo() * _PyTime_MulDiv()
* fix typos (#106247)Inada Naoki2023-06-301-1/+1
| | | Most typos are in comments, but two typos are in docstring.
* gh-97786: Fix compiler warnings in pytime.c (#101826)Mark Dickinson2023-02-201-6/+29
| | | Fixes compiler warnings in pytime.c.
* gh-74953: Add _PyTime_FromMicrosecondsClamp() function (#93942)Victor Stinner2022-06-171-0/+8
|
* gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)Victor Stinner2022-04-201-23/+40
| | | | | | | | | | | | Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
* bpo-46670: Test if a macro is defined, not its value (GH-31178)Victor Stinner2022-02-071-1/+1
| | | | | | | | * audioop.c: #ifdef WORDS_BIGENDIAN * ctypes.h: #ifdef USING_MALLOC_CLOSURE_DOT_C * _ctypes/malloc_closure.c: #ifdef HAVE_FFI_CLOSURE_ALLOC and #ifdef USING_APPLE_OS_LIBFFI * pytime.c: #ifdef __APPLE__ * unicodeobject.c: #ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION
* bpo-45412: Remove Py_SET_ERRNO_ON_MATH_ERROR() macro (GH-28820)Victor Stinner2021-10-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | Remove the following math macros using the errno variable: * Py_ADJUST_ERANGE1() * Py_ADJUST_ERANGE2() * Py_OVERFLOWED() * Py_SET_ERANGE_IF_OVERFLOW() * Py_SET_ERRNO_ON_MATH_ERROR() Create pycore_pymath.h internal header file. Rename Py_ADJUST_ERANGE1() and Py_ADJUST_ERANGE2() to _Py_ADJUST_ERANGE1() and _Py_ADJUST_ERANGE2(), and convert these macros to static inline functions. Move the following macros to pycore_pymath.h: * _Py_IntegralTypeSigned() * _Py_IntegralTypeMax() * _Py_IntegralTypeMin() * _Py_InIntegralTypeRange()
* bpo-41710: Add private _PyDeadline_Get() function (GH-28674)Victor Stinner2021-10-011-23/+62
| | | | | | | | Add a private C API for deadlines: add _PyDeadline_Init() and _PyDeadline_Get() functions. * Add _PyTime_Add() and _PyTime_Mul() functions which compute t1+t2 and t1*t2 and clamp the result on overflow. * _PyTime_MulDiv() now uses _PyTime_Add() and _PyTime_Mul().
* bpo-41710: Fix building pytime.c on Windows (GH-28644)Victor Stinner2021-09-301-5/+5
|
* bpo-41710: Add pytime_add() and pytime_mul() (GH-28642)Victor Stinner2021-09-301-99/+96
| | | | | | Add pytime_add() and pytime_mul() functions to pytime.c to compute t+t2 and t*k with clamping to [_PyTime_MIN; _PyTime_MAX]. Fix pytime.h: _PyTime_FromTimeval() is not implemented on Windows.
* bpo-41710: Add _PyTime_AsTimespec_clamp() (GH-28629)Victor Stinner2021-09-301-76/+162
| | | | | | | | | | | | | | | Add the _PyTime_AsTimespec_clamp() function: similar to _PyTime_AsTimespec(), but clamp to _PyTime_t min/max and don't raise an exception. PyThread_acquire_lock_timed() now uses _PyTime_AsTimespec_clamp() to remove the Py_UNREACHABLE() code path. * Add _PyTime_AsTime_t() function. * Add PY_TIME_T_MIN and PY_TIME_T_MAX constants. * Replace _PyTime_AsTimeval_noraise() with _PyTime_AsTimeval_clamp(). * Add pytime_divide_round_up() function. * Fix integer overflow in pytime_divide(). * Add pytime_divmod() function.
* bpo-41299: QueryPerformanceFrequency() cannot fail (GH-28552)Victor Stinner2021-09-241-21/+7
| | | | | | py_win_perf_counter_frequency() no longer checks for QueryPerformanceFrequency() failure. According to the QueryPerformanceFrequency() documentation, the function can no longer fails since Windows XP.
* bpo-21302: time.sleep() uses waitable timer on Windows (GH-28483)Victor Stinner2021-09-221-0/+11
| | | | | | | | | | | | On Windows, time.sleep() now uses a waitable timer which has a resolution of 100 ns (10^-7 sec). Previously, it had a solution of 1 ms (10^-3 sec). * On Windows, time.sleep() now calls PyErr_CheckSignals() before resetting the SIGINT event. * Add _PyTime_As100Nanoseconds() function. * Complete and update time.sleep() documentation. Co-authored-by: Livius <egyszeregy@freemail.hu>
* bpo-21302: Add _PyTime_AsNanoseconds() (GH-28350)Victor Stinner2021-09-151-123/+188
| | | | | | | | | | | | | | | | | Refactor pytime.c: * Add pytime_from_nanoseconds() and pytime_as_nanoseconds(), and use explicitly these functions * Add two empty lines between functions * PEP 7: add braces { ... } * C99: declare variables where they are set * Rename private functions to lowercase * Rename error_time_t_overflow() to pytime_time_t_overflow() * Rename win_perf_counter_frequency() to py_win_perf_counter_frequency() * py_get_monotonic_clock(): add an assertion to detect overflow when mach_absolute_time() unsigned uint64_t is casted to _PyTime_t (signed int64_t). _testcapi: use _PyTime_FromNanoseconds().
* bpo-37205: time.time() cannot fail with fatal error (GH-23314)Victor Stinner2020-11-161-106/+132
| | | | | | | | | | | | | | | time.time(), time.perf_counter() and time.monotonic() functions can no longer fail with a Python fatal error, instead raise a regular Python exception on failure. Remove _PyTime_Init(): don't check system, monotonic and perf counter clocks at startup anymore. On error, _PyTime_GetSystemClock(), _PyTime_GetMonotonicClock() and _PyTime_GetPerfCounter() now silently ignore the error and return 0. They cannot fail with a Python fatal error anymore. Add py_mach_timebase_info() and win_perf_counter_frequency() sub-functions.
* bpo-37205: time.perf_counter() and time.monotonic() are system-wide (GH-23284)Victor Stinner2020-11-161-14/+2
| | | | | | | time.perf_counter() on Windows and time.monotonic() on macOS are now system-wide. Previously, they used an offset computed at startup to reduce the precision loss caused by the float type. Use time.perf_counter_ns() and time.monotonic_ns() added in Python 3.7 to avoid this precision loss.
* bpo-41100: Support macOS 11 and Apple Silicon (GH-22855)Ronald Oussoren2020-11-081-3/+28
| | | | | | | | | | | Co-authored-by: Lawrence D’Anna <lawrence_danna@apple.com> * Add support for macOS 11 and Apple Silicon (aka arm64) As a side effect of this work use the system copy of libffi on macOS, and remove the vendored copy * Support building on recent versions of macOS while deploying to older versions This allows building installers on macOS 11 while still supporting macOS 10.9.
* bpo-40650: Include winsock2.h in pytime.c, instead of a full windows.h ↵Minmin Gong2020-05-181-1/+1
| | | | (GH-20137)
* bpo-38249: Expand Py_UNREACHABLE() to __builtin_unreachable() in the release ↵Serhiy Storchaka2020-03-091-4/+4
| | | | | mode. (GH-16329) Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-39502: Fix 64-bit Python PyTime_localtime() on AIX (GH-18285)Michael Felt2020-02-071-1/+1
| | | Fix time.localtime() on 64-bit AIX to support years before 1902 and after 2038.
* bpo-38068: Clean up gettimeofday configure logic. (GH-15775)Benjamin Peterson2019-09-101-4/+0
| | | Assume gettimeofday exists and takes two arguments.
* bpo-34373: Fix time.mktime() on AIX (GH-12726)Victor Stinner2019-04-091-10/+7
| | | | | | | | | | | | | | | Fix time.mktime() error handling on AIX for year before 1970. Other changes: * mktime(): rename variable 'buf' to 'tm'. * _PyTime_localtime(): * Use "localtime" rather than "ctime" in the error message (specific to AIX). * Always initialize errno to 0 just in case if localtime_r() doesn't set errno on error. * On AIX, avoid abs() which is limited to int type. * EINVAL constant is now always available.
* bpo-34373: fix test_mktime and test_pthread_getcpuclickid tests on AIX (GH-8726)Michael Felt2018-12-281-0/+14
| | | | | | | | | * Fix test_mktime on AIX by adding code to get mktime to behave the same way as it does on other *nix systems * Fix test_pthread_getcpuclickid in AIX by adjusting the test case expectations when running on AIX in 32-bit mode Patch by Michael Felt.
* Fix miscellaneous typos (#4275)luzpaz2017-11-051-1/+1
|
* bpo-31784: Implement PEP 564: add time.time_ns() (#3989)Victor Stinner2017-11-021-19/+86
| | | | | | | | | | | | | | | | | | | | | | | | | Add new time functions: * time.clock_gettime_ns() * time.clock_settime_ns() * time.monotonic_ns() * time.perf_counter_ns() * time.process_time_ns() * time.time_ns() Add new _PyTime functions: * _PyTime_FromTimespec() * _PyTime_FromNanosecondsObject() * _PyTime_FromTimeval() Other changes: * Add also os.times() tests to test_os. * pytime_fromtimeval() and pytime_fromtimeval() now return _PyTime_MAX or _PyTime_MIN on overflow, rather than undefined behaviour * _PyTime_FromNanoseconds() parameter type changes from long long to _PyTime_t
* bpo-31786: Make functions in the select module blocking when timeout is a ↵Pablo Galindo2017-10-171-2/+15
| | | | small negative value. (#4003)
* bpo-31773: _PyTime_GetPerfCounter() uses _PyTime_t (GH-3983)Victor Stinner2017-10-161-36/+122
| | | | | | | | * Rewrite win_perf_counter() to only use integers internally. * Add _PyTime_MulDiv() which compute "ticks * mul / div" in two parts (int part and remaining) to prevent integer overflow. * Clock frequency is checked at initialization for integer overflow. * Enhance also pymonotonic() to reduce the precision loss on macOS (mach_absolute_time() clock).
* bpo-31773: time.perf_counter() uses again double (GH-3964)Victor Stinner2017-10-121-15/+21
| | | | | | | | time.clock() and time.perf_counter() now use again C double internally. Remove also _PyTime_GetWinPerfCounterWithInfo(): use _PyTime_GetPerfCounterDoubleWithInfo() instead on Windows.
* Cleanup pytime.c (#3955)Victor Stinner2017-10-111-54/+76
| | | | | * Move _PyTime_overflow() at the top * Move assertion on numerator into _PyTime_ObjectToDenominator() * PEP 7: add { ... } to if blocks
* bpo-31415: Add _PyTime_GetPerfCounter() and use it for -X importtime (#3936)Victor Stinner2017-10-101-10/+71
| | | | | * Add _PyTime_GetPerfCounter() * Use _PyTime_GetPerfCounter() for -X importtime
* bpo-31338 (#3374)Barry Warsaw2017-09-151-9/+3
| | | | | | | * Add Py_UNREACHABLE() as an alias to abort(). * Use Py_UNREACHABLE() instead of assert(0) * Convert more unreachable code to use Py_UNREACHABLE() * Document Py_UNREACHABLE() and a few other macros.
* bpo-26669: Fix nan arg value error in pytime.c (#3085)Han Lee2017-09-081-0/+14
| | | | | | | | | | * Fix #26669 * Modify NaN check function and error message * Fix pytime.c when arg is nan * fix whitespace
* bpo-31373: fix undefined floating-point demotions (#3396)Benjamin Peterson2017-09-071-16/+16
|
* Revert "pytime: include winsock2, so we can have a complete timeval type ↵Antoine Pitrou2017-09-061-1/+0
| | | | | (#3377)" (#3383) This reverts commit 833860615bedfd2484ac0623d6f01ff0578ba09f, as it broke Windows builds.
* pytime: include winsock2, so we can have a complete timeval type (#3377)Benjamin Peterson2017-09-061-0/+1
|
* bpo-30183: Fixes HP-UX cc compilation error in pytime.c (#1351)haney2017-06-211-0/+20
| | | | | | | | | | | | | | | | * bpo-30183: Fixes HP-UX cc compilation error in pytime.c HP-UX does not support the CLOCK_MONOTONIC identifier, and will fail to compile: "Python/pytime.c", line 723: error #2020: identifier "CLOCK_MONOTONIC" is undefined const clockid_t clk_id = CLOCK_MONOTONIC; Add a new section for __hpux that calls 'gethrtime()' instead of 'clock_gettime()'. * bpo-30183: Removes unnecessary return
* Issue #28148: Stop using localtime() and gmtime() in the time module.Alexander Belopolsky2016-09-281-0/+52
| | | | | | Introduced platform independent _PyTime_localtime API that is similar to POSIX localtime_r, but available on all platforms. Patch by Ed Schouten.
* replace PY_LONG_LONG with long longBenjamin Peterson2016-09-061-9/+9
|
* require a long long data type (closes #27961)Benjamin Peterson2016-09-061-14/+2
|
* Merge 3.5 (pytime)Victor Stinner2015-11-101-3/+3
|\
| * pytime.c: rename pygettimeofday_new() to pygettimeofday()Victor Stinner2015-11-101-3/+3
| | | | | | | | I forgot to rename it in my previous refactoring of pytime.c.
| * Issue #25155: Fix _PyTime_Divide() roundingVictor Stinner2015-09-181-3/+8
| | | | | | | | | | _PyTime_Divide() rounding was wrong: copy code from Python default which has now much better unit tests.
| * Issue #25155: Add _PyTime_AsTimevalTime_t() functionVictor Stinner2015-09-181-38/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Issue #25558: Use compile-time asserts.Serhiy Storchaka2015-11-071-13/+12
| |
* | Fix _PyTime_AsTimevalStruct_impl() on OpenBSDVictor Stinner2015-10-011-2/+3
| | | | | | | | | | | | 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.
* | Backout change 28d3bcb1bad6: "Try to fix _PyTime_AsTimevalStruct_impl() onVictor Stinner2015-09-301-3/+2
| | | | | | | | | | 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.