diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2014-09-17 13:19:01 +0800 |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2014-09-17 13:19:01 +0800 |
commit | ebf0eb89938ef3da56660bb4b8e043d73311d5f4 (patch) | |
tree | ceb9977286425825740876df5d7349e19f131c38 /Python/pytime.c | |
parent | 8f9f5f2448be5f6d261011e2cf16ce1d9e733fc4 (diff) | |
parent | 7512258fade04669b3fa38b313372fbd2c04cf47 (diff) | |
download | cpython-ebf0eb89938ef3da56660bb4b8e043d73311d5f4.tar.gz |
Merge from 3.3
Issue #22421 - Secure pydoc server run. Bind it to localhost instead of all interfaces.
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index beeab87e2c..de6a41fe00 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -152,7 +152,7 @@ _PyLong_FromTime_t(time_t t) static int _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator, - double denominator) + double denominator, _PyTime_round_t round) { assert(denominator <= LONG_MAX); if (PyFloat_Check(obj)) { @@ -167,6 +167,20 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator, intpart -= 1.0; } + floatpart *= denominator; + if (round == _PyTime_ROUND_UP) { + if (intpart >= 0) { + floatpart = ceil(floatpart); + if (floatpart >= denominator) { + floatpart = 0.0; + intpart += 1.0; + } + } + else { + floatpart = floor(floatpart); + } + } + *sec = (time_t)intpart; err = intpart - (double)*sec; if (err <= -1.0 || err >= 1.0) { @@ -174,7 +188,6 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator, return -1; } - floatpart *= denominator; *numerator = (long)floatpart; return 0; } @@ -188,12 +201,18 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator, } int -_PyTime_ObjectToTime_t(PyObject *obj, time_t *sec) +_PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round) { if (PyFloat_Check(obj)) { double d, intpart, err; d = PyFloat_AsDouble(obj); + if (round == _PyTime_ROUND_UP) { + if (d >= 0) + d = ceil(d); + else + d = floor(d); + } (void)modf(d, &intpart); *sec = (time_t)intpart; @@ -213,15 +232,17 @@ _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec) } int -_PyTime_ObjectToTimespec(PyObject *obj, time_t *sec, long *nsec) +_PyTime_ObjectToTimespec(PyObject *obj, time_t *sec, long *nsec, + _PyTime_round_t round) { - return _PyTime_ObjectToDenominator(obj, sec, nsec, 1e9); + return _PyTime_ObjectToDenominator(obj, sec, nsec, 1e9, round); } int -_PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec) +_PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec, + _PyTime_round_t round) { - return _PyTime_ObjectToDenominator(obj, sec, usec, 1e6); + return _PyTime_ObjectToDenominator(obj, sec, usec, 1e6, round); } void |