[pypy-commit] pypy py3k: Use rtime.clock_{gettime,settime,getres}
arigo
pypy.commits at gmail.com
Sat Oct 1 04:56:05 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3k
Changeset: r87489:1b443a0430fd
Date: 2016-10-01 10:55 +0200
http://bitbucket.org/pypy/pypy/changeset/1b443a0430fd/
Log: Use rtime.clock_{gettime,settime,getres}
diff --git a/pypy/module/time/__init__.py b/pypy/module/time/__init__.py
--- a/pypy/module/time/__init__.py
+++ b/pypy/module/time/__init__.py
@@ -1,7 +1,7 @@
from pypy.interpreter.mixedmodule import MixedModule
-from .interp_time import (CLOCK_CONSTANTS, HAS_CLOCK_GETTIME, cConfig,
- HAS_MONOTONIC)
+from .interp_time import HAS_MONOTONIC
+from rpython.rlib import rtime
import os
_WIN = os.name == "nt"
@@ -24,20 +24,18 @@
'process_time': 'interp_time.process_time',
}
- if HAS_CLOCK_GETTIME:
+ if rtime.HAS_CLOCK_GETTIME:
interpleveldefs['clock_gettime'] = 'interp_time.clock_gettime'
interpleveldefs['clock_settime'] = 'interp_time.clock_settime'
interpleveldefs['clock_getres'] = 'interp_time.clock_getres'
+ for constant in rtime.ALL_DEFINED_CLOCKS:
+ interpleveldefs[constant] = 'space.wrap(%d)' % (
+ getattr(rtime, constant),)
if HAS_MONOTONIC:
interpleveldefs['monotonic'] = 'interp_time.monotonic'
if os.name == "posix":
interpleveldefs['tzset'] = 'interp_time.tzset'
- for constant in CLOCK_CONSTANTS:
- value = getattr(cConfig, constant)
- if value is not None:
- interpleveldefs[constant] = 'space.wrap(interp_time.cConfig.%s)' % constant
-
appleveldefs = {
'struct_time': 'app_time.struct_time',
'__doc__': 'app_time.__doc__',
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
@@ -160,15 +160,6 @@
)
CLOCKS_PER_SEC = platform.ConstantInteger("CLOCKS_PER_SEC")
has_gettimeofday = platform.Has('gettimeofday')
- has_clock_gettime = platform.Has('clock_gettime')
- CLOCK_PROF = platform.DefinedConstantInteger('CLOCK_PROF')
-
-CLOCK_CONSTANTS = ['CLOCK_HIGHRES', 'CLOCK_MONOTONIC', 'CLOCK_MONOTONIC_RAW',
- 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME',
- 'CLOCK_THREAD_CPUTIME_ID']
-
-for constant in CLOCK_CONSTANTS:
- setattr(CConfig, constant, platform.DefinedConstantInteger(constant))
if _POSIX:
calling_conv = 'c'
@@ -227,9 +218,9 @@
timeval = cConfig.timeval
CLOCKS_PER_SEC = cConfig.CLOCKS_PER_SEC
-HAS_CLOCK_GETTIME = cConfig.has_clock_gettime
-HAS_CLOCK_HIGHRES = cConfig.CLOCK_HIGHRES is not None
-HAS_CLOCK_MONOTONIC = cConfig.CLOCK_MONOTONIC is not None
+HAS_CLOCK_GETTIME = rtime.HAS_CLOCK_GETTIME
+HAS_CLOCK_HIGHRES = rtime.CLOCK_HIGHRES is not None
+HAS_CLOCK_MONOTONIC = rtime.CLOCK_MONOTONIC is not None
HAS_MONOTONIC = (_WIN or _MACOSX or
(HAS_CLOCK_GETTIME and (HAS_CLOCK_HIGHRES or HAS_CLOCK_MONOTONIC)))
tm = cConfig.tm
@@ -316,12 +307,7 @@
save_err=rffi.RFFI_SAVE_ERRNO)
if HAS_CLOCK_GETTIME:
from rpython.rlib.rtime import TIMESPEC, c_clock_gettime
- c_clock_settime = external('clock_settime',
- [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
- save_err=rffi.RFFI_SAVE_ERRNO)
- c_clock_getres = external('clock_getres',
- [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
- save_err=rffi.RFFI_SAVE_ERRNO)
+ from rpython.rlib.rtime import c_clock_settime, c_clock_getres
if _POSIX:
c_tzset = external('tzset', [], lltype.Void)
if _WIN:
@@ -623,11 +609,11 @@
Fractions of a second may be present if the system clock provides them."""
if HAS_CLOCK_GETTIME:
with lltype.scoped_alloc(TIMESPEC) as timespec:
- ret = c_clock_gettime(cConfig.CLOCK_REALTIME, timespec)
+ ret = c_clock_gettime(rtime.CLOCK_REALTIME, timespec)
if ret == 0:
if w_info is not None:
with lltype.scoped_alloc(TIMESPEC) as tsres:
- ret = c_clock_getres(cConfig.CLOCK_REALTIME, tsres)
+ ret = c_clock_getres(rtime.CLOCK_REALTIME, tsres)
if ret == 0:
res = _timespec_to_seconds(tsres)
else:
@@ -903,11 +889,11 @@
else:
assert _POSIX
def monotonic(space, w_info=None):
- if cConfig.CLOCK_HIGHRES is not None:
- clk_id = cConfig.CLOCK_HIGHRES
+ if rtime.CLOCK_HIGHRES is not None:
+ clk_id = rtime.CLOCK_HIGHRES
implementation = "clock_gettime(CLOCK_HIGHRES)"
else:
- clk_id = cConfig.CLOCK_MONOTONIC
+ clk_id = rtime.CLOCK_MONOTONIC
implementation = "clock_gettime(CLOCK_MONOTONIC)"
w_result = clock_gettime(space, clk_id)
if w_info is not None:
@@ -994,13 +980,13 @@
def process_time(space, w_info=None):
if HAS_CLOCK_GETTIME and (
- cConfig.CLOCK_PROF is not None or
- cConfig.CLOCK_PROCESS_CPUTIME_ID is not None):
- if cConfig.CLOCK_PROF is not None:
- clk_id = cConfig.CLOCK_PROF
+ rtime.CLOCK_PROF is not None or
+ rtime.CLOCK_PROCESS_CPUTIME_ID is not None):
+ if rtime.CLOCK_PROF is not None:
+ clk_id = rtime.CLOCK_PROF
implementation = "clock_gettime(CLOCK_PROF)"
else:
- clk_id = cConfig.CLOCK_PROCESS_CPUTIME_ID
+ clk_id = rtime.CLOCK_PROCESS_CPUTIME_ID
implementation = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)"
with lltype.scoped_alloc(TIMESPEC) as timespec:
ret = c_clock_gettime(clk_id, timespec)
More information about the pypy-commit
mailing list