summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-27 21:27:24 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-27 21:27:24 (GMT)
commit4bfb460d883bd224b61a0e7403a09ea093947890 (patch)
tree7555350c57b3d6145b08dba3ef242d721d84413a /Python
parent52d1493c0ccf04aed23f3db9a720ca24f2d19f13 (diff)
downloadcpython-4bfb460d883bd224b61a0e7403a09ea093947890.zip
cpython-4bfb460d883bd224b61a0e7403a09ea093947890.tar.gz
cpython-4bfb460d883bd224b61a0e7403a09ea093947890.tar.bz2
Issue #22117: time.monotonic() now uses the new _PyTime_t API
* Add _PyTime_FromNanoseconds() * Add _PyTime_AsSecondsDouble() * Add unit tests for _PyTime_AsSecondsDouble()
Diffstat (limited to 'Python')
-rw-r--r--Python/pytime.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index 2aeeddc..a496335 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -405,6 +405,15 @@ _PyTime_overflow(void)
"timestamp too large to convert to C _PyTime_t");
}
+_PyTime_t
+_PyTime_FromNanoseconds(PY_LONG_LONG ns)
+{
+ _PyTime_t t;
+ assert(sizeof(PY_LONG_LONG) <= sizeof(_PyTime_t));
+ t = Py_SAFE_DOWNCAST(ns, PY_LONG_LONG, _PyTime_t);
+ return t;
+}
+
#if !defined(MS_WINDOWS) && !defined(__APPLE__)
static int
_PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts)
@@ -470,6 +479,17 @@ _PyTime_FromSecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
}
}
+double
+_PyTime_AsSecondsDouble(_PyTime_t t)
+{
+ _PyTime_t sec, ns;
+ /* Divide using integers to avoid rounding issues on the integer part.
+ 1e-9 cannot be stored exactly in IEEE 64-bit. */
+ sec = t / SEC_TO_NS;
+ ns = t % SEC_TO_NS;
+ return (double)sec + (double)ns * 1e-9;
+}
+
PyObject *
_PyTime_AsNanosecondsObject(_PyTime_t t)
{
@@ -661,6 +681,12 @@ _PyTime_GetMonotonicClock(void)
}
int
+_PyTime_GetMonotonicClockWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+{
+ return pymonotonic_new(tp, info, 1);
+}
+
+int
_PyTime_Init(void)
{
_PyTime_timeval tv;