Author: Ronan Lamy <ronan.l...@gmail.com> Branch: release-pypy3.5-v5.9.x Changeset: r93593:21617b1a2e41 Date: 2017-12-28 15:57 +0100 http://bitbucket.org/pypy/pypy/changeset/21617b1a2e41/
Log: Fix issue #2717 (grafted from f145d85043878194d7eee33b2049063843e032d8) diff --git a/pypy/interpreter/test/test_timeutils.py b/pypy/interpreter/test/test_timeutils.py new file mode 100644 --- /dev/null +++ b/pypy/interpreter/test/test_timeutils.py @@ -0,0 +1,13 @@ +import pytest +from rpython.rlib.rarithmetic import r_longlong +from pypy.interpreter.error import OperationError +from pypy.interpreter.timeutils import timestamp_w + +def test_timestamp_w(space): + w_1_year = space.newint(365 * 24 * 3600) + result = timestamp_w(space, w_1_year) + assert isinstance(result, r_longlong) + assert result // 10 ** 9 == space.int_w(w_1_year) + w_millenium = space.mul(w_1_year, space.newint(1000)) + with pytest.raises(OperationError): # timestamps overflow after ~300 years + timestamp_w(space, w_millenium) diff --git a/pypy/interpreter/timeutils.py b/pypy/interpreter/timeutils.py --- a/pypy/interpreter/timeutils.py +++ b/pypy/interpreter/timeutils.py @@ -3,7 +3,7 @@ """ import math from rpython.rlib.rarithmetic import ( - r_longlong, ovfcheck, ovfcheck_float_to_longlong) + r_longlong, ovfcheck_float_to_longlong) from rpython.rlib import rfloat from pypy.interpreter.error import oefmt @@ -31,10 +31,10 @@ raise oefmt(space.w_OverflowError, "timestamp %R too large to convert to C _PyTime_t", w_secs) else: - sec = space.int_w(w_secs) try: - result = ovfcheck(sec * SECS_TO_NS) + sec = space.bigint_w(w_secs).tolonglong() + result = sec * r_longlong(SECS_TO_NS) except OverflowError: raise oefmt(space.w_OverflowError, - "timestamp too large to convert to C _PyTime_t") - return r_longlong(result) + "timestamp %R too large to convert to C _PyTime_t", w_secs) + return result _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit