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

Skip to content

Commit f3923e9

Browse files
committed
Issue #15413: os.times() had disappeared under Windows.
1 parent 4c66896 commit f3923e9

2 files changed

Lines changed: 27 additions & 25 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Core and Builtins
5252
Library
5353
-------
5454

55+
- Issue #15413: os.times() had disappeared under Windows.
56+
5557
- Issue #15402: An issue in the struct module that caused sys.getsizeof to
5658
return incorrect results for struct.Struct instances has been fixed.
5759
Initial patch by Serhiy Storchaka.

Modules/posixmodule.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7453,8 +7453,11 @@ static PyStructSequence_Desc times_result_desc = {
74537453

74547454
static PyTypeObject TimesResultType;
74557455

7456+
#ifdef MS_WINDOWS
7457+
#define HAVE_TIMES /* mandatory, for the method table */
7458+
#endif
74567459

7457-
#if defined(HAVE_TIMES) || defined(MS_WINDOWS)
7460+
#ifdef HAVE_TIMES
74587461

74597462
static PyObject *
74607463
build_times_result(double user, double system,
@@ -7492,10 +7495,6 @@ Return an object containing floating point numbers indicating process\n\
74927495
times. The object behaves like a named tuple with these fields:\n\
74937496
(utime, stime, cutime, cstime, elapsed_time)");
74947497

7495-
#endif
7496-
7497-
7498-
#ifdef HAVE_TIMES
74997498
#if defined(PYCC_VACPP) && defined(PYOS_OS2)
75007499
static long
75017500
system_uptime(void)
@@ -7520,26 +7519,6 @@ posix_times(PyObject *self, PyObject *noargs)
75207519
(double)0 /* t.tms_cstime / HZ */,
75217520
(double)system_uptime() / 1000);
75227521
}
7523-
#else /* not OS2 */
7524-
#define NEED_TICKS_PER_SECOND
7525-
static long ticks_per_second = -1;
7526-
static PyObject *
7527-
posix_times(PyObject *self, PyObject *noargs)
7528-
{
7529-
struct tms t;
7530-
clock_t c;
7531-
errno = 0;
7532-
c = times(&t);
7533-
if (c == (clock_t) -1)
7534-
return posix_error();
7535-
return build_times_result(
7536-
(double)t.tms_utime / ticks_per_second,
7537-
(double)t.tms_stime / ticks_per_second,
7538-
(double)t.tms_cutime / ticks_per_second,
7539-
(double)t.tms_cstime / ticks_per_second,
7540-
(double)c / ticks_per_second);
7541-
}
7542-
#endif /* not OS2 */
75437522
#elif defined(MS_WINDOWS)
75447523
static PyObject *
75457524
posix_times(PyObject *self, PyObject *noargs)
@@ -7562,8 +7541,29 @@ posix_times(PyObject *self, PyObject *noargs)
75627541
(double)0,
75637542
(double)0);
75647543
}
7544+
#else /* Neither Windows nor OS/2 */
7545+
#define NEED_TICKS_PER_SECOND
7546+
static long ticks_per_second = -1;
7547+
static PyObject *
7548+
posix_times(PyObject *self, PyObject *noargs)
7549+
{
7550+
struct tms t;
7551+
clock_t c;
7552+
errno = 0;
7553+
c = times(&t);
7554+
if (c == (clock_t) -1)
7555+
return posix_error();
7556+
return build_times_result(
7557+
(double)t.tms_utime / ticks_per_second,
7558+
(double)t.tms_stime / ticks_per_second,
7559+
(double)t.tms_cutime / ticks_per_second,
7560+
(double)t.tms_cstime / ticks_per_second,
7561+
(double)c / ticks_per_second);
7562+
}
75657563
#endif
75667564

7565+
#endif /* HAVE_TIMES */
7566+
75677567

75687568
#ifdef HAVE_GETSID
75697569
PyDoc_STRVAR(posix_getsid__doc__,

0 commit comments

Comments
 (0)