diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-11-16 16:37:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 16:37:14 (GMT) |
commit | 5f55067e238c21de25f09ece9bb24ae8c42d02b4 (patch) | |
tree | f3fbce5e16aaa3a8871518c4ccb18bc8a1d86e9e /Objects | |
parent | 5cfb7d19f5242c9b8ffd2fe30a24569e85a99e1d (diff) | |
download | cpython-5f55067e238c21de25f09ece9bb24ae8c42d02b4.zip cpython-5f55067e238c21de25f09ece9bb24ae8c42d02b4.tar.gz cpython-5f55067e238c21de25f09ece9bb24ae8c42d02b4.tar.bz2 |
gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)
https://github.com/python/cpython/issues/81057
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/floatobject.c | 27 | ||||
-rw-r--r-- | Objects/moduleobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 19 |
3 files changed, 34 insertions, 14 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 65383b2..46016e9 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1723,12 +1723,14 @@ float___getnewargs___impl(PyObject *self) } /* this is for the benefit of the pack/unpack routines below */ +typedef enum _py_float_format_type float_format_type; +#define unknown_format _py_float_format_unknown +#define ieee_big_endian_format _py_float_format_ieee_big_endian +#define ieee_little_endian_format _py_float_format_ieee_little_endian -typedef enum { - unknown_format, ieee_big_endian_format, ieee_little_endian_format -} float_format_type; +#define float_format (_PyRuntime.float_state.float_format) +#define double_format (_PyRuntime.float_state.double_format) -static float_format_type double_format, float_format; /*[clinic input] @classmethod @@ -1929,13 +1931,9 @@ PyTypeObject PyFloat_Type = { .tp_vectorcall = (vectorcallfunc)float_vectorcall, }; -void -_PyFloat_InitState(PyInterpreterState *interp) +static void +_init_global_state(void) { - if (!_Py_IsMainInterpreter(interp)) { - return; - } - float_format_type detected_double_format, detected_float_format; /* We attempt to determine if this machine is using IEEE @@ -1985,6 +1983,15 @@ _PyFloat_InitState(PyInterpreterState *interp) float_format = detected_float_format; } +void +_PyFloat_InitState(PyInterpreterState *interp) +{ + if (!_Py_IsMainInterpreter(interp)) { + return; + } + _init_global_state(); +} + PyStatus _PyFloat_InitTypes(PyInterpreterState *interp) { diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 4a423a7..8e03f24 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -218,6 +218,7 @@ _PyModule_CreateInitialized(PyModuleDef* module, int module_api_version) _Py_PackageContext, and PyModule_Create*() will substitute this (if the name actually matches). */ +#define _Py_PackageContext (_PyRuntime.imports.pkgcontext) if (_Py_PackageContext != NULL) { const char *p = strrchr(_Py_PackageContext, '.'); if (p != NULL && strcmp(module->m_name, p+1) == 0) { @@ -225,6 +226,7 @@ _PyModule_CreateInitialized(PyModuleDef* module, int module_api_version) _Py_PackageContext = NULL; } } +#undef _Py_PackageContext if ((m = (PyModuleObject*)PyModule_New(name)) == NULL) return NULL; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index eaa8f58..b1acfc7 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1856,7 +1856,7 @@ _PyUnicode_FromId(_Py_Identifier *id) Py_ssize_t index = _Py_atomic_size_get(&id->index); if (index < 0) { - struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_ids; + struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_state.ids; PyThread_acquire_lock(rt_ids->lock, WAIT_LOCK); // Check again to detect concurrent access. Another thread can have @@ -14491,12 +14491,14 @@ PyTypeObject PyUnicode_Type = { /* Initialize the Unicode implementation */ -void -_PyUnicode_InitState(PyInterpreterState *interp) +static void +_init_global_state(void) { - if (!_Py_IsMainInterpreter(interp)) { + static int initialized = 0; + if (initialized) { return; } + initialized = 1; /* initialize the linebreak bloom filter */ const Py_UCS2 linebreak[] = { @@ -14514,6 +14516,15 @@ _PyUnicode_InitState(PyInterpreterState *interp) Py_ARRAY_LENGTH(linebreak)); } +void +_PyUnicode_InitState(PyInterpreterState *interp) +{ + if (!_Py_IsMainInterpreter(interp)) { + return; + } + _init_global_state(); +} + PyStatus _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) |