From a7f2d83baf05bfb04e152f57b35fbbf2543a750d Mon Sep 17 00:00:00 2001 From: Nicholas Sim Date: Thu, 24 Dec 2020 13:18:54 +0800 Subject: [PATCH 1/5] bpo-35134: Add Include/cpython/pytime.h file Add Include/cpython/pytime.h header file. Move CPython C API from Include/pytime.h into a new Include/cpython/pytime.h header file, which is included by Include/pytime.h. --- Include/cpython/pytime.h | 237 ++++++++++++++++++++++++++++ Include/pytime.h | 242 +---------------------------- Makefile.pre.in | 1 + PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 + 5 files changed, 249 insertions(+), 235 deletions(-) create mode 100644 Include/cpython/pytime.h diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h new file mode 100644 index 00000000000000..800c719910fed0 --- /dev/null +++ b/Include/cpython/pytime.h @@ -0,0 +1,237 @@ +#ifndef Py_CPYTHON_PYTIME_H +# error "this header file must not be included directly" +#endif + +/************************************************************************** +Symbols and macros to supply platform-independent interfaces to time related +functions and constants +**************************************************************************/ + +/* _PyTime_t: Python timestamp with subsecond precision. It can be used to + store a duration, and so indirectly a date (related to another date, like + UNIX epoch). */ +typedef int64_t _PyTime_t; +#define _PyTime_MIN INT64_MIN +#define _PyTime_MAX INT64_MAX + +typedef enum { + /* Round towards minus infinity (-inf). + For example, used to read a clock. */ + _PyTime_ROUND_FLOOR=0, + /* Round towards infinity (+inf). + For example, used for timeout to wait "at least" N seconds. */ + _PyTime_ROUND_CEILING=1, + /* Round to nearest with ties going to nearest even integer. + For example, used to round from a Python float. */ + _PyTime_ROUND_HALF_EVEN=2, + /* Round away from zero + For example, used for timeout. _PyTime_ROUND_CEILING rounds + -1e-9 to 0 milliseconds which causes bpo-31786 issue. + _PyTime_ROUND_UP rounds -1e-9 to -1 millisecond which keeps + the timeout sign as expected. select.poll(timeout) must block + for negative values." */ + _PyTime_ROUND_UP=3, + /* _PyTime_ROUND_TIMEOUT (an alias for _PyTime_ROUND_UP) should be + used for timeouts. */ + _PyTime_ROUND_TIMEOUT = _PyTime_ROUND_UP +} _PyTime_round_t; + + +/* Convert a time_t to a PyLong. */ +PyAPI_FUNC(PyObject *) _PyLong_FromTime_t( + time_t sec); + +/* Convert a PyLong to a time_t. */ +PyAPI_FUNC(time_t) _PyLong_AsTime_t( + PyObject *obj); + +/* Convert a number of seconds, int or float, to time_t. */ +PyAPI_FUNC(int) _PyTime_ObjectToTime_t( + PyObject *obj, + time_t *sec, + _PyTime_round_t); + +/* Convert a number of seconds, int or float, to a timeval structure. + usec is in the range [0; 999999] and rounded towards zero. + For example, -1.2 is converted to (-2, 800000). */ +PyAPI_FUNC(int) _PyTime_ObjectToTimeval( + PyObject *obj, + time_t *sec, + long *usec, + _PyTime_round_t); + +/* Convert a number of seconds, int or float, to a timespec structure. + nsec is in the range [0; 999999999] and rounded towards zero. + For example, -1.2 is converted to (-2, 800000000). */ +PyAPI_FUNC(int) _PyTime_ObjectToTimespec( + PyObject *obj, + time_t *sec, + long *nsec, + _PyTime_round_t); + + +/* Create a timestamp from a number of seconds. */ +PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds); + +/* Macro to create a timestamp from a number of seconds, no integer overflow. + Only use the macro for small values, prefer _PyTime_FromSeconds(). */ +#define _PYTIME_FROMSECONDS(seconds) \ + ((_PyTime_t)(seconds) * (1000 * 1000 * 1000)) + +/* Create a timestamp from a number of nanoseconds. */ +PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns); + +/* Create a timestamp from nanoseconds (Python int). */ +PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t, + PyObject *obj); + +/* Convert a number of seconds (Python float or int) to a timetamp. + Raise an exception and return -1 on error, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t, + PyObject *obj, + _PyTime_round_t round); + +/* Convert a number of milliseconds (Python float or int, 10^-3) to a timetamp. + Raise an exception and return -1 on error, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t, + PyObject *obj, + _PyTime_round_t round); + +/* Convert a timestamp to a number of seconds as a C double. */ +PyAPI_FUNC(double) _PyTime_AsSecondsDouble(_PyTime_t t); + +/* Convert timestamp to a number of milliseconds (10^-3 seconds). */ +PyAPI_FUNC(_PyTime_t) _PyTime_AsMilliseconds(_PyTime_t t, + _PyTime_round_t round); + +/* Convert timestamp to a number of microseconds (10^-6 seconds). */ +PyAPI_FUNC(_PyTime_t) _PyTime_AsMicroseconds(_PyTime_t t, + _PyTime_round_t round); + +/* Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int + object. */ +PyAPI_FUNC(PyObject *) _PyTime_AsNanosecondsObject(_PyTime_t t); + +/* Create a timestamp from a timeval structure. + Raise an exception and return -1 on overflow, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv); + +/* Convert a timestamp to a timeval structure (microsecond resolution). + tv_usec is always positive. + Raise an exception and return -1 if the conversion overflowed, + return 0 on success. */ +PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t, + struct timeval *tv, + _PyTime_round_t round); + +/* Similar to _PyTime_AsTimeval(), but don't raise an exception on error. */ +PyAPI_FUNC(int) _PyTime_AsTimeval_noraise(_PyTime_t t, + struct timeval *tv, + _PyTime_round_t round); + +/* Convert a timestamp to a number of seconds (secs) and microseconds (us). + us is always positive. This function is similar to _PyTime_AsTimeval() + except that secs is always a time_t type, whereas the timeval structure + uses a C long for tv_sec on Windows. + Raise an exception and return -1 if the conversion overflowed, + return 0 on success. */ +PyAPI_FUNC(int) _PyTime_AsTimevalTime_t( + _PyTime_t t, + time_t *secs, + int *us, + _PyTime_round_t round); + +#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE) +/* Create a timestamp from a timespec structure. + Raise an exception and return -1 on overflow, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts); + +/* Convert a timestamp to a timespec structure (nanosecond resolution). + tv_nsec is always positive. + Raise an exception and return -1 on error, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts); +#endif + +/* Compute ticks * mul / div. + The caller must ensure that ((div - 1) * mul) cannot overflow. */ +PyAPI_FUNC(_PyTime_t) _PyTime_MulDiv(_PyTime_t ticks, + _PyTime_t mul, + _PyTime_t div); + +/* Structure used by time.get_clock_info() */ +typedef struct { + const char *implementation; + int monotonic; + int adjustable; + double resolution; +} _Py_clock_info_t; + +/* Get the current time from the system clock. + + If the internal clock fails, silently ignore the error and return 0. + On integer overflow, silently ignore the overflow and truncated the clock to + _PyTime_MIN or _PyTime_MAX. + + Use _PyTime_GetSystemClockWithInfo() to check for failure. */ +PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void); + +/* Get the current time from the system clock. + * On success, set *t and *info (if not NULL), and return 0. + * On error, raise an exception and return -1. + */ +PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( + _PyTime_t *t, + _Py_clock_info_t *info); + +/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. + The clock is not affected by system clock updates. The reference point of + the returned value is undefined, so that only the difference between the + results of consecutive calls is valid. + + If the internal clock fails, silently ignore the error and return 0. + On integer overflow, silently ignore the overflow and truncated the clock to + _PyTime_MIN or _PyTime_MAX. + + Use _PyTime_GetMonotonicClockWithInfo() to check for failure. */ +PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); + +/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. + The clock is not affected by system clock updates. The reference point of + the returned value is undefined, so that only the difference between the + results of consecutive calls is valid. + + Fill info (if set) with information of the function used to get the time. + + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo( + _PyTime_t *t, + _Py_clock_info_t *info); + + +/* Converts a timestamp to the Gregorian time, using the local time zone. + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm); + +/* Converts a timestamp to the Gregorian time, assuming UTC. + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); + +/* Get the performance counter: clock with the highest available resolution to + measure a short duration. + + If the internal clock fails, silently ignore the error and return 0. + On integer overflow, silently ignore the overflow and truncated the clock to + _PyTime_MIN or _PyTime_MAX. + + Use _PyTime_GetPerfCounterWithInfo() to check for failure. */ +PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void); + +/* Get the performance counter: clock with the highest available resolution to + measure a short duration. + + Fill info (if set) with information of the function used to get the time. + + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_GetPerfCounterWithInfo( + _PyTime_t *t, + _Py_clock_info_t *info); diff --git a/Include/pytime.h b/Include/pytime.h index 944170f7d0c4c3..f11424a1760edf 100644 --- a/Include/pytime.h +++ b/Include/pytime.h @@ -1,250 +1,22 @@ -#ifndef Py_LIMITED_API #ifndef Py_PYTIME_H #define Py_PYTIME_H -#include "pyconfig.h" /* include for defines */ -#include "object.h" - -/************************************************************************** -Symbols and macros to supply platform-independent interfaces to time related -functions and constants -**************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/* _PyTime_t: Python timestamp with subsecond precision. It can be used to - store a duration, and so indirectly a date (related to another date, like - UNIX epoch). */ -typedef int64_t _PyTime_t; -#define _PyTime_MIN INT64_MIN -#define _PyTime_MAX INT64_MAX - -typedef enum { - /* Round towards minus infinity (-inf). - For example, used to read a clock. */ - _PyTime_ROUND_FLOOR=0, - /* Round towards infinity (+inf). - For example, used for timeout to wait "at least" N seconds. */ - _PyTime_ROUND_CEILING=1, - /* Round to nearest with ties going to nearest even integer. - For example, used to round from a Python float. */ - _PyTime_ROUND_HALF_EVEN=2, - /* Round away from zero - For example, used for timeout. _PyTime_ROUND_CEILING rounds - -1e-9 to 0 milliseconds which causes bpo-31786 issue. - _PyTime_ROUND_UP rounds -1e-9 to -1 millisecond which keeps - the timeout sign as expected. select.poll(timeout) must block - for negative values." */ - _PyTime_ROUND_UP=3, - /* _PyTime_ROUND_TIMEOUT (an alias for _PyTime_ROUND_UP) should be - used for timeouts. */ - _PyTime_ROUND_TIMEOUT = _PyTime_ROUND_UP -} _PyTime_round_t; - - -/* Convert a time_t to a PyLong. */ -PyAPI_FUNC(PyObject *) _PyLong_FromTime_t( - time_t sec); - -/* Convert a PyLong to a time_t. */ -PyAPI_FUNC(time_t) _PyLong_AsTime_t( - PyObject *obj); - -/* Convert a number of seconds, int or float, to time_t. */ -PyAPI_FUNC(int) _PyTime_ObjectToTime_t( - PyObject *obj, - time_t *sec, - _PyTime_round_t); - -/* Convert a number of seconds, int or float, to a timeval structure. - usec is in the range [0; 999999] and rounded towards zero. - For example, -1.2 is converted to (-2, 800000). */ -PyAPI_FUNC(int) _PyTime_ObjectToTimeval( - PyObject *obj, - time_t *sec, - long *usec, - _PyTime_round_t); - -/* Convert a number of seconds, int or float, to a timespec structure. - nsec is in the range [0; 999999999] and rounded towards zero. - For example, -1.2 is converted to (-2, 800000000). */ -PyAPI_FUNC(int) _PyTime_ObjectToTimespec( - PyObject *obj, - time_t *sec, - long *nsec, - _PyTime_round_t); - - -/* Create a timestamp from a number of seconds. */ -PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds); - -/* Macro to create a timestamp from a number of seconds, no integer overflow. - Only use the macro for small values, prefer _PyTime_FromSeconds(). */ -#define _PYTIME_FROMSECONDS(seconds) \ - ((_PyTime_t)(seconds) * (1000 * 1000 * 1000)) - -/* Create a timestamp from a number of nanoseconds. */ -PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns); - -/* Create a timestamp from nanoseconds (Python int). */ -PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t, - PyObject *obj); - -/* Convert a number of seconds (Python float or int) to a timetamp. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t, - PyObject *obj, - _PyTime_round_t round); - -/* Convert a number of milliseconds (Python float or int, 10^-3) to a timetamp. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t, - PyObject *obj, - _PyTime_round_t round); - -/* Convert a timestamp to a number of seconds as a C double. */ -PyAPI_FUNC(double) _PyTime_AsSecondsDouble(_PyTime_t t); - -/* Convert timestamp to a number of milliseconds (10^-3 seconds). */ -PyAPI_FUNC(_PyTime_t) _PyTime_AsMilliseconds(_PyTime_t t, - _PyTime_round_t round); - -/* Convert timestamp to a number of microseconds (10^-6 seconds). */ -PyAPI_FUNC(_PyTime_t) _PyTime_AsMicroseconds(_PyTime_t t, - _PyTime_round_t round); - -/* Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int - object. */ -PyAPI_FUNC(PyObject *) _PyTime_AsNanosecondsObject(_PyTime_t t); - -/* Create a timestamp from a timeval structure. - Raise an exception and return -1 on overflow, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv); - -/* Convert a timestamp to a timeval structure (microsecond resolution). - tv_usec is always positive. - Raise an exception and return -1 if the conversion overflowed, - return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t, - struct timeval *tv, - _PyTime_round_t round); - -/* Similar to _PyTime_AsTimeval(), but don't raise an exception on error. */ -PyAPI_FUNC(int) _PyTime_AsTimeval_noraise(_PyTime_t t, - struct timeval *tv, - _PyTime_round_t round); - -/* Convert a timestamp to a number of seconds (secs) and microseconds (us). - us is always positive. This function is similar to _PyTime_AsTimeval() - except that secs is always a time_t type, whereas the timeval structure - uses a C long for tv_sec on Windows. - Raise an exception and return -1 if the conversion overflowed, - return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimevalTime_t( - _PyTime_t t, - time_t *secs, - int *us, - _PyTime_round_t round); - -#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE) -/* Create a timestamp from a timespec structure. - Raise an exception and return -1 on overflow, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts); - -/* Convert a timestamp to a timespec structure (nanosecond resolution). - tv_nsec is always positive. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts); -#endif - -/* Compute ticks * mul / div. - The caller must ensure that ((div - 1) * mul) cannot overflow. */ -PyAPI_FUNC(_PyTime_t) _PyTime_MulDiv(_PyTime_t ticks, - _PyTime_t mul, - _PyTime_t div); - -/* Structure used by time.get_clock_info() */ -typedef struct { - const char *implementation; - int monotonic; - int adjustable; - double resolution; -} _Py_clock_info_t; - -/* Get the current time from the system clock. - - If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to - _PyTime_MIN or _PyTime_MAX. - - Use _PyTime_GetSystemClockWithInfo() to check for failure. */ -PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void); - -/* Get the current time from the system clock. - * On success, set *t and *info (if not NULL), and return 0. - * On error, raise an exception and return -1. - */ -PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( - _PyTime_t *t, - _Py_clock_info_t *info); - -/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. - The clock is not affected by system clock updates. The reference point of - the returned value is undefined, so that only the difference between the - results of consecutive calls is valid. - - If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to - _PyTime_MIN or _PyTime_MAX. - - Use _PyTime_GetMonotonicClockWithInfo() to check for failure. */ -PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); - -/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. - The clock is not affected by system clock updates. The reference point of - the returned value is undefined, so that only the difference between the - results of consecutive calls is valid. - - Fill info (if set) with information of the function used to get the time. - - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo( - _PyTime_t *t, - _Py_clock_info_t *info); - - -/* Converts a timestamp to the Gregorian time, using the local time zone. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm); - -/* Converts a timestamp to the Gregorian time, assuming UTC. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); - -/* Get the performance counter: clock with the highest available resolution to - measure a short duration. - - If the internal clock fails, silently ignore the error and return 0. - On integer overflow, silently ignore the overflow and truncated the clock to - _PyTime_MIN or _PyTime_MAX. - - Use _PyTime_GetPerfCounterWithInfo() to check for failure. */ -PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void); - -/* Get the performance counter: clock with the highest available resolution to - measure a short duration. +#ifndef Py_LIMITED_API - Fill info (if set) with information of the function used to get the time. +#include "pyconfig.h" /* include for defines */ +#include "object.h" - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_GetPerfCounterWithInfo( - _PyTime_t *t, - _Py_clock_info_t *info); +# define Py_CPYTHON_PYTIME_H +# include "cpython/pytime.h" +# undef Py_CPYTHON_PYTIME_H +#endif /* Py_LIMITED_API */ #ifdef __cplusplus } #endif #endif /* Py_PYTIME_H */ -#endif /* Py_LIMITED_API */ diff --git a/Makefile.pre.in b/Makefile.pre.in index 5c93b0b3fa9c60..8f7fa7f2473b77 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1103,6 +1103,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/pymem.h \ $(srcdir)/Include/cpython/pystate.h \ $(srcdir)/Include/cpython/pythonrun.h \ + $(srcdir)/Include/cpython/pytime.h \ $(srcdir)/Include/cpython/sysmodule.h \ $(srcdir)/Include/cpython/traceback.h \ $(srcdir)/Include/cpython/tupleobject.h \ diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index fd27dea9daec71..dedf6dfcb7db3b 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -147,6 +147,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 75a653dcbdab29..210a4ceb39e606 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -447,6 +447,9 @@ Include\cpython + + Include\cpython + Include\cpython From c6233c69d4c55f018c8290a859c2b1055b7fe8d5 Mon Sep 17 00:00:00 2001 From: Nicholas Sim Date: Sat, 13 Feb 2021 16:18:07 +0800 Subject: [PATCH 2/5] remove Include/pytime.h Address review; replaced by Include/cpython/pytime.h --- Include/Python.h | 2 +- Include/cpython/pytime.h | 29 ++++++++++++++++------------- Include/pytime.h | 22 ---------------------- Makefile.pre.in | 1 - Modules/gcmodule.c | 2 +- PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythoncore.vcxproj.filters | 3 --- 7 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 Include/pytime.h diff --git a/Include/Python.h b/Include/Python.h index 57f71d41d8d477..e818a0873029ba 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -82,7 +82,7 @@ #error "PYMALLOC_DEBUG requires WITH_PYMALLOC" #endif #include "pymath.h" -#include "pytime.h" +#include "cpython/pytime.h" #include "pymem.h" #include "object.h" diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h index 800c719910fed0..25b45225312389 100644 --- a/Include/cpython/pytime.h +++ b/Include/cpython/pytime.h @@ -1,11 +1,17 @@ -#ifndef Py_CPYTHON_PYTIME_H -# error "this header file must not be included directly" -#endif +#ifndef Py_LIMITED_API +#ifndef Py_PYTIME_H +#define Py_PYTIME_H + +#include "../pyconfig.h" /* include for defines */ +#include "../object.h" /************************************************************************** Symbols and macros to supply platform-independent interfaces to time related functions and constants **************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif /* _PyTime_t: Python timestamp with subsecond precision. It can be used to store a duration, and so indirectly a date (related to another date, like @@ -167,11 +173,9 @@ typedef struct { } _Py_clock_info_t; /* Get the current time from the system clock. - If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. - Use _PyTime_GetSystemClockWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void); @@ -187,11 +191,9 @@ PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid. - If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. - Use _PyTime_GetMonotonicClockWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); @@ -199,9 +201,7 @@ PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid. - Fill info (if set) with information of the function used to get the time. - Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo( _PyTime_t *t, @@ -218,20 +218,23 @@ PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); /* Get the performance counter: clock with the highest available resolution to measure a short duration. - If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. - Use _PyTime_GetPerfCounterWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void); /* Get the performance counter: clock with the highest available resolution to measure a short duration. - Fill info (if set) with information of the function used to get the time. - Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_GetPerfCounterWithInfo( _PyTime_t *t, _Py_clock_info_t *info); + +#ifdef __cplusplus +} +#endif + +#endif /* Py_PYTIME_H */ +#endif /* Py_LIMITED_API */ diff --git a/Include/pytime.h b/Include/pytime.h deleted file mode 100644 index f11424a1760edf..00000000000000 --- a/Include/pytime.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef Py_PYTIME_H -#define Py_PYTIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_LIMITED_API - -#include "pyconfig.h" /* include for defines */ -#include "object.h" - -# define Py_CPYTHON_PYTIME_H -# include "cpython/pytime.h" -# undef Py_CPYTHON_PYTIME_H -#endif /* Py_LIMITED_API */ - -#ifdef __cplusplus -} -#endif - -#endif /* Py_PYTIME_H */ diff --git a/Makefile.pre.in b/Makefile.pre.in index 8f7fa7f2473b77..144824eb040192 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1062,7 +1062,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/pystrtod.h \ $(srcdir)/Include/pythonrun.h \ $(srcdir)/Include/pythread.h \ - $(srcdir)/Include/pytime.h \ $(srcdir)/Include/rangeobject.h \ $(srcdir)/Include/setobject.h \ $(srcdir)/Include/sliceobject.h \ diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index fdbba6a7afc29d..d0025b6e570e49 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -31,7 +31,7 @@ #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "pydtrace.h" -#include "pytime.h" // _PyTime_GetMonotonicClock() +#include "cpython/pytime.h" // _PyTime_GetMonotonicClock() typedef struct _gc_runtime_state GCState; diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index dedf6dfcb7db3b..bfca4bbae9f3e0 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -246,7 +246,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 210a4ceb39e606..1505a4779b391a 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -204,9 +204,6 @@ Include - - Include - Include From aa97ca2d05b4b00598eee42f3313e6c4254835ee Mon Sep 17 00:00:00 2001 From: Nicholas Sim Date: Sat, 13 Feb 2021 21:28:27 +0800 Subject: [PATCH 3/5] remove bad pyconfig include --- Include/cpython/pytime.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h index 25b45225312389..8bffcfeadaa49c 100644 --- a/Include/cpython/pytime.h +++ b/Include/cpython/pytime.h @@ -2,7 +2,6 @@ #ifndef Py_PYTIME_H #define Py_PYTIME_H -#include "../pyconfig.h" /* include for defines */ #include "../object.h" /************************************************************************** From 1c0f8ad3ffee4fac39900208c73deea70f31e179 Mon Sep 17 00:00:00 2001 From: Nicholas Sim Date: Sat, 13 Feb 2021 21:29:01 +0800 Subject: [PATCH 4/5] restore some accidentally-deleted whitespace --- Include/cpython/pytime.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h index 8bffcfeadaa49c..e9243a78bc98a4 100644 --- a/Include/cpython/pytime.h +++ b/Include/cpython/pytime.h @@ -172,9 +172,11 @@ typedef struct { } _Py_clock_info_t; /* Get the current time from the system clock. + If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. + Use _PyTime_GetSystemClockWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void); @@ -190,9 +192,11 @@ PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid. + If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. + Use _PyTime_GetMonotonicClockWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); @@ -200,7 +204,9 @@ PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid. + Fill info (if set) with information of the function used to get the time. + Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo( _PyTime_t *t, @@ -217,15 +223,19 @@ PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); /* Get the performance counter: clock with the highest available resolution to measure a short duration. + If the internal clock fails, silently ignore the error and return 0. On integer overflow, silently ignore the overflow and truncated the clock to _PyTime_MIN or _PyTime_MAX. + Use _PyTime_GetPerfCounterWithInfo() to check for failure. */ PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void); /* Get the performance counter: clock with the highest available resolution to measure a short duration. + Fill info (if set) with information of the function used to get the time. + Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_GetPerfCounterWithInfo( _PyTime_t *t, From 3116f44fc79c0631b1e7553bac9b695193f4cc2a Mon Sep 17 00:00:00 2001 From: Nicholas Sim Date: Tue, 16 Feb 2021 18:36:57 +0800 Subject: [PATCH 5/5] pytime.h: remove includes --- Include/Python.h | 2 +- Include/cpython/pytime.h | 2 -- Modules/gcmodule.c | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Include/Python.h b/Include/Python.h index e818a0873029ba..76ead9e5765ec8 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -82,7 +82,6 @@ #error "PYMALLOC_DEBUG requires WITH_PYMALLOC" #endif #include "pymath.h" -#include "cpython/pytime.h" #include "pymem.h" #include "object.h" @@ -128,6 +127,7 @@ #include "structseq.h" #include "namespaceobject.h" #include "picklebufobject.h" +#include "cpython/pytime.h" #include "codecs.h" #include "pyerrors.h" diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h index e9243a78bc98a4..56607d199ed542 100644 --- a/Include/cpython/pytime.h +++ b/Include/cpython/pytime.h @@ -2,8 +2,6 @@ #ifndef Py_PYTIME_H #define Py_PYTIME_H -#include "../object.h" - /************************************************************************** Symbols and macros to supply platform-independent interfaces to time related functions and constants diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index d0025b6e570e49..f0d56994908233 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -31,7 +31,6 @@ #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "pydtrace.h" -#include "cpython/pytime.h" // _PyTime_GetMonotonicClock() typedef struct _gc_runtime_state GCState;