[pypy-commit] pypy py3.3: Check for availability of clock_gettime() instead of assuming it exists on posix systems.

mjacob noreply at buildbot.pypy.org
Tue Aug 18 02:09:50 CEST 2015


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3.3
Changeset: r79027:0c1306f0e901
Date: 2015-08-18 01:01 +0200
http://bitbucket.org/pypy/pypy/changeset/0c1306f0e901/

Log:	Check for availability of clock_gettime() instead of assuming it
	exists on posix systems.

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
@@ -4,7 +4,7 @@
 from pypy.interpreter.gateway import unwrap_spec
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.rarithmetic import intmask
-from rpython.rlib.rtime import c_clock_gettime, TIMESPEC, win_perf_counter
+from rpython.rlib.rtime import win_perf_counter
 from rpython.rlib import rposix
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 import math
@@ -114,6 +114,7 @@
     CLOCKS_PER_SEC = platform.ConstantInteger("CLOCKS_PER_SEC")
     clock_t = platform.SimpleType("clock_t", rffi.ULONG)
     has_gettimeofday = platform.Has('gettimeofday')
+    has_clock_gettime = platform.Has('clock_gettime')
 
 CLOCK_CONSTANTS = ['CLOCK_HIGHRES', 'CLOCK_MONOTONIC', 'CLOCK_MONOTONIC_RAW',
                    'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME',
@@ -192,13 +193,15 @@
 c_mktime = external('mktime', [TM_P], rffi.TIME_T)
 c_localtime = external('localtime', [rffi.TIME_TP], TM_P,
                        save_err=rffi.RFFI_SAVE_ERRNO)
-if _POSIX:
+if cConfig.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)
+if _POSIX:
     c_tzset = external('tzset', [], lltype.Void)
 if _WIN:
     win_eci = ExternalCompilationInfo(
@@ -615,7 +618,7 @@
 
     return space.wrap(float(tt))
 
-if _POSIX:
+if cConfig.has_clock_gettime:
     def _timespec_to_seconds(timespec):
         return int(timespec.c_tv_sec) + int(timespec.c_tv_nsec) * 1e-9
 
@@ -647,6 +650,7 @@
             secs = _timespec_to_seconds(timespec)
         return space.wrap(secs)
 
+if _POSIX:
     def tzset(space):
         """tzset()
 


More information about the pypy-commit mailing list