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.
This commit is contained in:
Victor Stinner 2024-02-20 23:16:37 +01:00 • committed by GitHub
parent e1fdc3c323
commit 52d1477566
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 68 additions and 83 deletions

View file

@ -5133,7 +5133,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_TimeUnchecked();
time_t secs;
int us;

View file

@ -121,7 +121,7 @@ call_timer(ProfilerObject *pObj)
return CallExternalTimer(pObj);
}
else {
return _PyTime_GetPerfCounter();
return _PyTime_PerfCounterUnchecked();
}
}

View file

@ -75,7 +75,7 @@
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
#include "pycore_time.h" // _PyTime_GetSystemClock()
#include "pycore_time.h" // _PyTime_TimeUnchecked()
#ifdef HAVE_UNISTD_H
# include <unistd.h> // getpid()
@ -266,7 +266,7 @@ random_seed_time_pid(RandomObject *self)
PyTime_t now;
uint32_t key[5];
now = _PyTime_GetSystemClock();
now = _PyTime_TimeUnchecked();
key[0] = (uint32_t)(now & 0xffffffffU);
key[1] = (uint32_t)(now >> 32);
@ -278,7 +278,7 @@ random_seed_time_pid(RandomObject *self)
key[2] = 0;
#endif
now = _PyTime_GetMonotonicClock();
now = _PyTime_MonotonicUnchecked();
key[3] = (uint32_t)(now & 0xffffffffU);
key[4] = (uint32_t)(now >> 32);

View file

@ -2,7 +2,7 @@
#include "parts.h"
#include "pycore_lock.h"
#include "pycore_time.h" // _PyTime_GetMonotonicClock()
#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
#include "clinic/test_lock.c.h"
@ -290,7 +290,7 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
goto exit;
}
PyTime_t start = _PyTime_GetMonotonicClock();
PyTime_t start = _PyTime_MonotonicUnchecked();
for (Py_ssize_t i = 0; i < num_threads; i++) {
thread_data[i].bench_data = &bench_data;
@ -307,7 +307,7 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
}
Py_ssize_t total_iters = bench_data.total_iters;
PyTime_t end = _PyTime_GetMonotonicClock();
PyTime_t end = _PyTime_MonotonicUnchecked();
// Return the total number of acquisitions and the number of acquisitions
// for each thread.

View file

@ -71,13 +71,13 @@ _set_initialized(PyTime_t *initialized)
{
/* We go strictly monotonic to ensure each time is unique. */
PyTime_t prev;
if (_PyTime_GetMonotonicClockWithInfo(&prev, NULL) != 0) {
if (_PyTime_MonotonicWithInfo(&prev, NULL) != 0) {
return -1;
}
/* We do a busy sleep since the interval should be super short. */
PyTime_t t;
do {
if (_PyTime_GetMonotonicClockWithInfo(&t, NULL) != 0) {
if (_PyTime_MonotonicWithInfo(&t, NULL) != 0) {
return -1;
}
} while (t == prev);

View file

@ -106,8 +106,8 @@ _PyFloat_FromPyTime(PyTime_t t)
static int
get_system_time(PyTime_t *t)
{
// Avoid _PyTime_GetSystemClock() which silently ignores errors.
return _PyTime_GetSystemClockWithInfo(t, NULL);
// Avoid _PyTime_TimeUnchecked() which silently ignores errors.
return _PyTime_TimeWithInfo(t, NULL);
}
@ -1159,8 +1159,8 @@ should not be relied on.");
static int
get_monotonic(PyTime_t *t)
{
// Avoid _PyTime_GetMonotonicClock() which silently ignores errors.
return _PyTime_GetMonotonicClockWithInfo(t, NULL);
// Avoid _PyTime_MonotonicUnchecked() which silently ignores errors.
return _PyTime_MonotonicWithInfo(t, NULL);
}
@ -1198,8 +1198,8 @@ Monotonic clock, cannot go backward, as nanoseconds.");
static int
get_perf_counter(PyTime_t *t)
{
// Avoid _PyTime_GetPerfCounter() which silently ignores errors.
return _PyTime_GetPerfCounterWithInfo(t, NULL);
// Avoid _PyTime_PerfCounterUnchecked() which silently ignores errors.
return _PyTime_PerfCounterWithInfo(t, NULL);
}
@ -1615,17 +1615,17 @@ time_get_clock_info(PyObject *module, PyObject *args)
#endif
if (strcmp(name, "time") == 0) {
if (_PyTime_GetSystemClockWithInfo(&t, &info) < 0) {
if (_PyTime_TimeWithInfo(&t, &info) < 0) {
return NULL;
}
}
else if (strcmp(name, "monotonic") == 0) {
if (_PyTime_GetMonotonicClockWithInfo(&t, &info) < 0) {
if (_PyTime_MonotonicWithInfo(&t, &info) < 0) {
return NULL;
}
}
else if (strcmp(name, "perf_counter") == 0) {
if (_PyTime_GetPerfCounterWithInfo(&t, &info) < 0) {
if (_PyTime_PerfCounterWithInfo(&t, &info) < 0) {
return NULL;
}
}