Skip to content
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
8 changes: 6 additions & 2 deletions Doc/c-api/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ Raw Clock Functions
Similar to clock functions, but don't set an exception on error and don't
require the caller to hold the GIL.

The functions return ``0`` on success, or set ``*result`` to ``0`` return
``-1`` on failure.
On success, the functions return ``0``.

On failure, they set ``*result`` to ``0`` and return ``-1``, *without* setting
an exception. To get the cause of the error, acquire the GIL and call the
regular (non-``Raw``) function. Note that the regular function may succeed after
the ``Raw`` one failed.

.. c:function:: int PyTime_MonotonicRaw(PyTime_t *result)

Expand Down
6 changes: 6 additions & 0 deletions Modules/_testcapi/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test_pytime_monotonic(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
PyTime_t t;
int res = PyTime_Monotonic(&t);
if (res < 0) {
assert(t == 0);
return NULL;
}
assert(res == 0);
Expand All @@ -67,6 +68,7 @@ test_pytime_monotonic_raw(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
res = PyTime_MonotonicRaw(&t);
Py_END_ALLOW_THREADS
if (res < 0) {
assert(t == 0);
PyErr_SetString(PyExc_RuntimeError, "PyTime_MonotonicRaw() failed");
return NULL;
}
Expand All @@ -81,6 +83,7 @@ test_pytime_perf_counter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
PyTime_t t;
int res = PyTime_PerfCounter(&t);
if (res < 0) {
assert(t == 0);
return NULL;
}
assert(res == 0);
Expand All @@ -97,6 +100,7 @@ test_pytime_perf_counter_raw(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args
res = PyTime_PerfCounterRaw(&t);
Py_END_ALLOW_THREADS
if (res < 0) {
assert(t == 0);
PyErr_SetString(PyExc_RuntimeError, "PyTime_PerfCounterRaw() failed");
return NULL;
}
Expand All @@ -111,6 +115,7 @@ test_pytime_time(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
PyTime_t t;
int res = PyTime_Time(&t);
if (res < 0) {
assert(t == 0);
return NULL;
}
assert(res == 0);
Expand All @@ -127,6 +132,7 @@ test_pytime_time_raw(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
res = PyTime_TimeRaw(&t);
Py_END_ALLOW_THREADS
if (res < 0) {
assert(t == 0);
PyErr_SetString(PyExc_RuntimeError, "PyTime_TimeRaw() failed");
return NULL;
}
Expand Down
10 changes: 8 additions & 2 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,10 @@ PyTime_t
_PyTime_TimeUnchecked(void)
{
PyTime_t t;
(void)PyTime_TimeRaw(&t);
int result = PyTime_TimeRaw(&t);
// We assume that getting the time succeeds on current platforms.
// If this ever is not the case, use PyTime_TimeRaw instead.
assert(result == 0);
return t;
}

Expand Down Expand Up @@ -1267,7 +1270,10 @@ PyTime_t
_PyTime_MonotonicUnchecked(void)
{
PyTime_t t;
(void)PyTime_MonotonicRaw(&t);
int result = PyTime_MonotonicRaw(&t);
// We assume that getting the time succeeds on current platforms.
// If this ever is not the case, use PyTime_MonotonicRaw instead.
assert(result == 0);
return t;
}

Expand Down