gh-81057: Move time Globals to _PyRuntimeState (gh-100122)

https://github.com/python/cpython/issues/81057
This commit is contained in:
Eric Snow 2022-12-08 16:46:09 -07:00 • committed by GitHub
parent cda9f0236f
commit 8a3f06c54b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 100 additions and 118 deletions

View file

@ -1,38 +0,0 @@
#ifndef Py_INTERNAL_OS_H
#define Py_INTERNAL_OS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#ifndef MS_WINDOWS
#define _OS_NEED_TICKS_PER_SECOND
# define need_ticks_per_second_STATE \
long ticks_per_second;
# define need_ticks_per_second_INIT \
.ticks_per_second = -1,
#else
# define need_ticks_per_second_STATE
# define need_ticks_per_second_INIT
#endif /* MS_WINDOWS */
struct _os_runtime_state {
int _not_used;
need_ticks_per_second_STATE
};
# define _OS_RUNTIME_INIT \
{ \
._not_used = 0, \
need_ticks_per_second_INIT \
}
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_OS_H */

View file

@ -44,6 +44,7 @@ extern void _PySys_Fini(PyInterpreterState *interp);
extern int _PyBuiltins_AddExceptions(PyObject * bltinmod);
extern PyStatus _Py_HashRandomization_Init(const PyConfig *);
extern PyStatus _PyTime_Init(void);
extern PyStatus _PyImportZip_Init(PyThreadState *tstate);
extern PyStatus _PyGC_Init(PyInterpreterState *interp);
extern PyStatus _PyAtExit_Init(PyInterpreterState *interp);

View file

@ -21,7 +21,7 @@ extern "C" {
#include "pycore_pymem.h" // struct _pymem_allocators
#include "pycore_pyhash.h" // struct pyhash_runtime_state
#include "pycore_obmalloc.h" // struct obmalloc_state
#include "pycore_os.h" // struct _os_runtime_state
#include "pycore_time.h" // struct _time_runtime_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
struct _getargs_runtime_state {
@ -104,7 +104,7 @@ typedef struct pyruntimestate {
* KeyboardInterrupt exception, suggesting the user pressed ^C. */
int unhandled_keyboard_interrupt;
} signals;
struct _os_runtime_state os;
struct _time_runtime_state time;
struct pyinterpreters {
PyThread_type_lock mutex;

View file

@ -26,7 +26,6 @@ extern "C" {
}, \
.obmalloc = _obmalloc_state_INIT(runtime.obmalloc), \
.pyhash_state = pyhash_state_INIT, \
.os = _OS_RUNTIME_INIT, \
.interpreters = { \
/* This prevents interpreters from getting created \
until _PyInterpreterState_Enable() is called. */ \

View file

@ -0,0 +1,25 @@
#ifndef Py_INTERNAL_TIME_H
#define Py_INTERNAL_TIME_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
struct _time_runtime_state {
#ifdef HAVE_TIMES
int ticks_per_second_initialized;
long ticks_per_second;
#else
int _not_used;
#endif
};
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_TIME_H */