[Python-checkins] r68018 - in python/trunk: Misc/NEWS Modules/posixmodule.c
martin.v.loewis
python-checkins at python.org
Mon Dec 29 19:17:34 CET 2008
Author: martin.v.loewis
Date: Mon Dec 29 19:17:34 2008
New Revision: 68018
Log:
Issue #1040026: Fix os.times result on systems where HZ is incorrect.
Modified:
python/trunk/Misc/NEWS
python/trunk/Modules/posixmodule.c
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Mon Dec 29 19:17:34 2008
@@ -246,6 +246,8 @@
Extension Modules
-----------------
+- Issue #1040026: Fix os.times result on systems where HZ is incorrect.
+
- Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris,
OpenBSD.
Modified: python/trunk/Modules/posixmodule.c
==============================================================================
--- python/trunk/Modules/posixmodule.c (original)
+++ python/trunk/Modules/posixmodule.c Mon Dec 29 19:17:34 2008
@@ -5957,10 +5957,6 @@
#ifdef HAVE_TIMES
-#ifndef HZ
-#define HZ 60 /* Universal constant :-) */
-#endif /* HZ */
-
#if defined(PYCC_VACPP) && defined(PYOS_OS2)
static long
system_uptime(void)
@@ -5986,6 +5982,8 @@
(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)
{
@@ -5996,11 +5994,11 @@
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 */
@@ -8962,6 +8960,15 @@
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);
More information about the Python-checkins
mailing list