[pypy-commit] pypy py3.5: Fix issue #2717
rlamy
pypy.commits at gmail.com
Thu Dec 28 09:58:42 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r93587:f145d8504387
Date: 2017-12-28 15:57 +0100
http://bitbucket.org/pypy/pypy/changeset/f145d8504387/
Log: Fix issue #2717
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
More information about the pypy-commit
mailing list