mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
gh-94673: Properly Initialize and Finalize Static Builtin Types for Each Interpreter (gh-104072)
Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
This commit is contained in:
parent
b1ca34d4d5
commit
fdd878650d
17 changed files with 146 additions and 135 deletions
|
@ -3141,6 +3141,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
|
|||
{
|
||||
PyObject *version_info;
|
||||
int res;
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
|
||||
/* stdin/stdout/stderr are set in pylifecycle.c */
|
||||
|
||||
|
@ -3166,7 +3167,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
|
|||
SET_SYS("float_info", PyFloat_GetInfo());
|
||||
SET_SYS("int_info", PyLong_GetInfo());
|
||||
/* initialize hash_info */
|
||||
if (_PyStructSequence_InitBuiltin(&Hash_InfoType, &hash_info_desc) < 0) {
|
||||
if (_PyStructSequence_InitBuiltin(interp, &Hash_InfoType,
|
||||
&hash_info_desc) < 0)
|
||||
{
|
||||
goto type_init_failed;
|
||||
}
|
||||
SET_SYS("hash_info", get_hash_info(tstate));
|
||||
|
@ -3190,7 +3193,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
|
|||
#define ENSURE_INFO_TYPE(TYPE, DESC) \
|
||||
do { \
|
||||
if (_PyStructSequence_InitBuiltinWithFlags( \
|
||||
&TYPE, &DESC, Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { \
|
||||
interp, &TYPE, &DESC, Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { \
|
||||
goto type_init_failed; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -3226,8 +3229,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
|
|||
SET_SYS("thread_info", PyThread_GetInfo());
|
||||
|
||||
/* initialize asyncgen_hooks */
|
||||
if (_PyStructSequence_InitBuiltin(
|
||||
&AsyncGenHooksType, &asyncgen_hooks_desc) < 0) {
|
||||
if (_PyStructSequence_InitBuiltin(interp, &AsyncGenHooksType,
|
||||
&asyncgen_hooks_desc) < 0)
|
||||
{
|
||||
goto type_init_failed;
|
||||
}
|
||||
|
||||
|
@ -3489,20 +3493,20 @@ error:
|
|||
|
||||
|
||||
void
|
||||
_PySys_Fini(PyInterpreterState *interp)
|
||||
_PySys_FiniTypes(PyInterpreterState *interp)
|
||||
{
|
||||
if (_Py_IsMainInterpreter(interp)) {
|
||||
_PyStructSequence_FiniBuiltin(&VersionInfoType);
|
||||
_PyStructSequence_FiniBuiltin(&FlagsType);
|
||||
_PyStructSequence_FiniBuiltin(interp, &VersionInfoType);
|
||||
_PyStructSequence_FiniBuiltin(interp, &FlagsType);
|
||||
#if defined(MS_WINDOWS)
|
||||
_PyStructSequence_FiniBuiltin(&WindowsVersionType);
|
||||
_PyStructSequence_FiniBuiltin(interp, &WindowsVersionType);
|
||||
#endif
|
||||
_PyStructSequence_FiniBuiltin(&Hash_InfoType);
|
||||
_PyStructSequence_FiniBuiltin(&AsyncGenHooksType);
|
||||
_PyStructSequence_FiniBuiltin(interp, &Hash_InfoType);
|
||||
_PyStructSequence_FiniBuiltin(interp, &AsyncGenHooksType);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (_Py_IsMainInterpreter(interp)) {
|
||||
Py_CLEAR(EmscriptenInfoType);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue