Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110850: Replace _PyTime_t with PyTime_t #115719

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {

#include "pycore_lock.h" // PyMutex
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_time.h" // _PyTime_t
#include "pycore_time.h" // PyTime_t

extern int _PyImport_IsInitialized(PyInterpreterState *);

Expand Down Expand Up @@ -103,7 +103,7 @@ struct _import_state {
/* diagnostic info in PyImport_ImportModuleLevelObject() */
struct {
int import_level;
_PyTime_t accumulated;
PyTime_t accumulated;
int header;
} find_and_load;
};
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_time.h" // _PyTime_t
#include "pycore_time.h" // PyTime_t


// A mutex that occupies one byte. The lock can be zero initialized.
Expand Down Expand Up @@ -113,7 +113,7 @@ typedef enum _PyLockFlags {
// Lock a mutex with an optional timeout and additional options. See
// _PyLockFlags for details.
extern PyLockStatus
_PyMutex_LockTimed(PyMutex *m, _PyTime_t timeout_ns, _PyLockFlags flags);
_PyMutex_LockTimed(PyMutex *m, PyTime_t timeout_ns, _PyLockFlags flags);

// Lock a mutex with aditional options. See _PyLockFlags for details.
static inline void
Expand Down Expand Up @@ -146,7 +146,7 @@ PyAPI_FUNC(void) PyEvent_Wait(PyEvent *evt);
// Wait for the event to be set, or until the timeout expires. If the event is
// already set, then this returns immediately. Returns 1 if the event was set,
// and 0 if the timeout expired or thread was interrupted.
PyAPI_FUNC(int) PyEvent_WaitTimed(PyEvent *evt, _PyTime_t timeout_ns);
PyAPI_FUNC(int) PyEvent_WaitTimed(PyEvent *evt, PyTime_t timeout_ns);


// _PyRawMutex implements a word-sized mutex that that does not depend on the
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_parking_lot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_time.h" // _PyTime_t
#include "pycore_time.h" // PyTime_t


enum {
Expand Down Expand Up @@ -61,7 +61,7 @@ enum {
// }
PyAPI_FUNC(int)
_PyParkingLot_Park(const void *address, const void *expected,
size_t address_size, _PyTime_t timeout_ns,
size_t address_size, PyTime_t timeout_ns,
void *park_arg, int detach);

// Callback for _PyParkingLot_Unpark:
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extern void _PyThread_AfterFork(struct _pythread_runtime_state *state);


// unset: -1 seconds, in nanoseconds
#define PyThread_UNSET_TIMEOUT ((_PyTime_t)(-1 * 1000 * 1000 * 1000))
#define PyThread_UNSET_TIMEOUT ((PyTime_t)(-1 * 1000 * 1000 * 1000))

// Exported for the _xxinterpchannels module.
PyAPI_FUNC(int) PyThread_ParseTimeoutArg(
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

#include "pycore_pythread.h" // _POSIX_SEMAPHORES
#include "pycore_time.h" // _PyTime_t
#include "pycore_time.h" // PyTime_t

#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -48,7 +48,7 @@ typedef struct _PySemaphore {
// If `detach` is true, then the thread will detach/release the GIL while
// sleeping.
PyAPI_FUNC(int)
_PySemaphore_Wait(_PySemaphore *sema, _PyTime_t timeout_ns, int detach);
_PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout_ns, int detach);

// Wakes up a single thread waiting on sema. Note that _PySemaphore_Wakeup()
// can be called before _PySemaphore_Wait().
Expand Down
74 changes: 37 additions & 37 deletions Include/internal/pycore_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern "C" {
struct timeval;
#endif

typedef PyTime_t _PyTime_t;
typedef PyTime_t PyTime_t;
#define _SIZEOF_PYTIME_T 8

typedef enum {
Expand Down Expand Up @@ -130,84 +130,84 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(

// Create a timestamp from a number of seconds.
// Export for '_socket' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
PyAPI_FUNC(PyTime_t) _PyTime_FromSeconds(int seconds);

// Create a timestamp from a number of seconds in double.
// Export for '_socket' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round);
PyAPI_FUNC(PyTime_t) _PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round);

// 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))
((PyTime_t)(seconds) * (1000 * 1000 * 1000))

// Create a timestamp from a number of nanoseconds.
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns);
PyAPI_FUNC(PyTime_t) _PyTime_FromNanoseconds(PyTime_t ns);

// Create a timestamp from a number of microseconds.
// Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
extern _PyTime_t _PyTime_FromMicrosecondsClamp(_PyTime_t us);
extern PyTime_t _PyTime_FromMicrosecondsClamp(PyTime_t us);

// Create a timestamp from nanoseconds (Python int).
// Export for '_lsprof' shared extension.
PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t,
PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(PyTime_t *t,
PyObject *obj);

// Convert a number of seconds (Python float or int) to a timestamp.
// Raise an exception and return -1 on error, return 0 on success.
// Export for '_socket' shared extension.
PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t,
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 timestamp.
// Raise an exception and return -1 on error, return 0 on success.
// Export for 'select' shared extension.
PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t,
PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(PyTime_t *t,
PyObject *obj,
_PyTime_round_t round);

// Convert timestamp to a number of milliseconds (10^-3 seconds).
// Export for '_ssl' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_AsMilliseconds(_PyTime_t t,
PyAPI_FUNC(PyTime_t) _PyTime_AsMilliseconds(PyTime_t t,
_PyTime_round_t round);

// Convert timestamp to a number of microseconds (10^-6 seconds).
// Export for '_queue' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_AsMicroseconds(_PyTime_t t,
PyAPI_FUNC(PyTime_t) _PyTime_AsMicroseconds(PyTime_t t,
_PyTime_round_t round);

#ifdef MS_WINDOWS
// Convert timestamp to a number of 100 nanoseconds (10^-7 seconds).
extern _PyTime_t _PyTime_As100Nanoseconds(_PyTime_t t,
extern PyTime_t _PyTime_As100Nanoseconds(PyTime_t t,
_PyTime_round_t round);
#endif

// Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int
// object.
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(PyObject*) _PyTime_AsNanosecondsObject(_PyTime_t t);
PyAPI_FUNC(PyObject*) _PyTime_AsNanosecondsObject(PyTime_t t);

#ifndef MS_WINDOWS
// Create a timestamp from a timeval structure.
// Raise an exception and return -1 on overflow, return 0 on success.
extern int _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
extern int _PyTime_FromTimeval(PyTime_t *tp, struct timeval *tv);
#endif

// 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.
// Export for 'select' shared extension.
PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t,
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 overflow.
// On overflow, clamp tv_sec to _PyTime_t min/max.
// On overflow, clamp tv_sec to PyTime_t min/max.
// Export for 'select' shared extension.
PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(_PyTime_t t,
PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(PyTime_t t,
struct timeval *tv,
_PyTime_round_t round);

Expand All @@ -219,31 +219,31 @@ PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(_PyTime_t t,
// return 0 on success.
// Export for '_datetime' shared extension.
PyAPI_FUNC(int) _PyTime_AsTimevalTime_t(
_PyTime_t 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.
extern int _PyTime_FromTimespec(_PyTime_t *tp, const struct timespec *ts);
extern int _PyTime_FromTimespec(PyTime_t *tp, const 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.
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
PyAPI_FUNC(int) _PyTime_AsTimespec(PyTime_t t, struct timespec *ts);

// Similar to _PyTime_AsTimespec() but don't raise an exception on overflow.
// On overflow, clamp tv_sec to _PyTime_t min/max.
// On overflow, clamp tv_sec to PyTime_t min/max.
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(_PyTime_t t, struct timespec *ts);
PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(PyTime_t t, struct timespec *ts);
#endif


// Compute t1 + t2. Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
extern _PyTime_t _PyTime_Add(_PyTime_t t1, _PyTime_t t2);
extern PyTime_t _PyTime_Add(PyTime_t t1, PyTime_t t2);

// Structure used by time.get_clock_info()
typedef struct {
Expand All @@ -262,13 +262,13 @@ typedef struct {
// Use _PyTime_GetSystemClockWithInfo or the public PyTime_Time() to check
// for failure.
// Export for '_random' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void);
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.
extern int _PyTime_GetSystemClockWithInfo(
_PyTime_t *t,
PyTime_t *t,
_Py_clock_info_t *info);

// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
Expand All @@ -283,7 +283,7 @@ extern int _PyTime_GetSystemClockWithInfo(
// Use _PyTime_GetMonotonicClockWithInfo or the public PyTime_Monotonic()
// to check for failure.
// Export for '_random' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void);
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
Expand All @@ -295,7 +295,7 @@ PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void);
// Return 0 on success, raise an exception and return -1 on error.
// Export for '_testsinglephase' shared extension.
PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
_PyTime_t *t,
PyTime_t *t,
_Py_clock_info_t *info);


Expand All @@ -319,7 +319,7 @@ PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
// Use _PyTime_GetPerfCounterWithInfo() or the public PyTime_PerfCounter
// to check for failure.
// Export for '_lsprof' shared extension.
PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void);
PyAPI_FUNC(PyTime_t) _PyTime_GetPerfCounter(void);


// Get the performance counter: clock with the highest available resolution to
Expand All @@ -329,7 +329,7 @@ PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void);
//
// Return 0 on success, raise an exception and return -1 on error.
extern int _PyTime_GetPerfCounterWithInfo(
_PyTime_t *t,
PyTime_t *t,
_Py_clock_info_t *info);

// Alias for backward compatibility
Expand All @@ -343,33 +343,33 @@ extern int _PyTime_GetPerfCounterWithInfo(
// Create a deadline.
// Pseudo code: _PyTime_GetMonotonicClock() + timeout.
// Export for '_ssl' shared extension.
PyAPI_FUNC(_PyTime_t) _PyDeadline_Init(_PyTime_t timeout);
PyAPI_FUNC(PyTime_t) _PyDeadline_Init(PyTime_t timeout);

// Get remaining time from a deadline.
// Pseudo code: deadline - _PyTime_GetMonotonicClock().
// Export for '_ssl' shared extension.
PyAPI_FUNC(_PyTime_t) _PyDeadline_Get(_PyTime_t deadline);
PyAPI_FUNC(PyTime_t) _PyDeadline_Get(PyTime_t deadline);


// --- _PyTimeFraction -------------------------------------------------------

typedef struct {
_PyTime_t numer;
_PyTime_t denom;
PyTime_t numer;
PyTime_t denom;
} _PyTimeFraction;

// Set a fraction.
// Return 0 on success.
// Return -1 if the fraction is invalid.
extern int _PyTimeFraction_Set(
_PyTimeFraction *frac,
_PyTime_t numer,
_PyTime_t denom);
PyTime_t numer,
PyTime_t denom);

// Compute ticks * frac.numer / frac.denom.
// Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow.
extern _PyTime_t _PyTimeFraction_Mul(
_PyTime_t ticks,
extern PyTime_t _PyTimeFraction_Mul(
PyTime_t ticks,
const _PyTimeFraction *frac);

// Compute a clock resolution: frac.numer / frac.denom / 1e9.
Expand Down
2 changes: 1 addition & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5131,7 +5131,7 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp,
static PyObject *
datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
{
_PyTime_t ts = _PyTime_GetSystemClock();
PyTime_t ts = _PyTime_GetSystemClock();
time_t secs;
int us;

Expand Down
Loading
Loading