cpython: 0591cf5c9ebd (original) (raw)
Mercurial > cpython
changeset 95306:0591cf5c9ebd
Issue #23485: Add _PyTime_FromMillisecondsObject() function [#23485]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Mon, 30 Mar 2015 21:36:10 +0200 |
parents | 17b6d0d7da00 |
children | 69b1683ee001 |
files | Include/pytime.h Python/pytime.c |
diffstat | 2 files changed, 25 insertions(+), 6 deletions(-)[+] [-] Include/pytime.h 8 Python/pytime.c 23 |
line wrap: on
line diff
--- a/Include/pytime.h +++ b/Include/pytime.h @@ -69,12 +69,18 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec /* Create a timestamp from a number of nanoseconds (C long). / PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(PY_LONG_LONG ns); -/ Convert a Python float or int to a timetamp. +/* Convert a number of seconds (Python float or int) to a timetamp. Raise an exception and return -1 on error, return 0 on success. */ PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t, PyObject obj, _PyTime_round_t round); +/ Convert a number of milliseconds (Python float or int, 10^-3) to a timetamp.
- Raise an exception and return -1 on error, return 0 on success. */ +PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t,
- PyObject *obj,
- _PyTime_round_t round);
+ /* Convert a timestamp to a number of seconds as a C double. */ PyAPI_FUNC(double) _PyTime_AsSecondsDouble(_PyTime_t t);
--- a/Python/pytime.c +++ b/Python/pytime.c @@ -203,8 +203,9 @@ static int } #endif -int -_PyTime_FromSecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round) +static int +_PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round,
long to_nanoseconds)[](#l2.11)
{ if (PyFloat_Check(obj)) { /* volatile avoids unsafe optimization on float enabled by gcc -O3 / @@ -212,7 +213,7 @@ int / convert to a number of nanoseconds */ d = PyFloat_AsDouble(obj);
d *= 1e9;[](#l2.19)
d *= to_nanoseconds;[](#l2.20)
if (round == _PyTime_ROUND_CEILING) d = ceil(d); @@ -242,8 +243,8 @@ int _PyTime_overflow(); return -1; }
*t = sec * SEC_TO_NS;[](#l2.28)
if (*t / SEC_TO_NS != sec) {[](#l2.29)
*t = sec * to_nanoseconds;[](#l2.30)
if (*t / to_nanoseconds != sec) {[](#l2.31) _PyTime_overflow();[](#l2.32) return -1;[](#l2.33) }[](#l2.34)
@@ -251,6 +252,18 @@ int } } +int +_PyTime_FromSecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round) +{
+} + +int +_PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round) +{