Replace private _PyTime functions with public PyTime functions.
random_seed_time_pid() now reports errors to its caller.
// Alias for backward compatibility
#define _PyTime_MIN PyTime_MIN
#define _PyTime_MAX PyTime_MAX
-#define _PyTime_AsSecondsDouble PyTime_AsSecondsDouble
// --- _PyDeadline -----------------------------------------------------------
static PyObject *
datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
{
- PyTime_t ts = _PyTime_TimeUnchecked();
+ PyTime_t ts;
+ if (PyTime_Time(&ts) < 0) {
+ return NULL;
+ }
+
time_t secs;
int us;
#include "pycore_ceval.h" // Py_MakePendingCalls()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_parking_lot.h"
-#include "pycore_time.h" // PyTime_t
+#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include <stdbool.h>
#include <stddef.h> // offsetof()
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
-#include "pycore_time.h" // _PyTime_TimeUnchecked()
#ifdef HAVE_UNISTD_H
# include <unistd.h> // getpid()
return 0;
}
-static void
+static int
random_seed_time_pid(RandomObject *self)
{
PyTime_t now;
- uint32_t key[5];
+ if (PyTime_Time(&now) < 0) {
+ return -1;
+ }
- now = _PyTime_TimeUnchecked();
+ uint32_t key[5];
key[0] = (uint32_t)(now & 0xffffffffU);
key[1] = (uint32_t)(now >> 32);
key[2] = 0;
#endif
- now = _PyTime_MonotonicUnchecked();
+ if (PyTime_Monotonic(&now) < 0) {
+ return -1;
+ }
key[3] = (uint32_t)(now & 0xffffffffU);
key[4] = (uint32_t)(now >> 32);
init_by_array(self, key, Py_ARRAY_LENGTH(key));
+ return 0;
}
static int
/* Reading system entropy failed, fall back on the worst entropy:
use the current time and process identifier. */
- random_seed_time_pid(self);
+ if (random_seed_time_pid(self) < 0) {
+ return -1;
+ }
}
return 0;
}
#include "parts.h"
-#include "pycore_time.h"
+#include "pycore_time.h" // _PyTime_FromSeconds()
#ifdef MS_WINDOWS
-# include <winsock2.h> // struct timeval
+# include <winsock2.h> // struct timeval
#endif
//#include <time.h>
#include "Python.h"
#include "pycore_namespace.h" // _PyNamespace_New()
-#include "pycore_time.h" // PyTime_t
typedef struct {
{
/* We go strictly monotonic to ensure each time is unique. */
PyTime_t prev;
- if (_PyTime_MonotonicWithInfo(&prev, NULL) != 0) {
+ if (PyTime_Monotonic(&prev) != 0) {
return -1;
}
/* We do a busy sleep since the interval should be super short. */
PyTime_t t;
do {
- if (_PyTime_MonotonicWithInfo(&t, NULL) != 0) {
+ if (PyTime_Monotonic(&t) != 0) {
return -1;
}
} while (t == prev);
return -1;
}
- double d = _PyTime_AsSecondsDouble(state->initialized);
+ double d = PyTime_AsSecondsDouble(state->initialized);
if (PyModule_Add(module, "_module_initialized", PyFloat_FromDouble(d)) < 0) {
return -1;
}
if (state == NULL) {
Py_RETURN_NONE;
}
- double d = _PyTime_AsSecondsDouble(state->initialized);
+ double d = PyTime_AsSecondsDouble(state->initialized);
return PyFloat_FromDouble(d);
}
// TIMEOUT_MAX
double timeout_max = (double)PY_TIMEOUT_MAX * 1e-6;
- double time_max = _PyTime_AsSecondsDouble(_PyTime_MAX);
+ double time_max = PyTime_AsSecondsDouble(_PyTime_MAX);
timeout_max = Py_MIN(timeout_max, time_max);
// Round towards minus infinity
timeout_max = floor(timeout_max);
#include "Python.h"
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_import.h" // _PyImport_GetModuleAttrString()
-#include "pycore_time.h" // PyTime_t
+#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include <stdbool.h>
#include <stddef.h> // offsetof()
Py_RETURN_NONE;
}
else {
- double seconds = _PyTime_AsSecondsDouble(s->sock_timeout);
+ double seconds = PyTime_AsSecondsDouble(s->sock_timeout);
return PyFloat_FromDouble(seconds);
}
}
Py_RETURN_NONE;
}
else {
- double seconds = _PyTime_AsSecondsDouble(state->defaulttimeout);
+ double seconds = PyTime_AsSecondsDouble(state->defaulttimeout);
return PyFloat_FromDouble(seconds);
}
}
static PyObject*
_PyFloat_FromPyTime(PyTime_t t)
{
- double d = _PyTime_AsSecondsDouble(t);
+ double d = PyTime_AsSecondsDouble(t);
return PyFloat_FromDouble(d);
}
-static int
-get_system_time(PyTime_t *t)
-{
- // Avoid _PyTime_TimeUnchecked() which silently ignores errors.
- return _PyTime_TimeWithInfo(t, NULL);
-}
-
-
static PyObject *
time_time(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_system_time(&t) < 0) {
+ if (PyTime_Time(&t) < 0) {
return NULL;
}
return _PyFloat_FromPyTime(t);
time_time_ns(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_system_time(&t) < 0) {
+ if (PyTime_Time(&t) < 0) {
return NULL;
}
return _PyTime_AsNanosecondsObject(t);
#endif /* HAVE_WORKING_TZSET */
-static int
-get_monotonic(PyTime_t *t)
-{
- // Avoid _PyTime_MonotonicUnchecked() which silently ignores errors.
- return _PyTime_MonotonicWithInfo(t, NULL);
-}
-
-
static PyObject *
time_monotonic(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_monotonic(&t) < 0) {
+ if (PyTime_Monotonic(&t) < 0) {
return NULL;
}
return _PyFloat_FromPyTime(t);
time_monotonic_ns(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_monotonic(&t) < 0) {
+ if (PyTime_Monotonic(&t) < 0) {
return NULL;
}
return _PyTime_AsNanosecondsObject(t);
Monotonic clock, cannot go backward, as nanoseconds.");
-static int
-get_perf_counter(PyTime_t *t)
-{
- // Avoid _PyTime_PerfCounterUnchecked() which silently ignores errors.
- return _PyTime_PerfCounterWithInfo(t, NULL);
-}
-
-
static PyObject *
time_perf_counter(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_perf_counter(&t) < 0) {
+ if (PyTime_PerfCounter(&t) < 0) {
return NULL;
}
return _PyFloat_FromPyTime(t);
time_perf_counter_ns(PyObject *self, PyObject *unused)
{
PyTime_t t;
- if (get_perf_counter(&t) < 0) {
+ if (PyTime_PerfCounter(&t) < 0) {
return NULL;
}
return _PyTime_AsNanosecondsObject(t);
PyTime_t deadline, monotonic;
int err = 0;
- if (get_monotonic(&monotonic) < 0) {
+ if (PyTime_Monotonic(&monotonic) < 0) {
return -1;
}
deadline = monotonic + timeout;
}
#ifndef HAVE_CLOCK_NANOSLEEP
- if (get_monotonic(&monotonic) < 0) {
+ if (PyTime_Monotonic(&monotonic) < 0) {
return -1;
}
timeout = deadline - monotonic;
debug_cycle("uncollectable", FROM_GC(gc));
}
if (gcstate->debug & _PyGC_DEBUG_STATS) {
- double d = _PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
+ double d = PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
PySys_WriteStderr(
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
n+m, n, d);
n = state.uncollectable;
if (gcstate->debug & _PyGC_DEBUG_STATS) {
- double d = _PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
+ double d = PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
PySys_WriteStderr(
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
n+m, n, d);