Skip to content

Commit 7f6d5b8

Browse files
Move ticks_per_second to _PyRuntimeState.
1 parent 9a86dd3 commit 7f6d5b8

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

Include/internal/pycore_os.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ extern "C" {
99
#endif
1010

1111

12+
#ifndef MS_WINDOWS
13+
#define _OS_NEED_TICKS_PER_SECOND
14+
# define need_ticks_per_second_STATE \
15+
long ticks_per_second;
16+
# define need_ticks_per_second_INIT \
17+
.ticks_per_second = -1,
18+
#else
19+
# define need_ticks_per_second_STATE
20+
# define need_ticks_per_second_INIT
21+
#endif /* MS_WINDOWS */
22+
23+
1224
struct _os_runtime_state {
1325
int _not_used;
26+
need_ticks_per_second_STATE
1427
};
15-
16-
#define _OS_RUNTIME_INIT {0}
28+
# define _OS_RUNTIME_INIT \
29+
{ \
30+
._not_used = 0, \
31+
need_ticks_per_second_INIT \
32+
}
1733

1834

1935
#ifdef __cplusplus

Modules/posixmodule.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9051,10 +9051,23 @@ build_times_result(PyObject *module, double user, double system,
90519051
}
90529052

90539053

9054-
#ifndef MS_WINDOWS
9055-
#define NEED_TICKS_PER_SECOND
9056-
static long ticks_per_second = -1;
9057-
#endif /* MS_WINDOWS */
9054+
#ifdef _OS_NEED_TICKS_PER_SECOND
9055+
#define ticks_per_second _PyRuntime.os.ticks_per_second
9056+
static void
9057+
ticks_per_second_init(void)
9058+
{
9059+
if (ticks_per_second != -1) {
9060+
return;
9061+
}
9062+
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
9063+
ticks_per_second = sysconf(_SC_CLK_TCK);
9064+
# elif defined(HZ)
9065+
ticks_per_second = HZ;
9066+
# else
9067+
ticks_per_second = 60; /* magic fallback value; may be bogus */
9068+
# endif
9069+
}
9070+
#endif
90589071

90599072
/*[clinic input]
90609073
os.times
@@ -9089,10 +9102,10 @@ os_times_impl(PyObject *module)
90899102
(double)0,
90909103
(double)0);
90919104
}
9105+
#elif !defined(_OS_NEED_TICKS_PER_SECOND)
9106+
# error "missing ticks_per_second"
90929107
#else /* MS_WINDOWS */
90939108
{
9094-
9095-
90969109
struct tms t;
90979110
clock_t c;
90989111
errno = 0;
@@ -15922,14 +15935,9 @@ posixmodule_exec(PyObject *m)
1592215935
}
1592315936
PyModule_AddObject(m, "statvfs_result", Py_NewRef(StatVFSResultType));
1592415937
state->StatVFSResultType = StatVFSResultType;
15925-
#ifdef NEED_TICKS_PER_SECOND
15926-
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
15927-
ticks_per_second = sysconf(_SC_CLK_TCK);
15928-
# elif defined(HZ)
15929-
ticks_per_second = HZ;
15930-
# else
15931-
ticks_per_second = 60; /* magic fallback value; may be bogus */
15932-
# endif
15938+
15939+
#ifdef _OS_NEED_TICKS_PER_SECOND
15940+
ticks_per_second_init();
1593315941
#endif
1593415942

1593515943
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)

Tools/c-analyzer/cpython/globals-to-fix.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ Modules/faulthandler.c - old_stack -
391391
## initialized once
392392

393393
Modules/posixmodule.c - structseq_new -
394-
Modules/posixmodule.c - ticks_per_second -
395394
Modules/timemodule.c _PyTime_GetClockWithInfo initialized -
396395
Modules/timemodule.c _PyTime_GetProcessTimeWithInfo ticks_per_second -
397396

0 commit comments

Comments
 (0)