]> granicus.if.org Git - python/commitdiff
Document the fact that mach_timebase_info() cannot fail
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 28 Mar 2012 00:50:46 +0000 (02:50 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 28 Mar 2012 00:50:46 +0000 (02:50 +0200)
And call mach_absolute_time() after mach_timebase_info().

Modules/timemodule.c

index b32c9df1071c7441171489902e01f2c7a2b1b2f9..c99c0a934b4ec1f322d9907d0bb108d8d713e4c5 100644 (file)
@@ -768,13 +768,17 @@ steady_clock(int strict)
 #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);