[Python-checkins] cpython: Document the fact that mach_timebase_info() cannot fail

victor.stinner python-checkins at python.org
Wed Mar 28 02:54:55 CEST 2012


http://hg.python.org/cpython/rev/4310cfaa3727
changeset:   75969:4310cfaa3727
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Mar 28 02:50:46 2012 +0200
summary:
  Document the fact that mach_timebase_info() cannot fail

And call mach_absolute_time() after mach_timebase_info().

files:
  Modules/timemodule.c |  12 ++++++++----
  1 files changed, 8 insertions(+), 4 deletions(-)


diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -768,13 +768,17 @@
 #if defined(MS_WINDOWS) && !defined(__BORLANDC__)
     return win32_clock(!strict);
 #elif defined(__APPLE__)
-    uint64_t time = mach_absolute_time();
+    static mach_timebase_info_data_t timebase;
+    uint64_t time;
     double secs;
 
-    static mach_timebase_info_data_t timebase;
-    if (timebase.denom == 0)
-      mach_timebase_info(&timebase);
+    if (timebase.denom == 0) {
+        /* According to the Technical Q&A QA1398, mach_timebase_info() cannot
+           fail: https://developer.apple.com/library/mac/#qa/qa1398/ */
+        (void)mach_timebase_info(&timebase);
+    }
 
+    time = mach_absolute_time();
     secs = (double)time * timebase.numer / timebase.denom * 1e-9;
 
     return PyFloat_FromDouble(secs);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list