gh-110850: Rename internal PyTime C API functions (#115734) · python/cpython@52d1477 · GitHub
Skip to content

Commit 52d1477

Browse files
authored
gh-110850: Rename internal PyTime C API functions (#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 e1fdc3c commit 52d1477

16 files changed

Lines changed: 68 additions & 83 deletions

File tree

Include/internal/pycore_time.h

Lines changed: 18 additions & 32 deletions

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

0 commit comments

Comments
 (0)