mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +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
|
@ -2824,7 +2824,7 @@ _PyBuiltin_Init(void)
|
|||
{
|
||||
PyObject *mod, *dict, *debug;
|
||||
|
||||
const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
|
||||
const PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
|
||||
|
||||
if (PyType_Ready(&PyFilter_Type) < 0 ||
|
||||
PyType_Ready(&PyMap_Type) < 0 ||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#ifdef MS_WINDOWS
|
||||
# include <windows.h>
|
||||
/* All sample MSDN wincrypt programs include the header below. It is at least
|
||||
|
@ -547,14 +547,14 @@ _PyOS_URandomNonblock(void *buffer, Py_ssize_t size)
|
|||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_Py_HashRandomization_Init(const _PyCoreConfig *config)
|
||||
PyStatus
|
||||
_Py_HashRandomization_Init(const PyConfig *config)
|
||||
{
|
||||
void *secret = &_Py_HashSecret;
|
||||
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
|
||||
|
||||
if (_Py_HashSecret_Initialized) {
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
_Py_HashSecret_Initialized = 1;
|
||||
|
||||
|
@ -579,11 +579,11 @@ _Py_HashRandomization_Init(const _PyCoreConfig *config)
|
|||
pyurandom() is non-blocking mode (blocking=0): see the PEP 524. */
|
||||
res = pyurandom(secret, secret_size, 0, 0);
|
||||
if (res < 0) {
|
||||
return _Py_INIT_ERR("failed to get random numbers "
|
||||
return _PyStatus_ERR("failed to get random numbers "
|
||||
"to initialize Python");
|
||||
}
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
PyCodeObject *co = NULL;
|
||||
PyCompilerFlags local_flags;
|
||||
int merged;
|
||||
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
|
||||
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
|
||||
|
||||
if (!__doc__) {
|
||||
__doc__ = PyUnicode_InternFromString("__doc__");
|
||||
|
@ -4782,7 +4782,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
|
|||
return compiler_error(c, "'await' outside function");
|
||||
}
|
||||
|
||||
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
|
||||
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
|
||||
c->u->u_scope_type != COMPILER_SCOPE_COMPREHENSION){
|
||||
return compiler_error(c, "'await' outside async function");
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
|
|||
const char *pathname, FILE *fp)
|
||||
{
|
||||
int flags = BIND_FIRST | BIND_DEFERRED;
|
||||
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
|
||||
int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
|
||||
if (verbose) {
|
||||
flags = BIND_FIRST | BIND_IMMEDIATE |
|
||||
BIND_NONFATAL | BIND_VERBOSE;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* Error handling */
|
||||
|
||||
#include "Python.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_pystate.h"
|
||||
#include "pycore_traceback.h"
|
||||
|
@ -1090,16 +1090,16 @@ static PyStructSequence_Desc UnraisableHookArgs_desc = {
|
|||
};
|
||||
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyErr_Init(void)
|
||||
{
|
||||
if (UnraisableHookArgsType.tp_name == NULL) {
|
||||
if (PyStructSequence_InitType2(&UnraisableHookArgsType,
|
||||
&UnraisableHookArgs_desc) < 0) {
|
||||
return _Py_INIT_ERR("failed to initialize UnraisableHookArgs type");
|
||||
return _PyStatus_ERR("failed to initialize UnraisableHookArgs type");
|
||||
}
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ extern int PyInitFrozenExtensions(void);
|
|||
int
|
||||
Py_FrozenMain(int argc, char **argv)
|
||||
{
|
||||
_PyInitError err = _PyRuntime_Initialize();
|
||||
if (_PyInitError_Failed(err)) {
|
||||
_Py_ExitInitError(err);
|
||||
PyStatus status = _PyRuntime_Initialize();
|
||||
if (PyStatus_Exception(status)) {
|
||||
Py_ExitStatusException(status);
|
||||
}
|
||||
|
||||
const char *p;
|
||||
|
@ -39,11 +39,11 @@ Py_FrozenMain(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
_PyCoreConfig config;
|
||||
err = _PyCoreConfig_InitPythonConfig(&config);
|
||||
if (_PyInitError_Failed(err)) {
|
||||
_PyCoreConfig_Clear(&config);
|
||||
_Py_ExitInitError(err);
|
||||
PyConfig config;
|
||||
status = PyConfig_InitPythonConfig(&config);
|
||||
if (PyStatus_Exception(status)) {
|
||||
PyConfig_Clear(&config);
|
||||
Py_ExitStatusException(status);
|
||||
}
|
||||
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
|
||||
|
||||
|
@ -85,10 +85,10 @@ Py_FrozenMain(int argc, char **argv)
|
|||
if (argc >= 1)
|
||||
Py_SetProgramName(argv_copy[0]);
|
||||
|
||||
err = _Py_InitializeFromConfig(&config);
|
||||
_PyCoreConfig_Clear(&config);
|
||||
if (_PyInitError_Failed(err)) {
|
||||
_Py_ExitInitError(err);
|
||||
status = Py_InitializeFromConfig(&config);
|
||||
PyConfig_Clear(&config);
|
||||
if (PyStatus_Exception(status)) {
|
||||
Py_ExitStatusException(status);
|
||||
}
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
|
|
@ -43,17 +43,17 @@ module _imp
|
|||
|
||||
/* Initialize things */
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyImport_Init(PyInterpreterState *interp)
|
||||
{
|
||||
interp->builtins_copy = PyDict_Copy(interp->builtins);
|
||||
if (interp->builtins_copy == NULL) {
|
||||
return _Py_INIT_ERR("Can't backup builtins dict");
|
||||
return _PyStatus_ERR("Can't backup builtins dict");
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyImportHooks_Init(void)
|
||||
{
|
||||
PyObject *v, *path_hooks = NULL;
|
||||
|
@ -82,15 +82,15 @@ _PyImportHooks_Init(void)
|
|||
goto error;
|
||||
}
|
||||
Py_DECREF(path_hooks);
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
|
||||
error:
|
||||
PyErr_Print();
|
||||
return _Py_INIT_ERR("initializing sys.meta_path, sys.path_hooks, "
|
||||
return _PyStatus_ERR("initializing sys.meta_path, sys.path_hooks, "
|
||||
"or path_importer_cache failed");
|
||||
}
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyImportZip_Init(PyInterpreterState *interp)
|
||||
{
|
||||
PyObject *path_hooks, *zipimport;
|
||||
|
@ -102,7 +102,7 @@ _PyImportZip_Init(PyInterpreterState *interp)
|
|||
goto error;
|
||||
}
|
||||
|
||||
int verbose = interp->core_config.verbose;
|
||||
int verbose = interp->config.verbose;
|
||||
if (verbose) {
|
||||
PySys_WriteStderr("# installing zipimport hook\n");
|
||||
}
|
||||
|
@ -138,11 +138,11 @@ _PyImportZip_Init(PyInterpreterState *interp)
|
|||
}
|
||||
}
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
|
||||
error:
|
||||
PyErr_Print();
|
||||
return _Py_INIT_ERR("initializing zipimport failed");
|
||||
return _PyStatus_ERR("initializing zipimport failed");
|
||||
}
|
||||
|
||||
/* Locking primitives to prevent parallel imports of the same module
|
||||
|
@ -418,7 +418,7 @@ PyImport_Cleanup(void)
|
|||
|
||||
/* XXX Perhaps these precautions are obsolete. Who knows? */
|
||||
|
||||
int verbose = interp->core_config.verbose;
|
||||
int verbose = interp->config.verbose;
|
||||
if (verbose) {
|
||||
PySys_WriteStderr("# clear builtins._\n");
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ _PyImport_FindExtensionObjectEx(PyObject *name, PyObject *filename,
|
|||
PyMapping_DelItem(modules, name);
|
||||
return NULL;
|
||||
}
|
||||
int verbose = _PyInterpreterState_Get()->core_config.verbose;
|
||||
int verbose = _PyInterpreterState_Get()->config.verbose;
|
||||
if (verbose) {
|
||||
PySys_FormatStderr("import %U # previously loaded (%R)\n",
|
||||
name, filename);
|
||||
|
@ -1455,7 +1455,7 @@ remove_importlib_frames(PyInterpreterState *interp)
|
|||
which end with a call to "_call_with_frames_removed". */
|
||||
|
||||
PyErr_Fetch(&exception, &value, &base_tb);
|
||||
if (!exception || interp->core_config.verbose) {
|
||||
if (!exception || interp->config.verbose) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1655,7 +1655,7 @@ import_find_and_load(PyObject *abs_name)
|
|||
_Py_IDENTIFIER(_find_and_load);
|
||||
PyObject *mod = NULL;
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
int import_time = interp->core_config.import_time;
|
||||
int import_time = interp->config.import_time;
|
||||
static int import_level;
|
||||
static _PyTime_t accumulated;
|
||||
|
||||
|
@ -2338,7 +2338,7 @@ PyInit__imp(void)
|
|||
goto failure;
|
||||
}
|
||||
|
||||
const wchar_t *mode = _PyInterpreterState_Get()->core_config.check_hash_pycs_mode;
|
||||
const wchar_t *mode = _PyInterpreterState_Get()->config.check_hash_pycs_mode;
|
||||
PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1);
|
||||
if (pyc_mode == NULL) {
|
||||
goto failure;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "Python.h"
|
||||
#include "osdefs.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#include "pycore_fileutils.h"
|
||||
#include "pycore_pathconfig.h"
|
||||
#include "pycore_pymem.h"
|
||||
|
@ -34,7 +34,7 @@ copy_wstr(wchar_t **dst, const wchar_t *src)
|
|||
|
||||
|
||||
static void
|
||||
_PyPathConfig_Clear(_PyPathConfig *config)
|
||||
pathconfig_clear(_PyPathConfig *config)
|
||||
{
|
||||
/* _PyMem_SetDefaultAllocator() is needed to get a known memory allocator,
|
||||
since Py_SetPath(), Py_SetPythonHome() and Py_SetProgramName() can be
|
||||
|
@ -63,12 +63,11 @@ _PyPathConfig_Clear(_PyPathConfig *config)
|
|||
}
|
||||
|
||||
|
||||
/* Calculate the path configuration: initialize path_config from core_config */
|
||||
static _PyInitError
|
||||
_PyPathConfig_Calculate(_PyPathConfig *path_config,
|
||||
const _PyCoreConfig *core_config)
|
||||
/* Calculate the path configuration: initialize pathconfig from config */
|
||||
static PyStatus
|
||||
pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config)
|
||||
{
|
||||
_PyInitError err;
|
||||
PyStatus status;
|
||||
_PyPathConfig new_config = _PyPathConfig_INIT;
|
||||
|
||||
PyMemAllocatorEx old_alloc;
|
||||
|
@ -76,40 +75,40 @@ _PyPathConfig_Calculate(_PyPathConfig *path_config,
|
|||
|
||||
/* Calculate program_full_path, prefix, exec_prefix,
|
||||
dll_path (Windows), and module_search_path */
|
||||
err = _PyPathConfig_Calculate_impl(&new_config, core_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
goto err;
|
||||
status = _PyPathConfig_Calculate(&new_config, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Copy home and program_name from core_config */
|
||||
if (copy_wstr(&new_config.home, core_config->home) < 0) {
|
||||
err = _Py_INIT_NO_MEMORY();
|
||||
goto err;
|
||||
/* Copy home and program_name from config */
|
||||
if (copy_wstr(&new_config.home, config->home) < 0) {
|
||||
status = _PyStatus_NO_MEMORY();
|
||||
goto error;
|
||||
}
|
||||
if (copy_wstr(&new_config.program_name, core_config->program_name) < 0) {
|
||||
err = _Py_INIT_NO_MEMORY();
|
||||
goto err;
|
||||
if (copy_wstr(&new_config.program_name, config->program_name) < 0) {
|
||||
status = _PyStatus_NO_MEMORY();
|
||||
goto error;
|
||||
}
|
||||
|
||||
_PyPathConfig_Clear(path_config);
|
||||
*path_config = new_config;
|
||||
pathconfig_clear(pathconfig);
|
||||
*pathconfig = new_config;
|
||||
|
||||
err = _Py_INIT_OK();
|
||||
status = _PyStatus_OK();
|
||||
goto done;
|
||||
|
||||
err:
|
||||
_PyPathConfig_Clear(&new_config);
|
||||
error:
|
||||
pathconfig_clear(&new_config);
|
||||
|
||||
done:
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyPathConfig_SetGlobal(const _PyPathConfig *config)
|
||||
{
|
||||
_PyInitError err;
|
||||
PyStatus status;
|
||||
_PyPathConfig new_config = _PyPathConfig_INIT;
|
||||
|
||||
PyMemAllocatorEx old_alloc;
|
||||
|
@ -118,8 +117,8 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config)
|
|||
#define COPY_ATTR(ATTR) \
|
||||
do { \
|
||||
if (copy_wstr(&new_config.ATTR, config->ATTR) < 0) { \
|
||||
_PyPathConfig_Clear(&new_config); \
|
||||
err = _Py_INIT_NO_MEMORY(); \
|
||||
pathconfig_clear(&new_config); \
|
||||
status = _PyStatus_NO_MEMORY(); \
|
||||
goto done; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -134,15 +133,15 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config)
|
|||
COPY_ATTR(program_name);
|
||||
COPY_ATTR(home);
|
||||
|
||||
_PyPathConfig_Clear(&_Py_path_config);
|
||||
pathconfig_clear(&_Py_path_config);
|
||||
/* Steal new_config strings; don't clear new_config */
|
||||
_Py_path_config = new_config;
|
||||
|
||||
err = _Py_INIT_OK();
|
||||
status = _PyStatus_OK();
|
||||
|
||||
done:
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,14 +151,14 @@ _PyPathConfig_ClearGlobal(void)
|
|||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
_PyPathConfig_Clear(&_Py_path_config);
|
||||
pathconfig_clear(&_Py_path_config);
|
||||
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
}
|
||||
|
||||
|
||||
static wchar_t*
|
||||
_PyWstrList_Join(const _PyWstrList *list, wchar_t sep)
|
||||
_PyWideStringList_Join(const PyWideStringList *list, wchar_t sep)
|
||||
{
|
||||
size_t len = 1; /* NUL terminator */
|
||||
for (Py_ssize_t i=0; i < list->length; i++) {
|
||||
|
@ -189,70 +188,69 @@ _PyWstrList_Join(const _PyWstrList *list, wchar_t sep)
|
|||
}
|
||||
|
||||
|
||||
/* Set the global path configuration from core_config. */
|
||||
_PyInitError
|
||||
_PyCoreConfig_SetPathConfig(const _PyCoreConfig *core_config)
|
||||
/* Set the global path configuration from config. */
|
||||
PyStatus
|
||||
_PyConfig_SetPathConfig(const PyConfig *config)
|
||||
{
|
||||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
_PyInitError err;
|
||||
_PyPathConfig path_config = _PyPathConfig_INIT;
|
||||
PyStatus status;
|
||||
_PyPathConfig pathconfig = _PyPathConfig_INIT;
|
||||
|
||||
path_config.module_search_path = _PyWstrList_Join(&core_config->module_search_paths, DELIM);
|
||||
if (path_config.module_search_path == NULL) {
|
||||
pathconfig.module_search_path = _PyWideStringList_Join(&config->module_search_paths, DELIM);
|
||||
if (pathconfig.module_search_path == NULL) {
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
if (copy_wstr(&path_config.program_full_path, core_config->executable) < 0) {
|
||||
if (copy_wstr(&pathconfig.program_full_path, config->executable) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
if (copy_wstr(&path_config.prefix, core_config->prefix) < 0) {
|
||||
if (copy_wstr(&pathconfig.prefix, config->prefix) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
if (copy_wstr(&path_config.exec_prefix, core_config->exec_prefix) < 0) {
|
||||
if (copy_wstr(&pathconfig.exec_prefix, config->exec_prefix) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
#ifdef MS_WINDOWS
|
||||
path_config.dll_path = _Py_GetDLLPath();
|
||||
if (path_config.dll_path == NULL) {
|
||||
pathconfig.dll_path = _Py_GetDLLPath();
|
||||
if (pathconfig.dll_path == NULL) {
|
||||
goto no_memory;
|
||||
}
|
||||
#endif
|
||||
if (copy_wstr(&path_config.program_name, core_config->program_name) < 0) {
|
||||
if (copy_wstr(&pathconfig.program_name, config->program_name) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
if (copy_wstr(&path_config.home, core_config->home) < 0) {
|
||||
if (copy_wstr(&pathconfig.home, config->home) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
err = _PyPathConfig_SetGlobal(&path_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = _PyPathConfig_SetGlobal(&pathconfig);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = _Py_INIT_OK();
|
||||
status = _PyStatus_OK();
|
||||
goto done;
|
||||
|
||||
no_memory:
|
||||
err = _Py_INIT_NO_MEMORY();
|
||||
status = _PyStatus_NO_MEMORY();
|
||||
|
||||
done:
|
||||
_PyPathConfig_Clear(&path_config);
|
||||
pathconfig_clear(&pathconfig);
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
core_config_init_module_search_paths(_PyCoreConfig *config,
|
||||
_PyPathConfig *path_config)
|
||||
static PyStatus
|
||||
config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)
|
||||
{
|
||||
assert(!config->use_module_search_paths);
|
||||
assert(!config->module_search_paths_set);
|
||||
|
||||
_PyWstrList_Clear(&config->module_search_paths);
|
||||
_PyWideStringList_Clear(&config->module_search_paths);
|
||||
|
||||
const wchar_t *sys_path = path_config->module_search_path;
|
||||
const wchar_t *sys_path = pathconfig->module_search_path;
|
||||
const wchar_t delim = DELIM;
|
||||
const wchar_t *p = sys_path;
|
||||
while (1) {
|
||||
|
@ -264,15 +262,15 @@ core_config_init_module_search_paths(_PyCoreConfig *config,
|
|||
size_t path_len = (p - sys_path);
|
||||
wchar_t *path = PyMem_RawMalloc((path_len + 1) * sizeof(wchar_t));
|
||||
if (path == NULL) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
memcpy(path, sys_path, path_len * sizeof(wchar_t));
|
||||
path[path_len] = L'\0';
|
||||
|
||||
int res = _PyWstrList_Append(&config->module_search_paths, path);
|
||||
PyStatus status = PyWideStringList_Append(&config->module_search_paths, path);
|
||||
PyMem_RawFree(path);
|
||||
if (res < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (*p == '\0') {
|
||||
|
@ -280,96 +278,96 @@ core_config_init_module_search_paths(_PyCoreConfig *config,
|
|||
}
|
||||
sys_path = p + 1;
|
||||
}
|
||||
config->use_module_search_paths = 1;
|
||||
return _Py_INIT_OK();
|
||||
config->module_search_paths_set = 1;
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
_PyCoreConfig_CalculatePathConfig(_PyCoreConfig *config)
|
||||
static PyStatus
|
||||
config_calculate_pathconfig(PyConfig *config)
|
||||
{
|
||||
_PyPathConfig path_config = _PyPathConfig_INIT;
|
||||
_PyInitError err;
|
||||
_PyPathConfig pathconfig = _PyPathConfig_INIT;
|
||||
PyStatus status;
|
||||
|
||||
err = _PyPathConfig_Calculate(&path_config, config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = pathconfig_calculate(&pathconfig, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!config->use_module_search_paths) {
|
||||
err = core_config_init_module_search_paths(config, &path_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
if (!config->module_search_paths_set) {
|
||||
status = config_init_module_search_paths(config, &pathconfig);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->executable == NULL) {
|
||||
if (copy_wstr(&config->executable,
|
||||
path_config.program_full_path) < 0) {
|
||||
pathconfig.program_full_path) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->prefix == NULL) {
|
||||
if (copy_wstr(&config->prefix, path_config.prefix) < 0) {
|
||||
if (copy_wstr(&config->prefix, pathconfig.prefix) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->exec_prefix == NULL) {
|
||||
if (copy_wstr(&config->exec_prefix,
|
||||
path_config.exec_prefix) < 0) {
|
||||
pathconfig.exec_prefix) < 0) {
|
||||
goto no_memory;
|
||||
}
|
||||
}
|
||||
|
||||
if (path_config.isolated != -1) {
|
||||
config->isolated = path_config.isolated;
|
||||
if (pathconfig.isolated != -1) {
|
||||
config->isolated = pathconfig.isolated;
|
||||
}
|
||||
if (path_config.site_import != -1) {
|
||||
config->site_import = path_config.site_import;
|
||||
if (pathconfig.site_import != -1) {
|
||||
config->site_import = pathconfig.site_import;
|
||||
}
|
||||
|
||||
_PyPathConfig_Clear(&path_config);
|
||||
return _Py_INIT_OK();
|
||||
pathconfig_clear(&pathconfig);
|
||||
return _PyStatus_OK();
|
||||
|
||||
no_memory:
|
||||
err = _Py_INIT_NO_MEMORY();
|
||||
status = _PyStatus_NO_MEMORY();
|
||||
|
||||
error:
|
||||
_PyPathConfig_Clear(&path_config);
|
||||
return err;
|
||||
pathconfig_clear(&pathconfig);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_PyCoreConfig_InitPathConfig(_PyCoreConfig *config)
|
||||
PyStatus
|
||||
_PyConfig_InitPathConfig(PyConfig *config)
|
||||
{
|
||||
/* Do we need to calculate the path? */
|
||||
if (!config->use_module_search_paths
|
||||
if (!config->module_search_paths_set
|
||||
|| (config->executable == NULL)
|
||||
|| (config->prefix == NULL)
|
||||
|| (config->exec_prefix == NULL))
|
||||
{
|
||||
_PyInitError err = _PyCoreConfig_CalculatePathConfig(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
PyStatus status = config_calculate_pathconfig(config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->base_prefix == NULL) {
|
||||
if (copy_wstr(&config->base_prefix, config->prefix) < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
}
|
||||
|
||||
if (config->base_exec_prefix == NULL) {
|
||||
if (copy_wstr(&config->base_exec_prefix,
|
||||
config->exec_prefix) < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -381,26 +379,26 @@ pathconfig_global_init(void)
|
|||
return;
|
||||
}
|
||||
|
||||
_PyInitError err;
|
||||
_PyCoreConfig config;
|
||||
_PyCoreConfig_InitCompatConfig(&config);
|
||||
PyStatus status;
|
||||
PyConfig config;
|
||||
_PyConfig_InitCompatConfig(&config);
|
||||
|
||||
err = _PyCoreConfig_Read(&config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = PyConfig_Read(&config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = _PyCoreConfig_SetPathConfig(&config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = _PyConfig_SetPathConfig(&config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
_PyCoreConfig_Clear(&config);
|
||||
PyConfig_Clear(&config);
|
||||
return;
|
||||
|
||||
error:
|
||||
_PyCoreConfig_Clear(&config);
|
||||
_Py_ExitInitError(err);
|
||||
PyConfig_Clear(&config);
|
||||
Py_ExitStatusException(status);
|
||||
}
|
||||
|
||||
|
||||
|
@ -410,7 +408,7 @@ void
|
|||
Py_SetPath(const wchar_t *path)
|
||||
{
|
||||
if (path == NULL) {
|
||||
_PyPathConfig_Clear(&_Py_path_config);
|
||||
pathconfig_clear(&_Py_path_config);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -437,7 +435,7 @@ Py_SetPath(const wchar_t *path)
|
|||
new_config.program_name = _Py_path_config.program_name;
|
||||
_Py_path_config.program_name = NULL;
|
||||
|
||||
_PyPathConfig_Clear(&_Py_path_config);
|
||||
pathconfig_clear(&_Py_path_config);
|
||||
_Py_path_config = new_config;
|
||||
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
@ -569,9 +567,9 @@ Py_GetProgramName(void)
|
|||
Raise an exception and return -1 on error.
|
||||
*/
|
||||
int
|
||||
_PyPathConfig_ComputeSysPath0(const _PyWstrList *argv, PyObject **path0_p)
|
||||
_PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p)
|
||||
{
|
||||
assert(_PyWstrList_CheckConsistency(argv));
|
||||
assert(_PyWideStringList_CheckConsistency(argv));
|
||||
|
||||
if (argv->length == 0) {
|
||||
/* Leave sys.path unchanged if sys.argv is empty */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#include "pycore_getopt.h"
|
||||
#include "pycore_pystate.h" /* _PyRuntime_Initialize() */
|
||||
#include <locale.h> /* setlocale() */
|
||||
|
@ -7,8 +7,13 @@
|
|||
|
||||
#define DECODE_LOCALE_ERR(NAME, LEN) \
|
||||
(((LEN) == -2) \
|
||||
? _Py_INIT_ERR("cannot decode " NAME) \
|
||||
: _Py_INIT_NO_MEMORY())
|
||||
? _PyStatus_ERR("cannot decode " NAME) \
|
||||
: _PyStatus_NO_MEMORY())
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
static void
|
||||
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2);
|
||||
|
||||
|
||||
/* --- File system encoding/errors -------------------------------- */
|
||||
|
@ -67,22 +72,22 @@ _Py_SetFileSystemEncoding(const char *encoding, const char *errors)
|
|||
/* --- _PyArgv ---------------------------------------------------- */
|
||||
|
||||
/* Decode bytes_argv using Py_DecodeLocale() */
|
||||
_PyInitError
|
||||
_PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
|
||||
PyStatus
|
||||
_PyArgv_AsWstrList(const _PyArgv *args, PyWideStringList *list)
|
||||
{
|
||||
_PyWstrList wargv = _PyWstrList_INIT;
|
||||
PyWideStringList wargv = PyWideStringList_INIT;
|
||||
if (args->use_bytes_argv) {
|
||||
size_t size = sizeof(wchar_t*) * args->argc;
|
||||
wargv.items = (wchar_t **)PyMem_RawMalloc(size);
|
||||
if (wargv.items == NULL) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
||||
for (Py_ssize_t i = 0; i < args->argc; i++) {
|
||||
size_t len;
|
||||
wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len);
|
||||
if (arg == NULL) {
|
||||
_PyWstrList_Clear(&wargv);
|
||||
_PyWideStringList_Clear(&wargv);
|
||||
return DECODE_LOCALE_ERR("command line arguments",
|
||||
(Py_ssize_t)len);
|
||||
}
|
||||
|
@ -90,17 +95,17 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
|
|||
wargv.length++;
|
||||
}
|
||||
|
||||
_PyWstrList_Clear(list);
|
||||
_PyWideStringList_Clear(list);
|
||||
*list = wargv;
|
||||
}
|
||||
else {
|
||||
wargv.length = args->argc;
|
||||
wargv.items = (wchar_t **)args->wchar_argv;
|
||||
if (_PyWstrList_Copy(list, &wargv) < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
if (_PyWideStringList_Copy(list, &wargv) < 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,12 +114,12 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
|
|||
void
|
||||
_PyPreCmdline_Clear(_PyPreCmdline *cmdline)
|
||||
{
|
||||
_PyWstrList_Clear(&cmdline->argv);
|
||||
_PyWstrList_Clear(&cmdline->xoptions);
|
||||
_PyWideStringList_Clear(&cmdline->argv);
|
||||
_PyWideStringList_Clear(&cmdline->xoptions);
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
|
||||
{
|
||||
return _PyArgv_AsWstrList(args, &cmdline->argv);
|
||||
|
@ -122,7 +127,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
|
|||
|
||||
|
||||
static void
|
||||
_PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
|
||||
precmdline_get_preconfig(_PyPreCmdline *cmdline, const PyPreConfig *config)
|
||||
{
|
||||
#define COPY_ATTR(ATTR) \
|
||||
if (config->ATTR != -1) { \
|
||||
|
@ -138,7 +143,7 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
|
|||
|
||||
|
||||
static void
|
||||
_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
|
||||
precmdline_set_preconfig(const _PyPreCmdline *cmdline, PyPreConfig *config)
|
||||
{
|
||||
#define COPY_ATTR(ATTR) \
|
||||
config->ATTR = cmdline->ATTR
|
||||
|
@ -151,33 +156,34 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config)
|
||||
PyStatus
|
||||
_PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config)
|
||||
{
|
||||
#define COPY_ATTR(ATTR) \
|
||||
config->ATTR = cmdline->ATTR
|
||||
|
||||
if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) {
|
||||
return -1;
|
||||
PyStatus status = _PyWideStringList_Extend(&config->xoptions, &cmdline->xoptions);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
COPY_ATTR(isolated);
|
||||
COPY_ATTR(use_environment);
|
||||
COPY_ATTR(dev_mode);
|
||||
return 0;
|
||||
return _PyStatus_OK();
|
||||
|
||||
#undef COPY_ATTR
|
||||
}
|
||||
|
||||
|
||||
/* Parse the command line arguments */
|
||||
static _PyInitError
|
||||
static PyStatus
|
||||
precmdline_parse_cmdline(_PyPreCmdline *cmdline)
|
||||
{
|
||||
const _PyWstrList *argv = &cmdline->argv;
|
||||
const PyWideStringList *argv = &cmdline->argv;
|
||||
|
||||
_PyOS_ResetGetOpt();
|
||||
/* Don't log parsing errors into stderr here: _PyCoreConfig_Read()
|
||||
/* Don't log parsing errors into stderr here: PyConfig_Read()
|
||||
is responsible for that */
|
||||
_PyOS_opterr = 0;
|
||||
do {
|
||||
|
@ -199,32 +205,34 @@ precmdline_parse_cmdline(_PyPreCmdline *cmdline)
|
|||
|
||||
case 'X':
|
||||
{
|
||||
if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
PyStatus status = PyWideStringList_Append(&cmdline->xoptions,
|
||||
_PyOS_optarg);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
/* ignore other argument:
|
||||
handled by _PyCoreConfig_Read() */
|
||||
handled by PyConfig_Read() */
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
|
||||
PyStatus
|
||||
_PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
|
||||
{
|
||||
_PyPreCmdline_GetPreConfig(cmdline, preconfig);
|
||||
precmdline_get_preconfig(cmdline, preconfig);
|
||||
|
||||
if (preconfig->parse_argv) {
|
||||
_PyInitError err = precmdline_parse_cmdline(cmdline);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
PyStatus status = precmdline_parse_cmdline(cmdline);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,15 +262,15 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
|
|||
assert(cmdline->isolated >= 0);
|
||||
assert(cmdline->dev_mode >= 0);
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
/* --- _PyPreConfig ----------------------------------------------- */
|
||||
/* --- PyPreConfig ----------------------------------------------- */
|
||||
|
||||
|
||||
void
|
||||
_PyPreConfig_InitCompatConfig(_PyPreConfig *config)
|
||||
_PyPreConfig_InitCompatConfig(PyPreConfig *config)
|
||||
{
|
||||
memset(config, 0, sizeof(*config));
|
||||
|
||||
|
@ -291,7 +299,7 @@ _PyPreConfig_InitCompatConfig(_PyPreConfig *config)
|
|||
|
||||
|
||||
void
|
||||
_PyPreConfig_InitPythonConfig(_PyPreConfig *config)
|
||||
PyPreConfig_InitPythonConfig(PyPreConfig *config)
|
||||
{
|
||||
_PyPreConfig_InitCompatConfig(config);
|
||||
|
||||
|
@ -312,7 +320,7 @@ _PyPreConfig_InitPythonConfig(_PyPreConfig *config)
|
|||
|
||||
|
||||
void
|
||||
_PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
|
||||
PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
|
||||
{
|
||||
_PyPreConfig_InitCompatConfig(config);
|
||||
|
||||
|
@ -329,37 +337,37 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
|
|||
|
||||
|
||||
void
|
||||
_PyPreConfig_InitFromPreConfig(_PyPreConfig *config,
|
||||
const _PyPreConfig *config2)
|
||||
_PyPreConfig_InitFromPreConfig(PyPreConfig *config,
|
||||
const PyPreConfig *config2)
|
||||
{
|
||||
_PyPreConfig_InitCompatConfig(config);
|
||||
_PyPreConfig_Copy(config, config2);
|
||||
PyPreConfig_InitPythonConfig(config);
|
||||
preconfig_copy(config, config2);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_PyPreConfig_InitFromCoreConfig(_PyPreConfig *config,
|
||||
const _PyCoreConfig *coreconfig)
|
||||
_PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config)
|
||||
{
|
||||
_PyConfigInitEnum config_init = (_PyConfigInitEnum)coreconfig->_config_init;
|
||||
_PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init;
|
||||
switch (config_init) {
|
||||
case _PyConfig_INIT_PYTHON:
|
||||
_PyPreConfig_InitPythonConfig(config);
|
||||
PyPreConfig_InitPythonConfig(preconfig);
|
||||
break;
|
||||
case _PyConfig_INIT_ISOLATED:
|
||||
_PyPreConfig_InitIsolatedConfig(config);
|
||||
PyPreConfig_InitIsolatedConfig(preconfig);
|
||||
break;
|
||||
case _PyConfig_INIT_COMPAT:
|
||||
default:
|
||||
_PyPreConfig_InitCompatConfig(config);
|
||||
_PyPreConfig_InitCompatConfig(preconfig);
|
||||
}
|
||||
_PyPreConfig_GetCoreConfig(config, coreconfig);
|
||||
_PyPreConfig_GetConfig(preconfig, config);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
|
||||
static void
|
||||
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
|
||||
{
|
||||
assert(config2->_config_version == _Py_CONFIG_VERSION);
|
||||
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
|
||||
|
||||
COPY_ATTR(_config_init);
|
||||
|
@ -381,7 +389,7 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
|
|||
|
||||
|
||||
PyObject*
|
||||
_PyPreConfig_AsDict(const _PyPreConfig *config)
|
||||
_PyPreConfig_AsDict(const PyPreConfig *config)
|
||||
{
|
||||
PyObject *dict;
|
||||
|
||||
|
@ -427,12 +435,11 @@ fail:
|
|||
|
||||
|
||||
void
|
||||
_PyPreConfig_GetCoreConfig(_PyPreConfig *config,
|
||||
const _PyCoreConfig *core_config)
|
||||
_PyPreConfig_GetConfig(PyPreConfig *preconfig, const PyConfig *config)
|
||||
{
|
||||
#define COPY_ATTR(ATTR) \
|
||||
if (core_config->ATTR != -1) { \
|
||||
config->ATTR = core_config->ATTR; \
|
||||
if (config->ATTR != -1) { \
|
||||
preconfig->ATTR = config->ATTR; \
|
||||
}
|
||||
|
||||
COPY_ATTR(parse_argv);
|
||||
|
@ -445,7 +452,7 @@ _PyPreConfig_GetCoreConfig(_PyPreConfig *config,
|
|||
|
||||
|
||||
static void
|
||||
_PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
|
||||
preconfig_get_global_vars(PyPreConfig *config)
|
||||
{
|
||||
if (config->_config_init != _PyConfig_INIT_COMPAT) {
|
||||
/* Python and Isolated configuration ignore global variables */
|
||||
|
@ -476,7 +483,7 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
|
|||
|
||||
|
||||
static void
|
||||
_PyPreConfig_SetGlobalConfig(const _PyPreConfig *config)
|
||||
preconfig_set_global_vars(const PyPreConfig *config)
|
||||
{
|
||||
#define COPY_FLAG(ATTR, VAR) \
|
||||
if (config->ATTR >= 0) { \
|
||||
|
@ -555,7 +562,7 @@ _Py_get_env_flag(int use_environment, int *flag, const char *name)
|
|||
|
||||
|
||||
const wchar_t*
|
||||
_Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
|
||||
_Py_get_xoption(const PyWideStringList *xoptions, const wchar_t *name)
|
||||
{
|
||||
for (Py_ssize_t i=0; i < xoptions->length; i++) {
|
||||
const wchar_t *option = xoptions->items[i];
|
||||
|
@ -575,8 +582,8 @@ _Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
|
|||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
|
||||
static PyStatus
|
||||
preconfig_init_utf8_mode(PyPreConfig *config, const _PyPreCmdline *cmdline)
|
||||
{
|
||||
#ifdef MS_WINDOWS
|
||||
if (config->legacy_windows_fs_encoding) {
|
||||
|
@ -585,7 +592,7 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
|
|||
#endif
|
||||
|
||||
if (config->utf8_mode >= 0) {
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
const wchar_t *xopt;
|
||||
|
@ -601,13 +608,13 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
|
|||
config->utf8_mode = 0;
|
||||
}
|
||||
else {
|
||||
return _Py_INIT_ERR("invalid -X utf8 option value");
|
||||
return _PyStatus_ERR("invalid -X utf8 option value");
|
||||
}
|
||||
}
|
||||
else {
|
||||
config->utf8_mode = 1;
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
const char *opt = _Py_GetEnv(config->use_environment, "PYTHONUTF8");
|
||||
|
@ -619,10 +626,10 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
|
|||
config->utf8_mode = 0;
|
||||
}
|
||||
else {
|
||||
return _Py_INIT_ERR("invalid PYTHONUTF8 environment "
|
||||
return _PyStatus_ERR("invalid PYTHONUTF8 environment "
|
||||
"variable value");
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -642,12 +649,12 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
|
|||
if (config->utf8_mode < 0) {
|
||||
config->utf8_mode = 0;
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
preconfig_init_coerce_c_locale(_PyPreConfig *config)
|
||||
preconfig_init_coerce_c_locale(PyPreConfig *config)
|
||||
{
|
||||
if (!config->configure_locale) {
|
||||
config->coerce_c_locale = 0;
|
||||
|
@ -693,8 +700,8 @@ preconfig_init_coerce_c_locale(_PyPreConfig *config)
|
|||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
preconfig_init_allocator(_PyPreConfig *config)
|
||||
static PyStatus
|
||||
preconfig_init_allocator(PyPreConfig *config)
|
||||
{
|
||||
if (config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
|
||||
/* bpo-34247. The PYTHONMALLOC environment variable has the priority
|
||||
|
@ -705,7 +712,7 @@ preconfig_init_allocator(_PyPreConfig *config)
|
|||
if (envvar) {
|
||||
PyMemAllocatorName name;
|
||||
if (_PyMem_GetAllocatorName(envvar, &name) < 0) {
|
||||
return _Py_INIT_ERR("PYTHONMALLOC: unknown allocator");
|
||||
return _PyStatus_ERR("PYTHONMALLOC: unknown allocator");
|
||||
}
|
||||
config->allocator = (int)name;
|
||||
}
|
||||
|
@ -714,21 +721,21 @@ preconfig_init_allocator(_PyPreConfig *config)
|
|||
if (config->dev_mode && config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
|
||||
config->allocator = PYMEM_ALLOCATOR_DEBUG;
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
|
||||
static PyStatus
|
||||
preconfig_read(PyPreConfig *config, _PyPreCmdline *cmdline)
|
||||
{
|
||||
_PyInitError err;
|
||||
PyStatus status;
|
||||
|
||||
err = _PyPreCmdline_Read(cmdline, config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
status = _PyPreCmdline_Read(cmdline, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
_PyPreCmdline_SetPreConfig(cmdline, config);
|
||||
precmdline_set_preconfig(cmdline, config);
|
||||
|
||||
/* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */
|
||||
#ifdef MS_WINDOWS
|
||||
|
@ -739,15 +746,15 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
|
|||
|
||||
preconfig_init_coerce_c_locale(config);
|
||||
|
||||
err = preconfig_init_utf8_mode(config, cmdline);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
status = preconfig_init_utf8_mode(config, cmdline);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* allocator */
|
||||
err = preconfig_init_allocator(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
status = preconfig_init_allocator(config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
assert(config->coerce_c_locale >= 0);
|
||||
|
@ -760,7 +767,7 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
|
|||
assert(config->use_environment >= 0);
|
||||
assert(config->dev_mode >= 0);
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -770,30 +777,30 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
|
|||
- environment variables
|
||||
- Py_xxx global configuration variables
|
||||
- the LC_CTYPE locale */
|
||||
_PyInitError
|
||||
_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
|
||||
PyStatus
|
||||
_PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
|
||||
{
|
||||
_PyInitError err;
|
||||
PyStatus status;
|
||||
|
||||
err = _PyRuntime_Initialize();
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
status = _PyRuntime_Initialize();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
_PyPreConfig_GetGlobalConfig(config);
|
||||
preconfig_get_global_vars(config);
|
||||
|
||||
/* Copy LC_CTYPE locale, since it's modified later */
|
||||
const char *loc = setlocale(LC_CTYPE, NULL);
|
||||
if (loc == NULL) {
|
||||
return _Py_INIT_ERR("failed to LC_CTYPE locale");
|
||||
return _PyStatus_ERR("failed to LC_CTYPE locale");
|
||||
}
|
||||
char *init_ctype_locale = _PyMem_RawStrdup(loc);
|
||||
if (init_ctype_locale == NULL) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
||||
/* Save the config to be able to restore it if encodings change */
|
||||
_PyPreConfig save_config;
|
||||
PyPreConfig save_config;
|
||||
_PyPreConfig_InitFromPreConfig(&save_config, config);
|
||||
|
||||
/* Set LC_CTYPE to the user preferred locale */
|
||||
|
@ -808,8 +815,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
|
|||
#endif
|
||||
|
||||
if (args) {
|
||||
err = _PyPreCmdline_SetArgv(&cmdline, args);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = _PyPreCmdline_SetArgv(&cmdline, args);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
@ -823,7 +830,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
|
|||
/* Watchdog to prevent an infinite loop */
|
||||
loops++;
|
||||
if (loops == 3) {
|
||||
err = _Py_INIT_ERR("Encoding changed twice while "
|
||||
status = _PyStatus_ERR("Encoding changed twice while "
|
||||
"reading the configuration");
|
||||
goto done;
|
||||
}
|
||||
|
@ -835,8 +842,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
|
|||
Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
|
||||
#endif
|
||||
|
||||
err = preconfig_read(config, &cmdline);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
status = preconfig_read(config, &cmdline);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -877,14 +884,14 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
|
|||
just keep UTF-8 Mode value. */
|
||||
int new_utf8_mode = config->utf8_mode;
|
||||
int new_coerce_c_locale = config->coerce_c_locale;
|
||||
_PyPreConfig_Copy(config, &save_config);
|
||||
preconfig_copy(config, &save_config);
|
||||
config->utf8_mode = new_utf8_mode;
|
||||
config->coerce_c_locale = new_coerce_c_locale;
|
||||
|
||||
/* The encoding changed: read again the configuration
|
||||
with the new encoding */
|
||||
}
|
||||
err = _Py_INIT_OK();
|
||||
status = _PyStatus_OK();
|
||||
|
||||
done:
|
||||
if (init_ctype_locale != NULL) {
|
||||
|
@ -896,7 +903,7 @@ done:
|
|||
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
|
||||
#endif
|
||||
_PyPreCmdline_Clear(&cmdline);
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -912,26 +919,26 @@ done:
|
|||
|
||||
Do nothing if called after Py_Initialize(): ignore the new
|
||||
pre-configuration. */
|
||||
_PyInitError
|
||||
_PyPreConfig_Write(const _PyPreConfig *src_config)
|
||||
PyStatus
|
||||
_PyPreConfig_Write(const PyPreConfig *src_config)
|
||||
{
|
||||
_PyPreConfig config;
|
||||
PyPreConfig config;
|
||||
_PyPreConfig_InitFromPreConfig(&config, src_config);
|
||||
|
||||
if (_PyRuntime.core_initialized) {
|
||||
/* bpo-34008: Calling this functions after Py_Initialize() ignores
|
||||
the new configuration. */
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
PyMemAllocatorName name = (PyMemAllocatorName)config.allocator;
|
||||
if (name != PYMEM_ALLOCATOR_NOT_SET) {
|
||||
if (_PyMem_SetupAllocators(name) < 0) {
|
||||
return _Py_INIT_ERR("Unknown PYTHONMALLOC allocator");
|
||||
return _PyStatus_ERR("Unknown PYTHONMALLOC allocator");
|
||||
}
|
||||
}
|
||||
|
||||
_PyPreConfig_SetGlobalConfig(&config);
|
||||
preconfig_set_global_vars(&config);
|
||||
|
||||
if (config.configure_locale) {
|
||||
if (config.coerce_c_locale) {
|
||||
|
@ -946,7 +953,7 @@ _PyPreConfig_Write(const _PyPreConfig *src_config)
|
|||
}
|
||||
|
||||
/* Write the new pre-configuration into _PyRuntime */
|
||||
_PyPreConfig_Copy(&_PyRuntime.preconfig, &config);
|
||||
preconfig_copy(&_PyRuntime.preconfig, &config);
|
||||
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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,
|
||||
|
|
|
@ -94,7 +94,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
|
|||
PyCompilerFlags local_flags;
|
||||
int nomem_count = 0;
|
||||
#ifdef Py_REF_DEBUG
|
||||
int show_ref_count = _PyInterpreterState_Get()->core_config.show_ref_count;
|
||||
int show_ref_count = _PyInterpreterState_Get()->config.show_ref_count;
|
||||
#endif
|
||||
|
||||
filename = PyUnicode_DecodeFSDefault(filename_str);
|
||||
|
@ -584,7 +584,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
|
|||
int
|
||||
_Py_HandleSystemExit(int *exitcode_p)
|
||||
{
|
||||
int inspect = _PyInterpreterState_GET_UNSAFE()->core_config.inspect;
|
||||
int inspect = _PyInterpreterState_GET_UNSAFE()->config.inspect;
|
||||
if (inspect) {
|
||||
/* Don't exit if -i flag was given. This flag is set to 0
|
||||
* when entering interactive mode for inspecting. */
|
||||
|
|
|
@ -17,7 +17,7 @@ Data members:
|
|||
#include "Python.h"
|
||||
#include "code.h"
|
||||
#include "frameobject.h"
|
||||
#include "pycore_coreconfig.h"
|
||||
#include "pycore_initconfig.h"
|
||||
#include "pycore_pylifecycle.h"
|
||||
#include "pycore_pymem.h"
|
||||
#include "pycore_pathconfig.h"
|
||||
|
@ -752,7 +752,7 @@ sys_getfilesystemencoding_impl(PyObject *module)
|
|||
/*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
const PyConfig *config = &interp->config;
|
||||
return PyUnicode_FromWideChar(config->filesystem_encoding, -1);
|
||||
}
|
||||
|
||||
|
@ -767,7 +767,7 @@ sys_getfilesystemencodeerrors_impl(PyObject *module)
|
|||
/*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
const PyConfig *config = &interp->config;
|
||||
return PyUnicode_FromWideChar(config->filesystem_errors, -1);
|
||||
}
|
||||
|
||||
|
@ -2475,8 +2475,8 @@ make_flags(_PyRuntimeState *runtime, PyInterpreterState *interp)
|
|||
{
|
||||
int pos = 0;
|
||||
PyObject *seq;
|
||||
const _PyPreConfig *preconfig = &runtime->preconfig;
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
const PyPreConfig *preconfig = &runtime->preconfig;
|
||||
const PyConfig *config = &interp->config;
|
||||
|
||||
seq = PyStructSequence_New(&FlagsType);
|
||||
if (seq == NULL)
|
||||
|
@ -2690,7 +2690,7 @@ static struct PyModuleDef sysmodule = {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
static _PyInitError
|
||||
static PyStatus
|
||||
_PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
|
||||
PyObject *sysdict)
|
||||
{
|
||||
|
@ -2827,13 +2827,13 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
|
|||
if (PyErr_Occurred()) {
|
||||
goto err_occurred;
|
||||
}
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
|
||||
type_init_failed:
|
||||
return _Py_INIT_ERR("failed to initialize a type");
|
||||
return _PyStatus_ERR("failed to initialize a type");
|
||||
|
||||
err_occurred:
|
||||
return _Py_INIT_ERR("can't initialize sys module");
|
||||
return _PyStatus_ERR("can't initialize sys module");
|
||||
}
|
||||
|
||||
#undef SET_SYS_FROM_STRING
|
||||
|
@ -2885,7 +2885,7 @@ error:
|
|||
|
||||
|
||||
static PyObject*
|
||||
sys_create_xoptions_dict(const _PyCoreConfig *config)
|
||||
sys_create_xoptions_dict(const PyConfig *config)
|
||||
{
|
||||
Py_ssize_t nxoption = config->xoptions.length;
|
||||
wchar_t * const * xoptions = config->xoptions.items;
|
||||
|
@ -2910,12 +2910,12 @@ int
|
|||
_PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
|
||||
{
|
||||
PyObject *sysdict = interp->sysdict;
|
||||
const _PyCoreConfig *config = &interp->core_config;
|
||||
const PyConfig *config = &interp->config;
|
||||
int res;
|
||||
|
||||
#define COPY_LIST(KEY, VALUE) \
|
||||
do { \
|
||||
PyObject *list = _PyWstrList_AsList(&(VALUE)); \
|
||||
PyObject *list = _PyWideStringList_AsList(&(VALUE)); \
|
||||
if (list == NULL) { \
|
||||
return -1; \
|
||||
} \
|
||||
|
@ -3003,7 +3003,7 @@ err_occurred:
|
|||
infrastructure for the io module in place.
|
||||
|
||||
Use UTF-8/surrogateescape and ignore EAGAIN errors. */
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PySys_SetPreliminaryStderr(PyObject *sysdict)
|
||||
{
|
||||
PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr));
|
||||
|
@ -3017,56 +3017,56 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict)
|
|||
goto error;
|
||||
}
|
||||
Py_DECREF(pstderr);
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
|
||||
error:
|
||||
Py_XDECREF(pstderr);
|
||||
return _Py_INIT_ERR("can't set preliminary stderr");
|
||||
return _PyStatus_ERR("can't set preliminary stderr");
|
||||
}
|
||||
|
||||
|
||||
/* Create sys module without all attributes: _PySys_InitMain() should be called
|
||||
later to add remaining attributes. */
|
||||
_PyInitError
|
||||
PyStatus
|
||||
_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
|
||||
PyObject **sysmod_p)
|
||||
{
|
||||
PyObject *modules = PyDict_New();
|
||||
if (modules == NULL) {
|
||||
return _Py_INIT_ERR("can't make modules dictionary");
|
||||
return _PyStatus_ERR("can't make modules dictionary");
|
||||
}
|
||||
interp->modules = modules;
|
||||
|
||||
PyObject *sysmod = _PyModule_CreateInitialized(&sysmodule, PYTHON_API_VERSION);
|
||||
if (sysmod == NULL) {
|
||||
return _Py_INIT_ERR("failed to create a module object");
|
||||
return _PyStatus_ERR("failed to create a module object");
|
||||
}
|
||||
|
||||
PyObject *sysdict = PyModule_GetDict(sysmod);
|
||||
if (sysdict == NULL) {
|
||||
return _Py_INIT_ERR("can't initialize sys dict");
|
||||
return _PyStatus_ERR("can't initialize sys dict");
|
||||
}
|
||||
Py_INCREF(sysdict);
|
||||
interp->sysdict = sysdict;
|
||||
|
||||
if (PyDict_SetItemString(sysdict, "modules", interp->modules) < 0) {
|
||||
return _Py_INIT_ERR("can't initialize sys module");
|
||||
return _PyStatus_ERR("can't initialize sys module");
|
||||
}
|
||||
|
||||
_PyInitError err = _PySys_SetPreliminaryStderr(sysdict);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
PyStatus status = _PySys_SetPreliminaryStderr(sysdict);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
err = _PySys_InitCore(runtime, interp, sysdict);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
status = _PySys_InitCore(runtime, interp, sysdict);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
_PyImport_FixupBuiltin(sysmod, "sys", interp->modules);
|
||||
|
||||
*sysmod_p = sysmod;
|
||||
return _Py_INIT_OK();
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -3156,7 +3156,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
|
|||
if (updatepath) {
|
||||
/* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path.
|
||||
If argv[0] is a symlink, use the real path. */
|
||||
const _PyWstrList argv_list = {.length = argc, .items = argv};
|
||||
const PyWideStringList argv_list = {.length = argc, .items = argv};
|
||||
PyObject *path0 = NULL;
|
||||
if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) {
|
||||
if (path0 == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue