[pypy-commit] pypy default: Support (reasonably) converting a user-supplied "double" directly to a
arigo
noreply at buildbot.pypy.org
Fri Mar 7 21:35:35 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r69793:3f834e4349e4
Date: 2014-03-07 21:34 +0100
http://bitbucket.org/pypy/pypy/changeset/3f834e4349e4/
Log: Support (reasonably) converting a user-supplied "double" directly to
a time_t, which may be 64-bit even on 32-bit platforms --- notably
on Windows. Should fix issue1697.
diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -358,14 +358,16 @@
seconds = pytime.time()
else:
seconds = space.float_w(w_seconds)
- try:
- seconds = ovfcheck_float_to_int(seconds)
- t = rffi.r_time_t(seconds)
- if rffi.cast(lltype.Signed, t) != seconds:
- raise OverflowError
- except OverflowError:
+ #
+ t = rffi.cast(rffi.TIME_T, seconds)
+ #
+ # Logic from CPython: How much info did we lose? We assume that
+ # time_t is an integral type. If we lost a second or more, the
+ # input doesn't fit in a time_t; call it an error.
+ diff = seconds - rffi.cast(lltype.Float, t)
+ if diff <= -1.0 or diff >= 1.0:
raise OperationError(space.w_ValueError,
- space.wrap("time argument too large"))
+ space.wrap("timestamp out of range for platform time_t"))
return t
def _tm_to_tuple(space, t):
diff --git a/pypy/module/rctime/test/test_rctime.py b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -59,6 +59,8 @@
assert 0 <= (t1 - t0) < 1.2
t = rctime.time()
assert rctime.gmtime(t) == rctime.gmtime(t)
+ raises(ValueError, rctime.gmtime, 2**64)
+ raises(ValueError, rctime.gmtime, -2**64)
def test_localtime(self):
import time as rctime
More information about the pypy-commit
mailing list