Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05bfe1f

Browse files
committed
Merged revisions 68018 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 1efc23c commit 05bfe1f

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ Tools/Demos
154154
Extension Modules
155155
-----------------
156156

157+
- Issue #1040026: Fix os.times result on systems where HZ is incorrect.
158+
157159
- Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris,
158160
OpenBSD.
159161

Modules/posixmodule.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,10 +4494,6 @@ posix_symlink(PyObject *self, PyObject *args)
44944494

44954495

44964496
#ifdef HAVE_TIMES
4497-
#ifndef HZ
4498-
#define HZ 60 /* Universal constant :-) */
4499-
#endif /* HZ */
4500-
45014497
#if defined(PYCC_VACPP) && defined(PYOS_OS2)
45024498
static long
45034499
system_uptime(void)
@@ -4523,6 +4519,8 @@ posix_times(PyObject *self, PyObject *noargs)
45234519
(double)system_uptime() / 1000);
45244520
}
45254521
#else /* not OS2 */
4522+
#define NEED_TICKS_PER_SECOND
4523+
static long ticks_per_second = -1;
45264524
static PyObject *
45274525
posix_times(PyObject *self, PyObject *noargs)
45284526
{
@@ -4533,11 +4531,11 @@ posix_times(PyObject *self, PyObject *noargs)
45334531
if (c == (clock_t) -1)
45344532
return posix_error();
45354533
return Py_BuildValue("ddddd",
4536-
(double)t.tms_utime / HZ,
4537-
(double)t.tms_stime / HZ,
4538-
(double)t.tms_cutime / HZ,
4539-
(double)t.tms_cstime / HZ,
4540-
(double)c / HZ);
4534+
(double)t.tms_utime / ticks_per_second,
4535+
(double)t.tms_stime / ticks_per_second,
4536+
(double)t.tms_cutime / ticks_per_second,
4537+
(double)t.tms_cstime / ticks_per_second,
4538+
(double)c / ticks_per_second);
45414539
}
45424540
#endif /* not OS2 */
45434541
#endif /* HAVE_TIMES */
@@ -7409,6 +7407,15 @@ INITFUNC(void)
74097407

74107408
statvfs_result_desc.name = MODNAME ".statvfs_result";
74117409
PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
7410+
#ifdef NEED_TICKS_PER_SECOND
7411+
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
7412+
ticks_per_second = sysconf(_SC_CLK_TCK);
7413+
# elif defined(HZ)
7414+
ticks_per_second = HZ;
7415+
# else
7416+
ticks_per_second = 60; /* magic fallback value; may be bogus */
7417+
# endif
7418+
#endif
74127419
}
74137420
Py_INCREF((PyObject*) &StatResultType);
74147421
PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);

0 commit comments

Comments
 (0)