mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-36763: Implement the PEP 587 (GH-13592)
* Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
This commit is contained in:
parent
8cd5165ba0
commit
331a6a56e9
50 changed files with 3229 additions and 2165 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "Python.h"
|
||||
#include "pycore_ceval.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#include "pycore_pymem.h"
|
||||
#include "pycore_pystate.h"
|
||||
#include "pycore_pylifecycle.h"
|
||||
|
@ -42,7 +42,7 @@ static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_st
|
|||
static void _PyThreadState_Delete(_PyRuntimeState *runtime, PyThreadState *tstate);
|
||||
|
||||
|
||||
static _PyInitError
|
||||
static PyStatus
|
||||
_PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
|
||||
{
|
||||
/* We preserve the hook across init, because there is
|
||||
|
@ -60,7 +60,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
|
|||
|
||||
_PyGC_Initialize(&runtime->gc);
|
||||
_PyEval_Initialize(&runtime->ceval);
|
||||
_PyPreConfig_InitPythonConfig(&runtime->preconfig);
|
||||
PyPreConfig_InitPythonConfig(&runtime->preconfig);
|
||||
|
||||
runtime->gilstate.check_enabled = 1;
|
||||
|
||||
|
@ -71,22 +71,22 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
|
|||
|
||||
runtime->interpreters.mutex = PyThread_allocate_lock();
|
||||
if (runtime->interpreters.mutex == NULL) {
|
||||
return _Py_INIT_ERR("Can't initialize threads for interpreter");
|
||||
return _PyStatus_ERR("Can't initialize threads for interpreter");
|
||||
}
|
||||
runtime->interpreters.next_id = -1;
|
||||
|
||||
runtime->xidregistry.mutex = PyThread_allocate_lock();
|
||||
if (runtime->xidregistry.mutex == NULL) {
|
||||
return _Py_INIT_ERR("Can't initialize threads for cross-interpreter data registry");
|
||||
return _PyStatus_ERR("Can't initialize threads for cross-interpreter data registry");
|
||||
}
|
||||
|
||||
// Set it to the ID of the main thread of the main interpreter.
|
||||
runtime->main_thread = PyThread_get_thread_ident();
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyRuntimeState_Init(_PyRuntimeState *runtime)
|
||||
{
|
||||
/* Force default allocator, since _PyRuntimeState_Fini() must
|
||||
|
@ -94,10 +94,10 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
|
|||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
_PyInitError err = _PyRuntimeState_Init_impl(runtime);
|
||||
PyStatus status = _PyRuntimeState_Init_impl(runtime);
|
||||
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -163,7 +163,7 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
|
|||
static void _PyGILState_NoteThreadState(
|
||||
struct _gilstate_runtime_state *gilstate, PyThreadState* tstate);
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyInterpreterState_Enable(_PyRuntimeState *runtime)
|
||||
{
|
||||
struct pyinterpreters *interpreters = &runtime->interpreters;
|
||||
|
@ -182,11 +182,11 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
|
|||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
if (interpreters->mutex == NULL) {
|
||||
return _Py_INIT_ERR("Can't initialize threads for interpreter");
|
||||
return _PyStatus_ERR("Can't initialize threads for interpreter");
|
||||
}
|
||||
}
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
PyInterpreterState *
|
||||
|
@ -205,8 +205,11 @@ PyInterpreterState_New(void)
|
|||
interp->id_refcount = -1;
|
||||
interp->check_interval = 100;
|
||||
|
||||
_PyInitError err = _PyCoreConfig_InitPythonConfig(&interp->core_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
PyStatus status = PyConfig_InitPythonConfig(&interp->config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
/* Don't report status to caller: PyConfig_InitPythonConfig()
|
||||
can only fail with a memory allocation error. */
|
||||
PyConfig_Clear(&interp->config);
|
||||
PyMem_RawFree(interp);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -269,7 +272,7 @@ _PyInterpreterState_Clear(_PyRuntimeState *runtime, PyInterpreterState *interp)
|
|||
|
||||
Py_CLEAR(interp->audit_hooks);
|
||||
|
||||
_PyCoreConfig_Clear(&interp->core_config);
|
||||
PyConfig_Clear(&interp->config);
|
||||
Py_CLEAR(interp->codec_search_path);
|
||||
Py_CLEAR(interp->codec_search_cache);
|
||||
Py_CLEAR(interp->codec_error_registry);
|
||||
|
@ -523,12 +526,6 @@ _PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
|
|||
interp->requires_idref = required ? 1 : 0;
|
||||
}
|
||||
|
||||
_PyCoreConfig *
|
||||
_PyInterpreterState_GetCoreConfig(PyInterpreterState *interp)
|
||||
{
|
||||
return &interp->core_config;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyInterpreterState_GetMainModule(PyInterpreterState *interp)
|
||||
{
|
||||
|
@ -775,7 +772,7 @@ _PyState_ClearModules(void)
|
|||
void
|
||||
PyThreadState_Clear(PyThreadState *tstate)
|
||||
{
|
||||
int verbose = tstate->interp->core_config.verbose;
|
||||
int verbose = tstate->interp->config.verbose;
|
||||
|
||||
if (verbose && tstate->frame != NULL)
|
||||
fprintf(stderr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue