mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
bpo-46008: Make runtime-global object/type lifecycle functions and state consistent. (gh-29998)
This change is strictly renames and moving code around. It helps in the following ways: * ensures type-related init functions focus strictly on one of the three aspects (state, objects, types) * passes in PyInterpreterState * to all those functions, simplifying work on moving types/objects/state to the interpreter * consistent naming conventions help make what's going on more clear * keeping API related to a type in the corresponding header file makes it more obvious where to look for it https://bugs.python.org/issue46008
This commit is contained in:
parent
d8a464ef03
commit
c8749b5783
38 changed files with 818 additions and 361 deletions
|
@ -2,18 +2,31 @@
|
|||
|
||||
#include "Python.h"
|
||||
|
||||
#include "pycore_bytesobject.h" // _PyBytes_InitTypes()
|
||||
#include "pycore_ceval.h" // _PyEval_FiniGIL()
|
||||
#include "pycore_context.h" // _PyContext_Init()
|
||||
#include "pycore_exceptions.h" // _PyExc_InitTypes()
|
||||
#include "pycore_dict.h" // _PyDict_Fini()
|
||||
#include "pycore_fileutils.h" // _Py_ResetForceASCII()
|
||||
#include "pycore_floatobject.h" // _PyFloat_InitTypes()
|
||||
#include "pycore_frame.h" // _PyFrame_Fini()
|
||||
#include "pycore_genobject.h" // _PyAsyncGen_Fini()
|
||||
#include "pycore_import.h" // _PyImport_BootstrapImp()
|
||||
#include "pycore_initconfig.h" // _PyStatus_OK()
|
||||
#include "pycore_list.h" // _PyList_Fini()
|
||||
#include "pycore_long.h" // _PyLong_InitTypes()
|
||||
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
|
||||
#include "pycore_pathconfig.h" // _PyConfig_WritePathConfig()
|
||||
#include "pycore_pyerrors.h" // _PyErr_Occurred()
|
||||
#include "pycore_pylifecycle.h" // _PyErr_Print()
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_sliceobject.h" // _PySlice_Fini()
|
||||
#include "pycore_structseq.h" // _PyStructSequence_InitState()
|
||||
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
|
||||
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
|
||||
#include "pycore_tuple.h" // _PyTuple_InitTypes()
|
||||
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
|
||||
|
||||
#include <locale.h> // setlocale()
|
||||
#include <stdlib.h> // getenv()
|
||||
|
@ -659,27 +672,27 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
|||
|
||||
|
||||
static PyStatus
|
||||
pycore_init_singletons(PyInterpreterState *interp)
|
||||
pycore_init_global_objects(PyInterpreterState *interp)
|
||||
{
|
||||
PyStatus status;
|
||||
|
||||
_PyLong_Init(interp);
|
||||
_PyLong_InitGlobalObjects(interp);
|
||||
|
||||
if (_Py_IsMainInterpreter(interp)) {
|
||||
_PyFloat_Init();
|
||||
}
|
||||
_PyFloat_InitState(interp);
|
||||
|
||||
status = _PyBytes_Init(interp);
|
||||
status = _PyBytes_InitGlobalObjects(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyUnicode_Init(interp);
|
||||
status = _PyUnicode_InitGlobalObjects(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyTuple_Init(interp);
|
||||
_PyUnicode_InitState(interp);
|
||||
|
||||
status = _PyTuple_InitGlobalObjects(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
@ -692,48 +705,70 @@ static PyStatus
|
|||
pycore_init_types(PyInterpreterState *interp)
|
||||
{
|
||||
PyStatus status;
|
||||
int is_main_interp = _Py_IsMainInterpreter(interp);
|
||||
|
||||
if (is_main_interp) {
|
||||
if (_PyStructSequence_Init() < 0) {
|
||||
return _PyStatus_ERR("can't initialize structseq");
|
||||
}
|
||||
|
||||
status = _PyTypes_Init();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (_PyLong_InitTypes() < 0) {
|
||||
return _PyStatus_ERR("can't init int type");
|
||||
}
|
||||
|
||||
status = _PyUnicode_InitTypes();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_main_interp) {
|
||||
if (_PyFloat_InitTypes() < 0) {
|
||||
return _PyStatus_ERR("can't init float");
|
||||
}
|
||||
}
|
||||
|
||||
status = _PyExc_Init(interp);
|
||||
status = _PyStructSequence_InitState(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyErr_InitTypes();
|
||||
status = _PyTypes_InitState(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (is_main_interp) {
|
||||
if (!_PyContext_Init()) {
|
||||
return _PyStatus_ERR("can't init context");
|
||||
}
|
||||
status = _PyTypes_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyBytes_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyLong_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyUnicode_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyFloat_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyTuple_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyExc_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyExc_InitGlobalObjects(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyExc_InitState(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyErr_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyContext_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
|
@ -799,7 +834,7 @@ pycore_interp_init(PyThreadState *tstate)
|
|||
// Create singletons before the first PyType_Ready() call, since
|
||||
// PyType_Ready() uses singletons like the Unicode empty string (tp_doc)
|
||||
// and the empty tuple singletons (tp_bases).
|
||||
status = pycore_init_singletons(interp);
|
||||
status = pycore_init_global_objects(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
@ -1641,7 +1676,7 @@ finalize_interp_types(PyInterpreterState *interp)
|
|||
_PyFrame_Fini(interp);
|
||||
_PyAsyncGen_Fini(interp);
|
||||
_PyContext_Fini(interp);
|
||||
_PyType_Fini(interp);
|
||||
_PyTypes_Fini(interp);
|
||||
// Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses
|
||||
// a dict internally.
|
||||
_PyUnicode_ClearInterned(interp);
|
||||
|
@ -1655,7 +1690,6 @@ finalize_interp_types(PyInterpreterState *interp)
|
|||
_PyBytes_Fini(interp);
|
||||
_PyUnicode_Fini(interp);
|
||||
_PyFloat_Fini(interp);
|
||||
_PyLong_Fini(interp);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue