[pypy-commit] pypy py3.7-pep564: - fix obscure annotation issue by using r_int64(intmask(t.c_millitm)) instead
arigo
pypy.commits at gmail.com
Fri Nov 8 02:26:24 EST 2019
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.7-pep564
Changeset: r97993:3f033e498621
Date: 2019-11-08 08:25 +0100
http://bitbucket.org/pypy/pypy/changeset/3f033e498621/
Log: - fix obscure annotation issue by using
r_int64(intmask(t.c_millitm)) instead of r_int64(t.c_millitm). On
64-bit machines the latter is equivalent to int(t.c_millitm), and
c_millitm is unsigned, which makes the annotator think we should use
intmask() instead of int().
- use space.newint() instead of space.newlong_from_rarith_int()
again. Sorry! I realized that space.newint() would accept any
integer type, and fall back automatically to from_rarith_int()
depending on the type. This is better because on 64-bit machines
passing r_int64() fits into a regular integer.
- add test_translation.py, which finds quickly the annotation error
mentioned above, and no other, so there are chances that it works
now.
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -277,7 +277,7 @@
_setinfo(space, w_info, "GetSystemTimeAsFileTime()",
time_increment[0] * 1e-7, False, True)
if return_ns:
- return space.newlong_from_rarith_int(r_int64(microseconds) * 10**3)
+ return space.newint(r_int64(microseconds) * 10**3)
else:
tv_sec = microseconds / 10**6
tv_usec = microseconds % 10**6
@@ -302,7 +302,7 @@
if w_info is not None:
_setinfo(space, w_info, "gettimeofday()", 1e-6, False, True)
if return_ns:
- return space.newlong_from_rarith_int(
+ return space.newint(
r_int64(timeval.c_tv_sec) * 10**9 +
r_int64(timeval.c_tv_usec) * 10**3)
else:
@@ -315,9 +315,9 @@
if w_info is not None:
_setinfo(space, w_info, "ftime()", 1e-3, False, True)
if return_ns:
- return space.newlong_from_rarith_int(
+ return space.newint(
r_int64(t.c_time) * 10**9 +
- r_int64(t.c_millitm) * 10**6)
+ r_int64(intmask(t.c_millitm)) * 10**6)
else:
return space.newfloat(
widen(t.c_time) +
@@ -327,7 +327,7 @@
_setinfo(space, w_info, "time()", 1.0, False, True)
result = c_time(lltype.nullptr(rffi.TIME_TP.TO))
if return_ns:
- return space.newlong_from_rarith_int(r_int64(result) * 10**9)
+ return space.newint(r_int64(result) * 10**9)
else:
return space.newfloat(float(result))
@@ -697,7 +697,7 @@
_setinfo(space, w_info, "clock_gettime(CLOCK_REALTIME)",
res, False, True)
if return_ns:
- return space.newlong_from_rarith_int(_timespec_to_nanoseconds(timespec))
+ return space.newint(_timespec_to_nanoseconds(timespec))
else:
return space.newfloat(_timespec_to_seconds(timespec))
return _gettimeofday_impl(space, w_info, return_ns)
@@ -829,7 +829,7 @@
if ret != 0:
raise exception_from_saved_errno(space, space.w_OSError)
if return_ns:
- return space.newlong_from_rarith_int(_timespec_to_nanoseconds(timespec))
+ return space.newint(_timespec_to_nanoseconds(timespec))
else:
return space.newfloat(_timespec_to_seconds(timespec))
@@ -993,7 +993,7 @@
_setinfo(space, w_info, implementation, resolution, True, False)
if return_ns:
- return space.newlong_from_rarith_int(r_int64(tick_count) * 10**6)
+ return space.newint(r_int64(tick_count) * 10**6)
else:
return space.newfloat(tick_count * 1e-3)
@@ -1017,7 +1017,7 @@
res = (numer / denom) * 1e-9
_setinfo(space, w_info, "mach_absolute_time()", res, True, False)
if return_ns:
- return space.newlong_from_rarith_int(nanosecs)
+ return space.newint(nanosecs)
else:
secs = nanosecs / 10**9
rest = nanosecs % 10**9
@@ -1084,7 +1084,7 @@
_setinfo(space, w_info, "QueryPerformanceCounter()", resolution,
True, False)
if return_ns:
- return space.newlong_from_rarith_int(r_int64(diff) * 10**9 // time_state.divisor)
+ return space.newint(r_int64(diff) * 10**9 // time_state.divisor)
else:
return space.newfloat(float(diff) / float(time_state.divisor))
@@ -1139,7 +1139,7 @@
if w_info is not None:
_setinfo(space, w_info, "GetProcessTimes()", 1e-7, True, False)
if return_ns:
- return space.newlong_from_rarith_int((r_int64(kernel_time2) + r_int64(user_time2)) * 10**2)
+ return space.newint((r_int64(kernel_time2) + r_int64(user_time2)) * 10**2)
else:
return space.newfloat((float(kernel_time2) + float(user_time2)) * 1e-7)
else:
@@ -1168,7 +1168,7 @@
_setinfo(space, w_info,
implementation, res, True, False)
if return_ns:
- return space.newlong_from_rarith_int(_timespec_to_nanoseconds(timespec))
+ return space.newint(_timespec_to_nanoseconds(timespec))
else:
return space.newfloat(_timespec_to_seconds(timespec))
@@ -1182,7 +1182,7 @@
_setinfo(space, w_info,
"getrusage(RUSAGE_SELF)", 1e-6, True, False)
if return_ns:
- return space.newlong_from_rarith_int(
+ return space.newint(
decode_timeval_ns(rusage.c_ru_utime) +
decode_timeval_ns(rusage.c_ru_stime))
else:
@@ -1199,7 +1199,7 @@
1.0 / rposix.CLOCK_TICKS_PER_SECOND,
True, False)
if return_ns:
- return space.newlong_from_rarith_int(r_int64(cpu_time) * 10**9 // int(rposix.CLOCK_TICKS_PER_SECOND))
+ return space.newint(r_int64(cpu_time) * 10**9 // int(rposix.CLOCK_TICKS_PER_SECOND))
else:
return space.newfloat(float(cpu_time) / rposix.CLOCK_TICKS_PER_SECOND)
return _clock_impl(space, w_info, return_ns)
@@ -1233,7 +1233,7 @@
_setinfo(space, w_info,
"clock()", 1.0 / CLOCKS_PER_SEC, True, False)
if return_ns:
- return space.newlong_from_rarith_int(r_int64(value) * 10**9 // CLOCKS_PER_SEC)
+ return space.newint(r_int64(value) * 10**9 // CLOCKS_PER_SEC)
else:
return space.newfloat(float(value) / CLOCKS_PER_SEC)
diff --git a/pypy/module/time/test/test_ztranslation.py b/pypy/module/time/test/test_ztranslation.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/time/test/test_ztranslation.py
@@ -0,0 +1,4 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+def test_checkmodule():
+ checkmodule('time')
More information about the pypy-commit
mailing list