Skip to content

Commit e26a2ad

Browse files
vstinnerLukasWoodtli
authored andcommitted
pythongh-110850: Rename internal PyTime C API functions (python#115734)
Rename functions: * _PyTime_GetSystemClock() => _PyTime_TimeUnchecked() * _PyTime_GetPerfCounter() => _PyTime_PerfCounterUnchecked() * _PyTime_GetMonotonicClock() => _PyTime_MonotonicUnchecked() * _PyTime_GetSystemClockWithInfo() => _PyTime_TimeWithInfo() * _PyTime_GetMonotonicClockWithInfo() => _PyTime_MonotonicWithInfo() * _PyTime_GetMonotonicClockWithInfo() => _PyTime_MonotonicWithInfo() Changes: * Remove "typedef PyTime_t PyTime_t;" which was "typedef PyTime_t _PyTime_t;" before a previous rename. * Update comments of "Unchecked" functions. * Remove invalid PyTime_Time() comment.
1 parent b058ec0 commit e26a2ad

File tree

16 files changed

+68
-83
lines changed

16 files changed

+68
-83
lines changed

Include/internal/pycore_time.h

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ extern "C" {
6262
struct timeval;
6363
#endif
6464

65-
typedef PyTime_t PyTime_t;
6665
#define _SIZEOF_PYTIME_T 8
6766

6867
typedef enum {
@@ -253,37 +252,28 @@ typedef struct {
253252
double resolution;
254253
} _Py_clock_info_t;
255254

256-
// Get the current time from the system clock.
257-
//
258-
// If the internal clock fails, silently ignore the error and return 0.
259-
// On integer overflow, silently ignore the overflow and clamp the clock to
260-
// [_PyTime_MIN; _PyTime_MAX].
255+
// Similar to PyTime_Time() but silently ignore the error and return 0 if the
256+
// internal clock fails.
261257
//
262-
// Use _PyTime_GetSystemClockWithInfo or the public PyTime_Time() to check
258+
// Use _PyTime_TimeWithInfo() or the public PyTime_Time() to check
263259
// for failure.
264260
// Export for '_random' shared extension.
265-
PyAPI_FUNC(PyTime_t) _PyTime_GetSystemClock(void);
261+
PyAPI_FUNC(PyTime_t) _PyTime_TimeUnchecked(void);
266262

267263
// Get the current time from the system clock.
268264
// On success, set *t and *info (if not NULL), and return 0.
269265
// On error, raise an exception and return -1.
270-
extern int _PyTime_GetSystemClockWithInfo(
266+
extern int _PyTime_TimeWithInfo(
271267
PyTime_t *t,
272268
_Py_clock_info_t *info);
273269

274-
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
275-
// The clock is not affected by system clock updates. The reference point of
276-
// the returned value is undefined, so that only the difference between the
277-
// results of consecutive calls is valid.
270+
// Similar to PyTime_Monotonic() but silently ignore the error and return 0 if
271+
// the internal clock fails.
278272
//
279-
// If the internal clock fails, silently ignore the error and return 0.
280-
// On integer overflow, silently ignore the overflow and clamp the clock to
281-
// [_PyTime_MIN; _PyTime_MAX].
282-
//
283-
// Use _PyTime_GetMonotonicClockWithInfo or the public PyTime_Monotonic()
273+
// Use _PyTime_MonotonicWithInfo() or the public PyTime_Monotonic()
284274
// to check for failure.
285275
// Export for '_random' shared extension.
286-
PyAPI_FUNC(PyTime_t) _PyTime_GetMonotonicClock(void);
276+
PyAPI_FUNC(PyTime_t) _PyTime_MonotonicUnchecked(void);
287277

288278
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
289279
// The clock is not affected by system clock updates. The reference point of
@@ -294,7 +284,7 @@ PyAPI_FUNC(PyTime_t) _PyTime_GetMonotonicClock(void);
294284
//
295285
// Return 0 on success, raise an exception and return -1 on error.
296286
// Export for '_testsinglephase' shared extension.
297-
PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
287+
PyAPI_FUNC(int) _PyTime_MonotonicWithInfo(
298288
PyTime_t *t,
299289
_Py_clock_info_t *info);
300290

@@ -309,17 +299,13 @@ PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm);
309299
// Export for '_datetime' shared extension.
310300
PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
311301

312-
// Get the performance counter: clock with the highest available resolution to
313-
// measure a short duration.
302+
// Similar to PyTime_PerfCounter() but silently ignore the error and return 0
303+
// if the internal clock fails.
314304
//
315-
// If the internal clock fails, silently ignore the error and return 0.
316-
// On integer overflow, silently ignore the overflow and clamp the clock to
317-
// [_PyTime_MIN; _PyTime_MAX].
318-
//
319-
// Use _PyTime_GetPerfCounterWithInfo() or the public PyTime_PerfCounter
320-
// to check for failure.
305+
// Use _PyTime_PerfCounterWithInfo() or the public PyTime_PerfCounter() to
306+
// check for failure.
321307
// Export for '_lsprof' shared extension.
322-
PyAPI_FUNC(PyTime_t) _PyTime_GetPerfCounter(void);
308+
PyAPI_FUNC(PyTime_t) _PyTime_PerfCounterUnchecked(void);
323309

324310

325311
// Get the performance counter: clock with the highest available resolution to
@@ -328,7 +314,7 @@ PyAPI_FUNC(PyTime_t) _PyTime_GetPerfCounter(void);
328314
// Fill info (if set) with information of the function used to get the time.
329315
//
330316
// Return 0 on success, raise an exception and return -1 on error.
331-
extern int _PyTime_GetPerfCounterWithInfo(
317+
extern int _PyTime_PerfCounterWithInfo(
332318
PyTime_t *t,
333319
_Py_clock_info_t *info);
334320

@@ -341,12 +327,12 @@ extern int _PyTime_GetPerfCounterWithInfo(
341327
// --- _PyDeadline -----------------------------------------------------------
342328

343329
// Create a deadline.
344-
// Pseudo code: _PyTime_GetMonotonicClock() + timeout.
330+
// Pseudo code: _PyTime_MonotonicUnchecked() + timeout.
345331
// Export for '_ssl' shared extension.
346332
PyAPI_FUNC(PyTime_t) _PyDeadline_Init(PyTime_t timeout);
347333

348334
// Get remaining time from a deadline.
349-
// Pseudo code: deadline - _PyTime_GetMonotonicClock().
335+
// Pseudo code: deadline - _PyTime_MonotonicUnchecked().
350336
// Export for '_ssl' shared extension.
351337
PyAPI_FUNC(PyTime_t) _PyDeadline_Get(PyTime_t deadline);
352338

Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5133,7 +5133,7 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp,
51335133
static PyObject *
51345134
datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
51355135
{
5136-
PyTime_t ts = _PyTime_GetSystemClock();
5136+
PyTime_t ts = _PyTime_TimeUnchecked();
51375137
time_t secs;
51385138
int us;
51395139

Modules/_lsprof.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ call_timer(ProfilerObject *pObj)
121121
return CallExternalTimer(pObj);
122122
}
123123
else {
124-
return _PyTime_GetPerfCounter();
124+
return _PyTime_PerfCounterUnchecked();
125125
}
126126
}
127127

Modules/_randommodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
7676
#include "pycore_moduleobject.h" // _PyModule_GetState()
7777
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
78-
#include "pycore_time.h" // _PyTime_GetSystemClock()
78+
#include "pycore_time.h" // _PyTime_TimeUnchecked()
7979

8080
#ifdef HAVE_UNISTD_H
8181
# include <unistd.h> // getpid()
@@ -266,7 +266,7 @@ random_seed_time_pid(RandomObject *self)
266266
PyTime_t now;
267267
uint32_t key[5];
268268

269-
now = _PyTime_GetSystemClock();
269+
now = _PyTime_TimeUnchecked();
270270
key[0] = (uint32_t)(now & 0xffffffffU);
271271
key[1] = (uint32_t)(now >> 32);
272272

@@ -278,7 +278,7 @@ random_seed_time_pid(RandomObject *self)
278278
key[2] = 0;
279279
#endif
280280

281-
now = _PyTime_GetMonotonicClock();
281+
now = _PyTime_MonotonicUnchecked();
282282
key[3] = (uint32_t)(now & 0xffffffffU);
283283
key[4] = (uint32_t)(now >> 32);
284284

Modules/_testinternalcapi/test_lock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "parts.h"
44
#include "pycore_lock.h"
5-
#include "pycore_time.h" // _PyTime_GetMonotonicClock()
5+
#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
66

77
#include "clinic/test_lock.c.h"
88

@@ -290,7 +290,7 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
290290
goto exit;
291291
}
292292

293-
PyTime_t start = _PyTime_GetMonotonicClock();
293+
PyTime_t start = _PyTime_MonotonicUnchecked();
294294

295295
for (Py_ssize_t i = 0; i < num_threads; i++) {
296296
thread_data[i].bench_data = &bench_data;
@@ -307,7 +307,7 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
307307
}
308308

309309
Py_ssize_t total_iters = bench_data.total_iters;
310-
PyTime_t end = _PyTime_GetMonotonicClock();
310+
PyTime_t end = _PyTime_MonotonicUnchecked();
311311

312312
// Return the total number of acquisitions and the number of acquisitions
313313
// for each thread.

Modules/_testsinglephase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ _set_initialized(PyTime_t *initialized)
7171
{
7272
/* We go strictly monotonic to ensure each time is unique. */
7373
PyTime_t prev;
74-
if (_PyTime_GetMonotonicClockWithInfo(&prev, NULL) != 0) {
74+
if (_PyTime_MonotonicWithInfo(&prev, NULL) != 0) {
7575
return -1;
7676
}
7777
/* We do a busy sleep since the interval should be super short. */
7878
PyTime_t t;
7979
do {
80-
if (_PyTime_GetMonotonicClockWithInfo(&t, NULL) != 0) {
80+
if (_PyTime_MonotonicWithInfo(&t, NULL) != 0) {
8181
return -1;
8282
}
8383
} while (t == prev);

Modules/timemodule.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ _PyFloat_FromPyTime(PyTime_t t)
106106
static int
107107
get_system_time(PyTime_t *t)
108108
{
109-
// Avoid _PyTime_GetSystemClock() which silently ignores errors.
110-
return _PyTime_GetSystemClockWithInfo(t, NULL);
109+
// Avoid _PyTime_TimeUnchecked() which silently ignores errors.
110+
return _PyTime_TimeWithInfo(t, NULL);
111111
}
112112

113113

@@ -1159,8 +1159,8 @@ should not be relied on.");
11591159
static int
11601160
get_monotonic(PyTime_t *t)
11611161
{
1162-
// Avoid _PyTime_GetMonotonicClock() which silently ignores errors.
1163-
return _PyTime_GetMonotonicClockWithInfo(t, NULL);
1162+
// Avoid _PyTime_MonotonicUnchecked() which silently ignores errors.
1163+
return _PyTime_MonotonicWithInfo(t, NULL);
11641164
}
11651165

11661166

@@ -1198,8 +1198,8 @@ Monotonic clock, cannot go backward, as nanoseconds.");
11981198
static int
11991199
get_perf_counter(PyTime_t *t)
12001200
{
1201-
// Avoid _PyTime_GetPerfCounter() which silently ignores errors.
1202-
return _PyTime_GetPerfCounterWithInfo(t, NULL);
1201+
// Avoid _PyTime_PerfCounterUnchecked() which silently ignores errors.
1202+
return _PyTime_PerfCounterWithInfo(t, NULL);
12031203
}
12041204

12051205

@@ -1615,17 +1615,17 @@ time_get_clock_info(PyObject *module, PyObject *args)
16151615
#endif
16161616

16171617
if (strcmp(name, "time") == 0) {
1618-
if (_PyTime_GetSystemClockWithInfo(&t, &info) < 0) {
1618+
if (_PyTime_TimeWithInfo(&t, &info) < 0) {
16191619
return NULL;
16201620
}
16211621
}
16221622
else if (strcmp(name, "monotonic") == 0) {
1623-
if (_PyTime_GetMonotonicClockWithInfo(&t, &info) < 0) {
1623+
if (_PyTime_MonotonicWithInfo(&t, &info) < 0) {
16241624
return NULL;
16251625
}
16261626
}
16271627
else if (strcmp(name, "perf_counter") == 0) {
1628-
if (_PyTime_GetPerfCounterWithInfo(&t, &info) < 0) {
1628+
if (_PyTime_PerfCounterWithInfo(&t, &info) < 0) {
16291629
return NULL;
16301630
}
16311631
}

Python/gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "pycore_object_alloc.h" // _PyObject_MallocWithType()
1313
#include "pycore_pyerrors.h"
1414
#include "pycore_pystate.h" // _PyThreadState_GET()
15-
#include "pycore_time.h" // _PyTime_GetPerfCounter()
15+
#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
1616
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
1717
#include "pydtrace.h"
1818

@@ -1327,7 +1327,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
13271327
if (gcstate->debug & _PyGC_DEBUG_STATS) {
13281328
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
13291329
show_stats_each_generations(gcstate);
1330-
t1 = _PyTime_GetPerfCounter();
1330+
t1 = _PyTime_PerfCounterUnchecked();
13311331
}
13321332

13331333
if (PyDTrace_GC_START_ENABLED()) {
@@ -1428,7 +1428,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
14281428
debug_cycle("uncollectable", FROM_GC(gc));
14291429
}
14301430
if (gcstate->debug & _PyGC_DEBUG_STATS) {
1431-
double d = _PyTime_AsSecondsDouble(_PyTime_GetPerfCounter() - t1);
1431+
double d = _PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
14321432
PySys_WriteStderr(
14331433
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
14341434
n+m, n, d);

Python/gc_free_threading.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11081108
if (gcstate->debug & _PyGC_DEBUG_STATS) {
11091109
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
11101110
show_stats_each_generations(gcstate);
1111-
t1 = _PyTime_GetPerfCounter();
1111+
t1 = _PyTime_PerfCounterUnchecked();
11121112
}
11131113

11141114
if (PyDTrace_GC_START_ENABLED()) {
@@ -1136,7 +1136,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11361136
n = state.uncollectable;
11371137

11381138
if (gcstate->debug & _PyGC_DEBUG_STATS) {
1139-
double d = _PyTime_AsSecondsDouble(_PyTime_GetPerfCounter() - t1);
1139+
double d = _PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
11401140
PySys_WriteStderr(
11411141
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
11421142
n+m, n, d);

Python/import.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
1414
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1515
#include "pycore_sysmodule.h" // _PySys_Audit()
16-
#include "pycore_time.h" // _PyTime_GetPerfCounter()
16+
#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
1717
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
1818

1919
#include "marshal.h" // PyMarshal_ReadObjectFromString()
@@ -2748,7 +2748,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
27482748
#undef header
27492749

27502750
import_level++;
2751-
t1 = _PyTime_GetPerfCounter();
2751+
t1 = _PyTime_PerfCounterUnchecked();
27522752
accumulated = 0;
27532753
}
27542754

@@ -2763,7 +2763,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
27632763
mod != NULL);
27642764

27652765
if (import_time) {
2766-
PyTime_t cum = _PyTime_GetPerfCounter() - t1;
2766+
PyTime_t cum = _PyTime_PerfCounterUnchecked() - t1;
27672767

27682768
import_level--;
27692769
fprintf(stderr, "import time: %9ld | %10ld | %*s%s\n",

Python/lock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "pycore_lock.h"
66
#include "pycore_parking_lot.h"
77
#include "pycore_semaphore.h"
8-
#include "pycore_time.h" // _PyTime_GetMonotonicClock()
8+
#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
99

1010
#ifdef MS_WINDOWS
1111
# define WIN32_LEAN_AND_MEAN
@@ -66,7 +66,7 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
6666
return PY_LOCK_FAILURE;
6767
}
6868

69-
PyTime_t now = _PyTime_GetMonotonicClock();
69+
PyTime_t now = _PyTime_MonotonicUnchecked();
7070
PyTime_t endtime = 0;
7171
if (timeout > 0) {
7272
endtime = _PyTime_Add(now, timeout);
@@ -143,7 +143,7 @@ mutex_unpark(PyMutex *m, struct mutex_entry *entry, int has_more_waiters)
143143
{
144144
uint8_t v = 0;
145145
if (entry) {
146-
PyTime_t now = _PyTime_GetMonotonicClock();
146+
PyTime_t now = _PyTime_MonotonicUnchecked();
147147
int should_be_fair = now > entry->time_to_be_fair;
148148

149149
entry->handed_off = should_be_fair;

Python/parking_lot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat
77
#include "pycore_pystate.h" // _PyThreadState_GET
88
#include "pycore_semaphore.h" // _PySemaphore
9-
#include "pycore_time.h" //_PyTime_GetMonotonicClock()
9+
#include "pycore_time.h" //_PyTime_MonotonicUnchecked()
1010

1111
#include <stdbool.h>
1212

@@ -120,13 +120,13 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
120120
struct timespec ts;
121121

122122
#if defined(CLOCK_MONOTONIC) && defined(HAVE_SEM_CLOCKWAIT)
123-
PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
123+
PyTime_t deadline = _PyTime_Add(_PyTime_MonotonicUnchecked(), timeout);
124124

125125
_PyTime_AsTimespec_clamp(deadline, &ts);
126126

127127
err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts);
128128
#else
129-
PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
129+
PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
130130

131131
_PyTime_AsTimespec_clamp(deadline, &ts);
132132

@@ -163,7 +163,7 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
163163
_PyTime_AsTimespec_clamp(timeout, &ts);
164164
err = pthread_cond_timedwait_relative_np(&sema->cond, &sema->mutex, &ts);
165165
#else
166-
PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
166+
PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
167167
_PyTime_AsTimespec_clamp(deadline, &ts);
168168

169169
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);

0 commit comments

Comments
 (0)