gh-110850: Add PyTime_t C API (GH-115215)

* gh-110850: Add PyTime_t C API

Add PyTime_t API:

* PyTime_t type.
* PyTime_MIN and PyTime_MAX constants.
* PyTime_AsSecondsDouble(), PyTime_Monotonic(),
  PyTime_PerfCounter() and PyTime_GetSystemClock() functions.

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Petr Viktorin 2024-02-12 18:13:10 +01:00 committed by GitHub
parent c39272e143
commit 879f4546bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 448 additions and 114 deletions

View file

@ -52,21 +52,6 @@ test_pytime_fromsecondsobject(PyObject *self, PyObject *args)
return _PyTime_AsNanosecondsObject(ts);
}
static PyObject *
test_pytime_assecondsdouble(PyObject *self, PyObject *args)
{
PyObject *obj;
if (!PyArg_ParseTuple(args, "O", &obj)) {
return NULL;
}
_PyTime_t ts;
if (_PyTime_FromNanosecondsObject(&ts, obj) < 0) {
return NULL;
}
double d = _PyTime_AsSecondsDouble(ts);
return PyFloat_FromDouble(d);
}
static PyObject *
test_PyTime_AsTimeval(PyObject *self, PyObject *args)
{
@ -254,7 +239,6 @@ test_pytime_object_to_timespec(PyObject *self, PyObject *args)
static PyMethodDef TestMethods[] = {
{"_PyTime_AsMicroseconds", test_PyTime_AsMicroseconds, METH_VARARGS},
{"_PyTime_AsMilliseconds", test_PyTime_AsMilliseconds, METH_VARARGS},
{"_PyTime_AsSecondsDouble", test_pytime_assecondsdouble, METH_VARARGS},
#ifdef HAVE_CLOCK_GETTIME
{"_PyTime_AsTimespec", test_PyTime_AsTimespec, METH_VARARGS},
{"_PyTime_AsTimespec_clamp", test_PyTime_AsTimespec_clamp, METH_VARARGS},