]> granicus.if.org Git - python/commitdiff
Merged revisions 68018 via svnmerge from
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 29 Dec 2008 18:20:48 +0000 (18:20 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 29 Dec 2008 18:20:48 +0000 (18:20 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68018 | martin.v.loewis | 2008-12-29 19:17:34 +0100 (Mo, 29 Dez 2008) | 2 lines

  Issue #1040026: Fix os.times result on systems where HZ is incorrect.
........

Misc/NEWS
Modules/posixmodule.c

index 8c97ad2d7d2f99c526c63f266369a4fc0e393f70..7067353ac67ea06ea67ff64ece2062f1a745ed49 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,11 @@ Library
 
 - FileIO's mode attribute now always includes ``"b"``.
 
+Extension Modules
+-----------------
+
+- Issue #1040026: Fix os.times result on systems where HZ is incorrect.
+
 
 What's New in Python 2.6.1
 ==========================
index 1d0b7ec730cd7ccedc9f9b1e5b146e435a09dd8c..5858b4af127e6657aa416ad56f28dc11fb26e336 100644 (file)
@@ -5961,10 +5961,6 @@ posix_symlink(PyObject *self, PyObject *args)
 
 
 #ifdef HAVE_TIMES
-#ifndef HZ
-#define HZ 60 /* Universal constant :-) */
-#endif /* HZ */
-
 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
 static long
 system_uptime(void)
@@ -5990,6 +5986,8 @@ posix_times(PyObject *self, PyObject *noargs)
                             (double)system_uptime() / 1000);
 }
 #else /* not OS2 */
+#define NEED_TICKS_PER_SECOND
+static long ticks_per_second = -1;
 static PyObject *
 posix_times(PyObject *self, PyObject *noargs)
 {
@@ -6000,11 +5998,11 @@ posix_times(PyObject *self, PyObject *noargs)
        if (c == (clock_t) -1)
                return posix_error();
        return Py_BuildValue("ddddd",
-                            (double)t.tms_utime / HZ,
-                            (double)t.tms_stime / HZ,
-                            (double)t.tms_cutime / HZ,
-                            (double)t.tms_cstime / HZ,
-                            (double)c / HZ);
+                            (double)t.tms_utime / ticks_per_second,
+                            (double)t.tms_stime / ticks_per_second,
+                            (double)t.tms_cutime / ticks_per_second,
+                            (double)t.tms_cstime / ticks_per_second,
+                            (double)c / ticks_per_second);
 }
 #endif /* not OS2 */
 #endif /* HAVE_TIMES */
@@ -8966,6 +8964,15 @@ INITFUNC(void)
 
                statvfs_result_desc.name = MODNAME ".statvfs_result";
                PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
+#ifdef NEED_TICKS_PER_SECOND
+#  if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
+               ticks_per_second = sysconf(_SC_CLK_TCK);
+#  elif defined(HZ)
+               ticks_per_second = HZ;
+#  else
+               ticks_per_second = 60; /* magic fallback value; may be bogus */
+#  endif
+#endif
        }
        Py_INCREF((PyObject*) &StatResultType);
        PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);