summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-27 14:39:22 (GMT)
committerGitHub <noreply@github.com>2019-05-27 14:39:22 (GMT)
commit331a6a56e9a9c72f3e4605987fabdaec72677702 (patch)
tree49d20cedd9df4371f2410b2fb24255535ca02c50 /Python
parent8cd5165ba05ff57cfdbbc71c393bddad1ce1ab87 (diff)
downloadcpython-331a6a56e9a9c72f3e4605987fabdaec72677702.zip
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.gz
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.bz2
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()
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c2
-rw-r--r--Python/bootstrap_hash.c12
-rw-r--r--Python/compile.c4
-rw-r--r--Python/dynload_hpux.c2
-rw-r--r--Python/errors.c8
-rw-r--r--Python/frozenmain.c24
-rw-r--r--Python/import.c30
-rw-r--r--Python/initconfig.c (renamed from Python/coreconfig.c)916
-rw-r--r--Python/pathconfig.c214
-rw-r--r--Python/preconfig.c235
-rw-r--r--Python/pylifecycle.c689
-rw-r--r--Python/pystate.c41
-rw-r--r--Python/pythonrun.c4
-rw-r--r--Python/sysmodule.c56
14 files changed, 1106 insertions, 1131 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index ff5a512..5d58085 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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 ||
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
index fe71cc3..43f5264 100644
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -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();
}
diff --git a/Python/compile.c b/Python/compile.c
index 734e840..425d0d6 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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");
}
diff --git a/Python/dynload_hpux.c b/Python/dynload_hpux.c
index f275e53..da9baa4 100644
--- a/Python/dynload_hpux.c
+++ b/Python/dynload_hpux.c
@@ -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;
diff --git a/Python/errors.c b/Python/errors.c
index 831f111..bd33d4d 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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();
}
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index c3af080..c56938a 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -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
diff --git a/Python/import.c b/Python/import.c
index ec172b2..41a5c01 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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;
diff --git a/Python/coreconfig.c b/Python/initconfig.c
index 89ccff4..66b1b30 100644
--- a/Python/coreconfig.c
+++ b/Python/initconfig.c
@@ -1,6 +1,6 @@
#include "Python.h"
#include "osdefs.h" /* DELIM */
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
#include "pycore_fileutils.h"
#include "pycore_getopt.h"
#include "pycore_pylifecycle.h"
@@ -202,39 +202,39 @@ fail:
}
-/* --- _PyInitError ----------------------------------------------- */
+/* --- PyStatus ----------------------------------------------- */
-_PyInitError _PyInitError_Ok(void)
-{ return _Py_INIT_OK(); }
+PyStatus PyStatus_Ok(void)
+{ return _PyStatus_OK(); }
-_PyInitError _PyInitError_Error(const char *err_msg)
+PyStatus PyStatus_Error(const char *err_msg)
{
- return (_PyInitError){._type = _Py_INIT_ERR_TYPE_ERROR,
+ return (PyStatus){._type = _PyStatus_TYPE_ERROR,
.err_msg = err_msg};
}
-_PyInitError _PyInitError_NoMemory(void)
-{ return _PyInitError_Error("memory allocation failed"); }
+PyStatus PyStatus_NoMemory(void)
+{ return PyStatus_Error("memory allocation failed"); }
-_PyInitError _PyInitError_Exit(int exitcode)
-{ return _Py_INIT_EXIT(exitcode); }
+PyStatus PyStatus_Exit(int exitcode)
+{ return _PyStatus_EXIT(exitcode); }
-int _PyInitError_IsError(_PyInitError err)
-{ return _Py_INIT_IS_ERROR(err); }
+int PyStatus_IsError(PyStatus status)
+{ return _PyStatus_IS_ERROR(status); }
-int _PyInitError_IsExit(_PyInitError err)
-{ return _Py_INIT_IS_EXIT(err); }
+int PyStatus_IsExit(PyStatus status)
+{ return _PyStatus_IS_EXIT(status); }
-int _PyInitError_Failed(_PyInitError err)
-{ return _Py_INIT_FAILED(err); }
+int PyStatus_Exception(PyStatus status)
+{ return _PyStatus_EXCEPTION(status); }
-/* --- _PyWstrList ------------------------------------------------ */
+/* --- PyWideStringList ------------------------------------------------ */
#ifndef NDEBUG
int
-_PyWstrList_CheckConsistency(const _PyWstrList *list)
+_PyWideStringList_CheckConsistency(const PyWideStringList *list)
{
assert(list->length >= 0);
if (list->length != 0) {
@@ -249,9 +249,9 @@ _PyWstrList_CheckConsistency(const _PyWstrList *list)
void
-_PyWstrList_Clear(_PyWstrList *list)
+_PyWideStringList_Clear(PyWideStringList *list)
{
- assert(_PyWstrList_CheckConsistency(list));
+ assert(_PyWideStringList_CheckConsistency(list));
for (Py_ssize_t i=0; i < list->length; i++) {
PyMem_RawFree(list->items[i]);
}
@@ -262,17 +262,17 @@ _PyWstrList_Clear(_PyWstrList *list)
int
-_PyWstrList_Copy(_PyWstrList *list, const _PyWstrList *list2)
+_PyWideStringList_Copy(PyWideStringList *list, const PyWideStringList *list2)
{
- assert(_PyWstrList_CheckConsistency(list));
- assert(_PyWstrList_CheckConsistency(list2));
+ assert(_PyWideStringList_CheckConsistency(list));
+ assert(_PyWideStringList_CheckConsistency(list2));
if (list2->length == 0) {
- _PyWstrList_Clear(list);
+ _PyWideStringList_Clear(list);
return 0;
}
- _PyWstrList copy = _PyWstrList_INIT;
+ PyWideStringList copy = PyWideStringList_INIT;
size_t size = list2->length * sizeof(list2->items[0]);
copy.items = PyMem_RawMalloc(size);
@@ -283,60 +283,61 @@ _PyWstrList_Copy(_PyWstrList *list, const _PyWstrList *list2)
for (Py_ssize_t i=0; i < list2->length; i++) {
wchar_t *item = _PyMem_RawWcsdup(list2->items[i]);
if (item == NULL) {
- _PyWstrList_Clear(&copy);
+ _PyWideStringList_Clear(&copy);
return -1;
}
copy.items[i] = item;
copy.length = i + 1;
}
- _PyWstrList_Clear(list);
+ _PyWideStringList_Clear(list);
*list = copy;
return 0;
}
-int
-_PyWstrList_Append(_PyWstrList *list, const wchar_t *item)
+PyStatus
+PyWideStringList_Append(PyWideStringList *list, const wchar_t *item)
{
if (list->length == PY_SSIZE_T_MAX) {
/* lenght+1 would overflow */
- return -1;
+ return _PyStatus_NO_MEMORY();
}
wchar_t *item2 = _PyMem_RawWcsdup(item);
if (item2 == NULL) {
- return -1;
+ return _PyStatus_NO_MEMORY();
}
size_t size = (list->length + 1) * sizeof(list->items[0]);
wchar_t **items2 = (wchar_t **)PyMem_RawRealloc(list->items, size);
if (items2 == NULL) {
PyMem_RawFree(item2);
- return -1;
+ return _PyStatus_NO_MEMORY();
}
items2[list->length] = item2;
list->items = items2;
list->length++;
- return 0;
+ return _PyStatus_OK();
}
-int
-_PyWstrList_Extend(_PyWstrList *list, const _PyWstrList *list2)
+PyStatus
+_PyWideStringList_Extend(PyWideStringList *list, const PyWideStringList *list2)
{
for (Py_ssize_t i = 0; i < list2->length; i++) {
- if (_PyWstrList_Append(list, list2->items[i])) {
- return -1;
+ PyStatus status = PyWideStringList_Append(list, list2->items[i]);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return 0;
+ return _PyStatus_OK();
}
static int
-_PyWstrList_Find(_PyWstrList *list, const wchar_t *item)
+_PyWideStringList_Find(PyWideStringList *list, const wchar_t *item)
{
for (Py_ssize_t i = 0; i < list->length; i++) {
if (wcscmp(list->items[i], item) == 0) {
@@ -348,9 +349,9 @@ _PyWstrList_Find(_PyWstrList *list, const wchar_t *item)
PyObject*
-_PyWstrList_AsList(const _PyWstrList *list)
+_PyWideStringList_AsList(const PyWideStringList *list)
{
- assert(_PyWstrList_CheckConsistency(list));
+ assert(_PyWideStringList_CheckConsistency(list));
PyObject *pylist = PyList_New(list->length);
if (pylist == NULL) {
@@ -457,7 +458,7 @@ _Py_ClearStandardStreamEncoding(void)
/* --- Py_GetArgcArgv() ------------------------------------------- */
/* For Py_GetArgcArgv(); set by _Py_SetArgcArgv() */
-static _PyWstrList orig_argv = {.length = 0, .items = NULL};
+static PyWideStringList orig_argv = {.length = 0, .items = NULL};
void
@@ -466,7 +467,7 @@ _Py_ClearArgcArgv(void)
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- _PyWstrList_Clear(&orig_argv);
+ _PyWideStringList_Clear(&orig_argv);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}
@@ -475,13 +476,13 @@ _Py_ClearArgcArgv(void)
static int
_Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
{
- const _PyWstrList argv_list = {.length = argc, .items = (wchar_t **)argv};
+ const PyWideStringList argv_list = {.length = argc, .items = (wchar_t **)argv};
int res;
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- res = _PyWstrList_Copy(&orig_argv, &argv_list);
+ res = _PyWideStringList_Copy(&orig_argv, &argv_list);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return res;
@@ -498,16 +499,16 @@ Py_GetArgcArgv(int *argc, wchar_t ***argv)
}
-/* --- _PyCoreConfig ---------------------------------------------- */
+/* --- PyConfig ---------------------------------------------- */
#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())
/* Free memory allocated in config, but don't clear all attributes */
void
-_PyCoreConfig_Clear(_PyCoreConfig *config)
+PyConfig_Clear(PyConfig *config)
{
#define CLEAR(ATTR) \
do { \
@@ -516,15 +517,15 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)
} while (0)
CLEAR(config->pycache_prefix);
- CLEAR(config->module_search_path_env);
+ CLEAR(config->pythonpath_env);
CLEAR(config->home);
CLEAR(config->program_name);
- _PyWstrList_Clear(&config->argv);
- _PyWstrList_Clear(&config->warnoptions);
- _PyWstrList_Clear(&config->xoptions);
- _PyWstrList_Clear(&config->module_search_paths);
- config->use_module_search_paths = 0;
+ _PyWideStringList_Clear(&config->argv);
+ _PyWideStringList_Clear(&config->warnoptions);
+ _PyWideStringList_Clear(&config->xoptions);
+ _PyWideStringList_Clear(&config->module_search_paths);
+ config->module_search_paths_set = 0;
CLEAR(config->executable);
CLEAR(config->prefix);
@@ -545,7 +546,7 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)
void
-_PyCoreConfig_InitCompatConfig(_PyCoreConfig *config)
+_PyConfig_InitCompatConfig(PyConfig *config)
{
memset(config, 0, sizeof(*config));
@@ -558,7 +559,7 @@ _PyCoreConfig_InitCompatConfig(_PyCoreConfig *config)
config->use_hash_seed = -1;
config->faulthandler = -1;
config->tracemalloc = -1;
- config->use_module_search_paths = 0;
+ config->module_search_paths_set = 0;
config->parse_argv = 0;
config->site_import = -1;
config->bytes_warning = -1;
@@ -583,9 +584,9 @@ _PyCoreConfig_InitCompatConfig(_PyCoreConfig *config)
static void
-_PyCoreConfig_InitDefaults(_PyCoreConfig *config)
+config_init_defaults(PyConfig *config)
{
- _PyCoreConfig_InitCompatConfig(config);
+ _PyConfig_InitCompatConfig(config);
config->isolated = 0;
config->use_environment = 1;
@@ -607,23 +608,23 @@ _PyCoreConfig_InitDefaults(_PyCoreConfig *config)
}
-_PyInitError
-_PyCoreConfig_InitPythonConfig(_PyCoreConfig *config)
+PyStatus
+PyConfig_InitPythonConfig(PyConfig *config)
{
- _PyCoreConfig_InitDefaults(config);
+ config_init_defaults(config);
config->_config_init = (int)_PyConfig_INIT_PYTHON;
config->configure_c_stdio = 1;
config->parse_argv = 1;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-_PyInitError
-_PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config)
+PyStatus
+PyConfig_InitIsolatedConfig(PyConfig *config)
{
- _PyCoreConfig_InitDefaults(config);
+ config_init_defaults(config);
config->_config_init = (int)_PyConfig_INIT_ISOLATED;
config->isolated = 1;
@@ -639,25 +640,24 @@ _PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config)
config->legacy_windows_stdio = 0;
#endif
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* Copy str into *config_str (duplicate the string) */
-_PyInitError
-_PyCoreConfig_SetString(_PyCoreConfig *config, wchar_t **config_str,
- const wchar_t *str)
+PyStatus
+PyConfig_SetString(PyConfig *config, wchar_t **config_str, const wchar_t *str)
{
- _PyInitError err = _Py_PreInitializeFromCoreConfig(config, NULL);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _Py_PreInitializeFromConfig(config, NULL);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
wchar_t *str2;
if (str != NULL) {
str2 = _PyMem_RawWcsdup(str);
if (str2 == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
}
else {
@@ -665,17 +665,17 @@ _PyCoreConfig_SetString(_PyCoreConfig *config, wchar_t **config_str,
}
PyMem_RawFree(*config_str);
*config_str = str2;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-_PyCoreConfig_DecodeLocaleErr(_PyCoreConfig *config, wchar_t **config_str,
- const char *str, const char *decode_err_msg)
+static PyStatus
+config_set_bytes_string(PyConfig *config, wchar_t **config_str,
+ const char *str, const char *decode_err_msg)
{
- _PyInitError err = _Py_PreInitializeFromCoreConfig(config, NULL);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _Py_PreInitializeFromConfig(config, NULL);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
wchar_t *str2;
@@ -684,10 +684,10 @@ _PyCoreConfig_DecodeLocaleErr(_PyCoreConfig *config, wchar_t **config_str,
str2 = Py_DecodeLocale(str, &len);
if (str2 == NULL) {
if (len == (size_t)-2) {
- return _Py_INIT_ERR(decode_err_msg);
+ return _PyStatus_ERR(decode_err_msg);
}
else {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
}
}
@@ -696,43 +696,43 @@ _PyCoreConfig_DecodeLocaleErr(_PyCoreConfig *config, wchar_t **config_str,
}
PyMem_RawFree(*config_str);
*config_str = str2;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-#define CONFIG_DECODE_LOCALE(config, config_str, str, NAME) \
- _PyCoreConfig_DecodeLocaleErr(config, config_str, str, "cannot decode " NAME)
+#define CONFIG_SET_BYTES_STR(config, config_str, str, NAME) \
+ config_set_bytes_string(config, config_str, str, "cannot decode " NAME)
/* Decode str using Py_DecodeLocale() and set the result into *config_str.
Pre-initialize Python if needed to ensure that encodings are properly
configured. */
-_PyInitError
-_PyCoreConfig_DecodeLocale(_PyCoreConfig *config, wchar_t **config_str,
+PyStatus
+PyConfig_SetBytesString(PyConfig *config, wchar_t **config_str,
const char *str)
{
- return CONFIG_DECODE_LOCALE(config, config_str, str, "string");
+ return CONFIG_SET_BYTES_STR(config, config_str, str, "string");
}
-_PyInitError
-_PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
+PyStatus
+_PyConfig_Copy(PyConfig *config, const PyConfig *config2)
{
- _PyInitError err;
- _PyCoreConfig_Clear(config);
+ PyStatus status;
+ PyConfig_Clear(config);
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
#define COPY_WSTR_ATTR(ATTR) \
do { \
- err = _PyCoreConfig_SetString(config, &config->ATTR, config2->ATTR); \
- if (_Py_INIT_FAILED(err)) { \
- return err; \
+ status = PyConfig_SetString(config, &config->ATTR, config2->ATTR); \
+ if (_PyStatus_EXCEPTION(status)) { \
+ return status; \
} \
} while (0)
#define COPY_WSTRLIST(LIST) \
do { \
- if (_PyWstrList_Copy(&config->LIST, &config2->LIST) < 0 ) { \
- return _Py_INIT_NO_MEMORY(); \
+ if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0 ) { \
+ return _PyStatus_NO_MEMORY(); \
} \
} while (0)
@@ -753,7 +753,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
COPY_ATTR(malloc_stats);
COPY_WSTR_ATTR(pycache_prefix);
- COPY_WSTR_ATTR(module_search_path_env);
+ COPY_WSTR_ATTR(pythonpath_env);
COPY_WSTR_ATTR(home);
COPY_WSTR_ATTR(program_name);
@@ -762,7 +762,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
COPY_WSTRLIST(warnoptions);
COPY_WSTRLIST(xoptions);
COPY_WSTRLIST(module_search_paths);
- COPY_ATTR(use_module_search_paths);
+ COPY_ATTR(module_search_paths_set);
COPY_WSTR_ATTR(executable);
COPY_WSTR_ATTR(prefix);
@@ -800,12 +800,12 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
#undef COPY_ATTR
#undef COPY_WSTR_ATTR
#undef COPY_WSTRLIST
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
static PyObject *
-_PyCoreConfig_AsDict(const _PyCoreConfig *config)
+config_as_dict(const PyConfig *config)
{
PyObject *dict;
@@ -837,7 +837,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
#define SET_ITEM_WSTR(ATTR) \
SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR))
#define SET_ITEM_WSTRLIST(LIST) \
- SET_ITEM(#LIST, _PyWstrList_AsList(&config->LIST))
+ SET_ITEM(#LIST, _PyWideStringList_AsList(&config->LIST))
SET_ITEM_INT(_config_init);
SET_ITEM_INT(isolated);
@@ -861,7 +861,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
SET_ITEM_WSTRLIST(argv);
SET_ITEM_WSTRLIST(xoptions);
SET_ITEM_WSTRLIST(warnoptions);
- SET_ITEM_WSTR(module_search_path_env);
+ SET_ITEM_WSTR(pythonpath_env);
SET_ITEM_WSTR(home);
SET_ITEM_WSTRLIST(module_search_paths);
SET_ITEM_WSTR(executable);
@@ -911,7 +911,7 @@ fail:
static const char*
-_PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name)
+config_get_env(const PyConfig *config, const char *name)
{
return _Py_GetEnv(config->use_environment, name);
}
@@ -920,46 +920,46 @@ _PyCoreConfig_GetEnv(const _PyCoreConfig *config, const char *name)
/* Get a copy of the environment variable as wchar_t*.
Return 0 on success, but *dest can be NULL.
Return -1 on memory allocation failure. Return -2 on decoding error. */
-static _PyInitError
-_PyCoreConfig_GetEnvDup(_PyCoreConfig *config,
- wchar_t **dest,
- wchar_t *wname, char *name,
- const char *decode_err_msg)
+static PyStatus
+config_get_env_dup(PyConfig *config,
+ wchar_t **dest,
+ wchar_t *wname, char *name,
+ const char *decode_err_msg)
{
assert(*dest == NULL);
assert(config->use_environment >= 0);
if (!config->use_environment) {
*dest = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
#ifdef MS_WINDOWS
const wchar_t *var = _wgetenv(wname);
if (!var || var[0] == '\0') {
*dest = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
- return _PyCoreConfig_SetString(config, dest, var);
+ return PyConfig_SetString(config, dest, var);
#else
const char *var = getenv(name);
if (!var || var[0] == '\0') {
*dest = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
- return _PyCoreConfig_DecodeLocaleErr(config, dest, var, decode_err_msg);
+ return config_set_bytes_string(config, dest, var, decode_err_msg);
#endif
}
#define CONFIG_GET_ENV_DUP(CONFIG, DEST, WNAME, NAME) \
- _PyCoreConfig_GetEnvDup(CONFIG, DEST, WNAME, NAME, "cannot decode " NAME)
+ config_get_env_dup(CONFIG, DEST, WNAME, NAME, "cannot decode " NAME)
static void
-_PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
+config_get_global_vars(PyConfig *config)
{
if (config->_config_init != _PyConfig_INIT_COMPAT) {
/* Python and Isolated configuration ignore global variables */
@@ -1001,7 +1001,7 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
/* Set Py_xxx global configuration variables from 'config' configuration. */
static void
-_PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
+config_set_global_vars(const PyConfig *config)
{
#define COPY_FLAG(ATTR, VAR) \
if (config->ATTR != -1) { \
@@ -1042,19 +1042,19 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
/* Get the program name: use PYTHONEXECUTABLE and __PYVENV_LAUNCHER__
environment variables on macOS if available. */
-static _PyInitError
-config_init_program_name(_PyCoreConfig *config)
+static PyStatus
+config_init_program_name(PyConfig *config)
{
- _PyInitError err;
+ PyStatus status;
/* If Py_SetProgramName() was called, use its value */
const wchar_t *program_name = _Py_path_config.program_name;
if (program_name != NULL) {
config->program_name = _PyMem_RawWcsdup(program_name);
if (config->program_name == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
#ifdef __APPLE__
@@ -1067,14 +1067,14 @@ config_init_program_name(_PyCoreConfig *config)
so the actual executable path is passed in an environment variable.
See Lib/plat-mac/bundlebuiler.py for details about the bootstrap
script. */
- const char *p = _PyCoreConfig_GetEnv(config, "PYTHONEXECUTABLE");
+ const char *p = config_get_env(config, "PYTHONEXECUTABLE");
if (p != NULL) {
- err = CONFIG_DECODE_LOCALE(config, &config->program_name, p,
- "PYTHONEXECUTABLE environment variable");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = CONFIG_SET_BYTES_STR(config, &config->program_name, p,
+ "PYTHONEXECUTABLE environment variable");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
#ifdef WITH_NEXT_FRAMEWORK
else {
@@ -1083,26 +1083,27 @@ config_init_program_name(_PyCoreConfig *config)
/* Used by Mac/Tools/pythonw.c to forward
* the argv0 of the stub executable
*/
- err = CONFIG_DECODE_LOCALE(config,
- &config->program_name, pyvenv_launcher,
- "__PYVENV_LAUNCHER__ environment variable");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = CONFIG_SET_BYTES_STR(config,
+ &config->program_name,
+ pyvenv_launcher,
+ "__PYVENV_LAUNCHER__ environment variable");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
}
#endif /* WITH_NEXT_FRAMEWORK */
#endif /* __APPLE__ */
/* Use argv[0] if available and non-empty */
- const _PyWstrList *argv = &config->argv;
+ const PyWideStringList *argv = &config->argv;
if (argv->length >= 1 && argv->items[0][0] != L'\0') {
config->program_name = _PyMem_RawWcsdup(argv->items[0]);
if (config->program_name == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* Last fall back: hardcoded name */
@@ -1111,54 +1112,54 @@ config_init_program_name(_PyCoreConfig *config)
#else
const wchar_t *default_program_name = L"python3";
#endif
- err = _PyCoreConfig_SetString(config, &config->program_name,
- default_program_name);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->program_name,
+ default_program_name);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_init_executable(_PyCoreConfig *config)
+static PyStatus
+config_init_executable(PyConfig *config)
{
assert(config->executable == NULL);
/* If Py_SetProgramFullPath() was called, use its value */
const wchar_t *program_full_path = _Py_path_config.program_full_path;
if (program_full_path != NULL) {
- _PyInitError err = _PyCoreConfig_SetString(config,
- &config->executable,
- program_full_path);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = PyConfig_SetString(config,
+ &config->executable,
+ program_full_path);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
static const wchar_t*
-config_get_xoption(const _PyCoreConfig *config, wchar_t *name)
+config_get_xoption(const PyConfig *config, wchar_t *name)
{
return _Py_get_xoption(&config->xoptions, name);
}
-static _PyInitError
-config_init_home(_PyCoreConfig *config)
+static PyStatus
+config_init_home(PyConfig *config)
{
assert(config->home == NULL);
/* If Py_SetPythonHome() was called, use its value */
wchar_t *home = _Py_path_config.home;
if (home) {
- _PyInitError err = _PyCoreConfig_SetString(config, &config->home, home);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = PyConfig_SetString(config, &config->home, home);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
return CONFIG_GET_ENV_DUP(config, &config->home,
@@ -1166,10 +1167,10 @@ config_init_home(_PyCoreConfig *config)
}
-static _PyInitError
-config_init_hash_seed(_PyCoreConfig *config)
+static PyStatus
+config_init_hash_seed(PyConfig *config)
{
- const char *seed_text = _PyCoreConfig_GetEnv(config, "PYTHONHASHSEED");
+ const char *seed_text = config_get_env(config, "PYTHONHASHSEED");
Py_BUILD_ASSERT(sizeof(_Py_HashSecret_t) == sizeof(_Py_HashSecret.uc));
/* Convert a text seed to a numeric one */
@@ -1182,7 +1183,7 @@ config_init_hash_seed(_PyCoreConfig *config)
|| seed > 4294967295UL
|| (errno == ERANGE && seed == ULONG_MAX))
{
- return _Py_INIT_ERR("PYTHONHASHSEED must be \"random\" "
+ return _PyStatus_ERR("PYTHONHASHSEED must be \"random\" "
"or an integer in range [0; 4294967295]");
}
/* Use a specific hash */
@@ -1194,7 +1195,7 @@ config_init_hash_seed(_PyCoreConfig *config)
config->use_hash_seed = 0;
config->hash_seed = 0;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
@@ -1216,10 +1217,10 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
}
-static _PyInitError
-config_read_env_vars(_PyCoreConfig *config)
+static PyStatus
+config_read_env_vars(PyConfig *config)
{
- _PyInitError err;
+ PyStatus status;
int use_env = config->use_environment;
/* Get environment variables */
@@ -1251,39 +1252,39 @@ config_read_env_vars(_PyCoreConfig *config)
"PYTHONLEGACYWINDOWSSTDIO");
#endif
- if (_PyCoreConfig_GetEnv(config, "PYTHONDUMPREFS")) {
+ if (config_get_env(config, "PYTHONDUMPREFS")) {
config->dump_refs = 1;
}
- if (_PyCoreConfig_GetEnv(config, "PYTHONMALLOCSTATS")) {
+ if (config_get_env(config, "PYTHONMALLOCSTATS")) {
config->malloc_stats = 1;
}
- if (config->module_search_path_env == NULL) {
- err = CONFIG_GET_ENV_DUP(config, &config->module_search_path_env,
- L"PYTHONPATH", "PYTHONPATH");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->pythonpath_env == NULL) {
+ status = CONFIG_GET_ENV_DUP(config, &config->pythonpath_env,
+ L"PYTHONPATH", "PYTHONPATH");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->use_hash_seed < 0) {
- err = config_init_hash_seed(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_hash_seed(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_init_tracemalloc(_PyCoreConfig *config)
+static PyStatus
+config_init_tracemalloc(PyConfig *config)
{
int nframe;
int valid;
- const char *env = _PyCoreConfig_GetEnv(config, "PYTHONTRACEMALLOC");
+ const char *env = config_get_env(config, "PYTHONTRACEMALLOC");
if (env) {
if (!_Py_str_to_int(env, &nframe)) {
valid = (nframe >= 0);
@@ -1292,7 +1293,7 @@ config_init_tracemalloc(_PyCoreConfig *config)
valid = 0;
}
if (!valid) {
- return _Py_INIT_ERR("PYTHONTRACEMALLOC: invalid number of frames");
+ return _PyStatus_ERR("PYTHONTRACEMALLOC: invalid number of frames");
}
config->tracemalloc = nframe;
}
@@ -1308,8 +1309,8 @@ config_init_tracemalloc(_PyCoreConfig *config)
valid = 0;
}
if (!valid) {
- return _Py_INIT_ERR("-X tracemalloc=NFRAME: "
- "invalid number of frames");
+ return _PyStatus_ERR("-X tracemalloc=NFRAME: "
+ "invalid number of frames");
}
}
else {
@@ -1318,12 +1319,12 @@ config_init_tracemalloc(_PyCoreConfig *config)
}
config->tracemalloc = nframe;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_init_pycache_prefix(_PyCoreConfig *config)
+static PyStatus
+config_init_pycache_prefix(PyConfig *config)
{
assert(config->pycache_prefix == NULL);
@@ -1333,7 +1334,7 @@ config_init_pycache_prefix(_PyCoreConfig *config)
if (sep && wcslen(sep) > 1) {
config->pycache_prefix = _PyMem_RawWcsdup(sep + 1);
if (config->pycache_prefix == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
}
else {
@@ -1341,7 +1342,7 @@ config_init_pycache_prefix(_PyCoreConfig *config)
// if "-X pycache_prefix=" option is used
config->pycache_prefix = NULL;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
return CONFIG_GET_ENV_DUP(config, &config->pycache_prefix,
@@ -1350,41 +1351,41 @@ config_init_pycache_prefix(_PyCoreConfig *config)
}
-static _PyInitError
-config_read_complex_options(_PyCoreConfig *config)
+static PyStatus
+config_read_complex_options(PyConfig *config)
{
/* More complex options configured by env var and -X option */
if (config->faulthandler < 0) {
- if (_PyCoreConfig_GetEnv(config, "PYTHONFAULTHANDLER")
+ if (config_get_env(config, "PYTHONFAULTHANDLER")
|| config_get_xoption(config, L"faulthandler")) {
config->faulthandler = 1;
}
}
- if (_PyCoreConfig_GetEnv(config, "PYTHONPROFILEIMPORTTIME")
+ if (config_get_env(config, "PYTHONPROFILEIMPORTTIME")
|| config_get_xoption(config, L"importtime")) {
config->import_time = 1;
}
- _PyInitError err;
+ PyStatus status;
if (config->tracemalloc < 0) {
- err = config_init_tracemalloc(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_tracemalloc(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->pycache_prefix == NULL) {
- err = config_init_pycache_prefix(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_pycache_prefix(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
static const wchar_t *
-config_get_stdio_errors(const _PyCoreConfig *config)
+config_get_stdio_errors(const PyConfig *config)
{
#ifndef MS_WINDOWS
const char *loc = setlocale(LC_CTYPE, NULL);
@@ -1410,65 +1411,65 @@ config_get_stdio_errors(const _PyCoreConfig *config)
}
-static _PyInitError
-config_get_locale_encoding(_PyCoreConfig *config, wchar_t **locale_encoding)
+static PyStatus
+config_get_locale_encoding(PyConfig *config, wchar_t **locale_encoding)
{
#ifdef MS_WINDOWS
char encoding[20];
PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP());
- return _PyCoreConfig_DecodeLocale(config, locale_encoding, encoding);
+ return PyConfig_SetBytesString(config, locale_encoding, encoding);
#elif defined(_Py_FORCE_UTF8_LOCALE)
- return _PyCoreConfig_SetString(config, locale_encoding, L"utf-8");
+ return PyConfig_SetString(config, locale_encoding, L"utf-8");
#else
const char *encoding = nl_langinfo(CODESET);
if (!encoding || encoding[0] == '\0') {
- return _Py_INIT_ERR("failed to get the locale encoding: "
- "nl_langinfo(CODESET) failed");
+ return _PyStatus_ERR("failed to get the locale encoding: "
+ "nl_langinfo(CODESET) failed");
}
/* nl_langinfo(CODESET) is decoded by Py_DecodeLocale() */
- return CONFIG_DECODE_LOCALE(config,
+ return CONFIG_SET_BYTES_STR(config,
locale_encoding, encoding,
"nl_langinfo(CODESET)");
#endif
}
-static _PyInitError
-config_init_stdio_encoding(_PyCoreConfig *config,
- const _PyPreConfig *preconfig)
+static PyStatus
+config_init_stdio_encoding(PyConfig *config,
+ const PyPreConfig *preconfig)
{
- _PyInitError err;
+ PyStatus status;
/* If Py_SetStandardStreamEncoding() have been called, use these
parameters. */
if (config->stdio_encoding == NULL && _Py_StandardStreamEncoding != NULL) {
- err = CONFIG_DECODE_LOCALE(config, &config->stdio_encoding,
- _Py_StandardStreamEncoding,
- "_Py_StandardStreamEncoding");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = CONFIG_SET_BYTES_STR(config, &config->stdio_encoding,
+ _Py_StandardStreamEncoding,
+ "_Py_StandardStreamEncoding");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->stdio_errors == NULL && _Py_StandardStreamErrors != NULL) {
- err = CONFIG_DECODE_LOCALE(config, &config->stdio_errors,
- _Py_StandardStreamErrors,
- "_Py_StandardStreamErrors");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = CONFIG_SET_BYTES_STR(config, &config->stdio_errors,
+ _Py_StandardStreamErrors,
+ "_Py_StandardStreamErrors");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->stdio_encoding != NULL && config->stdio_errors != NULL) {
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* PYTHONIOENCODING environment variable */
- const char *opt = _PyCoreConfig_GetEnv(config, "PYTHONIOENCODING");
+ const char *opt = config_get_env(config, "PYTHONIOENCODING");
if (opt) {
char *pythonioencoding = _PyMem_RawStrdup(opt);
if (pythonioencoding == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
char *errors = strchr(pythonioencoding, ':');
@@ -1483,12 +1484,12 @@ config_init_stdio_encoding(_PyCoreConfig *config,
/* Does PYTHONIOENCODING contain an encoding? */
if (pythonioencoding[0]) {
if (config->stdio_encoding == NULL) {
- err = CONFIG_DECODE_LOCALE(config, &config->stdio_encoding,
- pythonioencoding,
- "PYTHONIOENCODING environment variable");
- if (_Py_INIT_FAILED(err)) {
+ status = CONFIG_SET_BYTES_STR(config, &config->stdio_encoding,
+ pythonioencoding,
+ "PYTHONIOENCODING environment variable");
+ if (_PyStatus_EXCEPTION(status)) {
PyMem_RawFree(pythonioencoding);
- return err;
+ return status;
}
}
@@ -1502,12 +1503,12 @@ config_init_stdio_encoding(_PyCoreConfig *config,
}
if (config->stdio_errors == NULL && errors != NULL) {
- err = CONFIG_DECODE_LOCALE(config, &config->stdio_errors,
- errors,
- "PYTHONIOENCODING environment variable");
- if (_Py_INIT_FAILED(err)) {
+ status = CONFIG_SET_BYTES_STR(config, &config->stdio_errors,
+ errors,
+ "PYTHONIOENCODING environment variable");
+ if (_PyStatus_EXCEPTION(status)) {
PyMem_RawFree(pythonioencoding);
- return err;
+ return status;
}
}
@@ -1517,83 +1518,84 @@ config_init_stdio_encoding(_PyCoreConfig *config,
/* UTF-8 Mode uses UTF-8/surrogateescape */
if (preconfig->utf8_mode) {
if (config->stdio_encoding == NULL) {
- err = _PyCoreConfig_SetString(config, &config->stdio_encoding, L"utf-8");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->stdio_encoding,
+ L"utf-8");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->stdio_errors == NULL) {
- err = _PyCoreConfig_SetString(config, &config->stdio_errors,
- L"surrogateescape");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->stdio_errors,
+ L"surrogateescape");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
}
/* Choose the default error handler based on the current locale. */
if (config->stdio_encoding == NULL) {
- err = config_get_locale_encoding(config, &config->stdio_encoding);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_get_locale_encoding(config, &config->stdio_encoding);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->stdio_errors == NULL) {
const wchar_t *errors = config_get_stdio_errors(config);
assert(errors != NULL);
- err = _PyCoreConfig_SetString(config, &config->stdio_errors, errors);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->stdio_errors, errors);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_init_fs_encoding(_PyCoreConfig *config, const _PyPreConfig *preconfig)
+static PyStatus
+config_init_fs_encoding(PyConfig *config, const PyPreConfig *preconfig)
{
- _PyInitError err;
+ PyStatus status;
if (config->filesystem_encoding == NULL) {
#ifdef _Py_FORCE_UTF8_FS_ENCODING
- err = _PyCoreConfig_SetString(config, &config->filesystem_encoding, L"utf-8");
+ status = PyConfig_SetString(config, &config->filesystem_encoding, L"utf-8");
#else
#ifdef MS_WINDOWS
if (preconfig->legacy_windows_fs_encoding) {
/* Legacy Windows filesystem encoding: mbcs/replace */
- err = _PyCoreConfig_SetString(config, &config->filesystem_encoding,
- L"mbcs");
+ status = PyConfig_SetString(config, &config->filesystem_encoding,
+ L"mbcs");
}
else
#endif
if (preconfig->utf8_mode) {
- err = _PyCoreConfig_SetString(config, &config->filesystem_encoding,
- L"utf-8");
+ status = PyConfig_SetString(config, &config->filesystem_encoding,
+ L"utf-8");
}
#ifndef MS_WINDOWS
else if (_Py_GetForceASCII()) {
- err = _PyCoreConfig_SetString(config, &config->filesystem_encoding,
- L"ascii");
+ status = PyConfig_SetString(config, &config->filesystem_encoding,
+ L"ascii");
}
#endif
else {
#ifdef MS_WINDOWS
/* Windows defaults to utf-8/surrogatepass (PEP 529). */
- err = _PyCoreConfig_SetString(config, &config->filesystem_encoding,
- L"utf-8");
+ status = PyConfig_SetString(config, &config->filesystem_encoding,
+ L"utf-8");
#else
- err = config_get_locale_encoding(config,
- &config->filesystem_encoding);
+ status = config_get_locale_encoding(config,
+ &config->filesystem_encoding);
#endif
}
#endif /* !_Py_FORCE_UTF8_FS_ENCODING */
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -1609,25 +1611,25 @@ config_init_fs_encoding(_PyCoreConfig *config, const _PyPreConfig *preconfig)
#else
errors = L"surrogateescape";
#endif
- err = _PyCoreConfig_SetString(config, &config->filesystem_errors, errors);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->filesystem_errors, errors);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_read(_PyCoreConfig *config)
+static PyStatus
+config_read(PyConfig *config)
{
- _PyInitError err;
- const _PyPreConfig *preconfig = &_PyRuntime.preconfig;
+ PyStatus status;
+ const PyPreConfig *preconfig = &_PyRuntime.preconfig;
if (config->use_environment) {
- err = config_read_env_vars(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_read_env_vars(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -1639,29 +1641,29 @@ config_read(_PyCoreConfig *config)
config->show_alloc_count = 1;
}
- err = config_read_complex_options(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_read_complex_options(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
if (config->home == NULL) {
- err = config_init_home(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_home(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->executable == NULL) {
- err = config_init_executable(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_executable(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->_install_importlib) {
- err = _PyCoreConfig_InitPathConfig(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyConfig_InitPathConfig(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -1683,29 +1685,30 @@ config_read(_PyCoreConfig *config)
}
if (config->filesystem_encoding == NULL || config->filesystem_errors == NULL) {
- err = config_init_fs_encoding(config, preconfig);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_fs_encoding(config, preconfig);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- err = config_init_stdio_encoding(config, preconfig);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_stdio_encoding(config, preconfig);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
if (config->argv.length < 1) {
/* Ensure at least one (empty) argument is seen */
- if (_PyWstrList_Append(&config->argv, L"") < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = PyWideStringList_Append(&config->argv, L"");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->check_hash_pycs_mode == NULL) {
- err = _PyCoreConfig_SetString(config, &config->check_hash_pycs_mode,
- L"default");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->check_hash_pycs_mode,
+ L"default");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -1713,12 +1716,12 @@ config_read(_PyCoreConfig *config)
config->configure_c_stdio = 1;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
static void
-config_init_stdio(const _PyCoreConfig *config)
+config_init_stdio(const PyConfig *config)
{
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
/* don't translate newlines (\r\n <=> \n) */
@@ -1759,23 +1762,23 @@ config_init_stdio(const _PyCoreConfig *config)
- set Py_xxx global configuration variables
- initialize C standard streams (stdin, stdout, stderr) */
void
-_PyCoreConfig_Write(const _PyCoreConfig *config, _PyRuntimeState *runtime)
+_PyConfig_Write(const PyConfig *config, _PyRuntimeState *runtime)
{
- _PyCoreConfig_SetGlobalConfig(config);
+ config_set_global_vars(config);
if (config->configure_c_stdio) {
config_init_stdio(config);
}
/* Write the new pre-configuration into _PyRuntime */
- _PyPreConfig *preconfig = &runtime->preconfig;
+ PyPreConfig *preconfig = &runtime->preconfig;
preconfig->isolated = config->isolated;
preconfig->use_environment = config->use_environment;
preconfig->dev_mode = config->dev_mode;
}
-/* --- _PyCoreConfig command line parser -------------------------- */
+/* --- PyConfig command line parser -------------------------- */
static void
config_usage(int error, const wchar_t* program)
@@ -1797,12 +1800,12 @@ config_usage(int error, const wchar_t* program)
/* Parse the command line arguments */
-static _PyInitError
-config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
+static PyStatus
+config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,
Py_ssize_t *opt_index)
{
- _PyInitError err;
- const _PyWstrList *argv = &config->argv;
+ PyStatus status;
+ const PyWideStringList *argv = &config->argv;
int print_version = 0;
const wchar_t* program = config->program_name;
@@ -1822,7 +1825,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
size_t len = wcslen(_PyOS_optarg) + 1 + 1;
wchar_t *command = PyMem_RawMalloc(sizeof(wchar_t) * len);
if (command == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t));
command[len - 2] = '\n';
@@ -1839,7 +1842,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
if (config->run_module == NULL) {
config->run_module = _PyMem_RawWcsdup(_PyOS_optarg);
if (config->run_module == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
}
break;
@@ -1853,16 +1856,16 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
|| wcscmp(_PyOS_optarg, L"never") == 0
|| wcscmp(_PyOS_optarg, L"default") == 0)
{
- err = _PyCoreConfig_SetString(config, &config->check_hash_pycs_mode,
- _PyOS_optarg);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = PyConfig_SetString(config, &config->check_hash_pycs_mode,
+ _PyOS_optarg);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
} else {
fprintf(stderr, "--check-hash-based-pycs must be one of "
"'default', 'always', or 'never'\n");
config_usage(1, program);
- return _Py_INIT_EXIT(2);
+ return _PyStatus_EXIT(2);
}
break;
@@ -1922,15 +1925,16 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
case 'h':
case '?':
config_usage(0, program);
- return _Py_INIT_EXIT(0);
+ return _PyStatus_EXIT(0);
case 'V':
print_version++;
break;
case 'W':
- if (_PyWstrList_Append(warnoptions, _PyOS_optarg) < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = PyWideStringList_Append(warnoptions, _PyOS_optarg);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
break;
@@ -1947,14 +1951,14 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
default:
/* unknown argument: parsing failed */
config_usage(1, program);
- return _Py_INIT_EXIT(2);
+ return _PyStatus_EXIT(2);
}
} while (1);
if (print_version) {
printf("Python %s\n",
(print_version >= 2) ? Py_GetVersion() : PY_VERSION);
- return _Py_INIT_EXIT(0);
+ return _PyStatus_EXIT(0);
}
if (config->run_command == NULL && config->run_module == NULL
@@ -1964,7 +1968,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
{
config->run_filename = _PyMem_RawWcsdup(argv->items[_PyOS_optind]);
if (config->run_filename == NULL) {
- return _Py_INIT_NO_MEMORY();
+ return _PyStatus_NO_MEMORY();
}
}
@@ -1975,7 +1979,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
*opt_index = _PyOS_optind;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
@@ -1986,21 +1990,21 @@ config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
#endif
/* Get warning options from PYTHONWARNINGS environment variable. */
-static _PyInitError
-config_init_env_warnoptions(_PyCoreConfig *config, _PyWstrList *warnoptions)
+static PyStatus
+config_init_env_warnoptions(PyConfig *config, PyWideStringList *warnoptions)
{
- _PyInitError err;
+ PyStatus status;
/* CONFIG_GET_ENV_DUP requires dest to be initialized to NULL */
wchar_t *env = NULL;
- err = CONFIG_GET_ENV_DUP(config, &env,
+ status = CONFIG_GET_ENV_DUP(config, &env,
L"PYTHONWARNINGS", "PYTHONWARNINGS");
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* env var is not set or is empty */
if (env == NULL) {
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
@@ -2009,35 +2013,35 @@ config_init_env_warnoptions(_PyCoreConfig *config, _PyWstrList *warnoptions)
warning != NULL;
warning = WCSTOK(NULL, L",", &context))
{
- if (_PyWstrList_Append(warnoptions, warning) < 0) {
+ status = PyWideStringList_Append(warnoptions, warning);
+ if (_PyStatus_EXCEPTION(status)) {
PyMem_RawFree(env);
- return _Py_INIT_NO_MEMORY();
+ return status;
}
}
PyMem_RawFree(env);
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static int
-config_add_warnoption(_PyCoreConfig *config, const wchar_t *option)
+static PyStatus
+config_add_warnoption(PyConfig *config, const wchar_t *option)
{
- if (_PyWstrList_Find(&config->warnoptions, option)) {
+ if (_PyWideStringList_Find(&config->warnoptions, option)) {
/* Already present: do nothing */
- return 0;
- }
- if (_PyWstrList_Append(&config->warnoptions, option)) {
- return -1;
+ return _PyStatus_OK();
}
- return 0;
+ return PyWideStringList_Append(&config->warnoptions, option);
}
-static _PyInitError
-config_init_warnoptions(_PyCoreConfig *config,
- const _PyWstrList *cmdline_warnoptions,
- const _PyWstrList *env_warnoptions)
+static PyStatus
+config_init_warnoptions(PyConfig *config,
+ const PyWideStringList *cmdline_warnoptions,
+ const PyWideStringList *env_warnoptions)
{
+ PyStatus status;
+
/* The priority order for warnings configuration is (highest precedence
* first):
*
@@ -2054,25 +2058,28 @@ config_init_warnoptions(_PyCoreConfig *config,
*/
if (config->dev_mode) {
- if (config_add_warnoption(config, L"default") < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = config_add_warnoption(config, L"default");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
Py_ssize_t i;
- const _PyWstrList *options;
+ const PyWideStringList *options;
options = env_warnoptions;
for (i = 0; i < options->length; i++) {
- if (config_add_warnoption(config, options->items[i]) < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = config_add_warnoption(config, options->items[i]);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
options = cmdline_warnoptions;
for (i = 0; i < options->length; i++) {
- if (config_add_warnoption(config, options->items[i]) < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = config_add_warnoption(config, options->items[i]);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -2088,33 +2095,35 @@ config_init_warnoptions(_PyCoreConfig *config,
else {
filter = L"default::BytesWarning";
}
- if (config_add_warnoption(config, filter) < 0) {
- return _Py_INIT_NO_MEMORY();
+ status = config_add_warnoption(config, filter);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_update_argv(_PyCoreConfig *config, Py_ssize_t opt_index)
+static PyStatus
+config_update_argv(PyConfig *config, Py_ssize_t opt_index)
{
- const _PyWstrList *cmdline_argv = &config->argv;
- _PyWstrList config_argv = _PyWstrList_INIT;
+ const PyWideStringList *cmdline_argv = &config->argv;
+ PyWideStringList config_argv = PyWideStringList_INIT;
/* Copy argv to be able to modify it (to force -c/-m) */
if (cmdline_argv->length <= opt_index) {
/* Ensure at least one (empty) argument is seen */
- if (_PyWstrList_Append(&config_argv, L"") < 0) {
- return _Py_INIT_NO_MEMORY();
+ PyStatus status = PyWideStringList_Append(&config_argv, L"");
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
else {
- _PyWstrList slice;
+ PyWideStringList slice;
slice.length = cmdline_argv->length - opt_index;
slice.items = &cmdline_argv->items[opt_index];
- if (_PyWstrList_Copy(&config_argv, &slice) < 0) {
- return _Py_INIT_NO_MEMORY();
+ if (_PyWideStringList_Copy(&config_argv, &slice) < 0) {
+ return _PyStatus_NO_MEMORY();
}
}
assert(config_argv.length >= 1);
@@ -2131,109 +2140,108 @@ config_update_argv(_PyCoreConfig *config, Py_ssize_t opt_index)
if (arg0 != NULL) {
arg0 = _PyMem_RawWcsdup(arg0);
if (arg0 == NULL) {
- _PyWstrList_Clear(&config_argv);
- return _Py_INIT_NO_MEMORY();
+ _PyWideStringList_Clear(&config_argv);
+ return _PyStatus_NO_MEMORY();
}
PyMem_RawFree(config_argv.items[0]);
config_argv.items[0] = arg0;
}
- _PyWstrList_Clear(&config->argv);
+ _PyWideStringList_Clear(&config->argv);
config->argv = config_argv;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-core_read_precmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
+static PyStatus
+core_read_precmdline(PyConfig *config, _PyPreCmdline *precmdline)
{
- _PyInitError err;
+ PyStatus status;
if (config->parse_argv) {
- if (_PyWstrList_Copy(&precmdline->argv, &config->argv) < 0) {
- return _Py_INIT_NO_MEMORY();
+ if (_PyWideStringList_Copy(&precmdline->argv, &config->argv) < 0) {
+ return _PyStatus_NO_MEMORY();
}
}
- _PyPreConfig preconfig;
+ PyPreConfig preconfig;
_PyPreConfig_InitFromPreConfig(&preconfig, &_PyRuntime.preconfig);
- _PyPreConfig_GetCoreConfig(&preconfig, config);
+ _PyPreConfig_GetConfig(&preconfig, config);
- err = _PyPreCmdline_Read(precmdline, &preconfig);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyPreCmdline_Read(precmdline, &preconfig);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- if (_PyPreCmdline_SetCoreConfig(precmdline, config) < 0) {
- err = _Py_INIT_NO_MEMORY();
- return err;
+ status = _PyPreCmdline_SetConfig(precmdline, config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
-
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-config_read_cmdline(_PyCoreConfig *config)
+static PyStatus
+config_read_cmdline(PyConfig *config)
{
- _PyInitError err;
- _PyWstrList cmdline_warnoptions = _PyWstrList_INIT;
- _PyWstrList env_warnoptions = _PyWstrList_INIT;
+ PyStatus status;
+ PyWideStringList cmdline_warnoptions = PyWideStringList_INIT;
+ PyWideStringList env_warnoptions = PyWideStringList_INIT;
if (config->parse_argv < 0) {
config->parse_argv = 1;
}
if (config->program_name == NULL) {
- err = config_init_program_name(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = config_init_program_name(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
if (config->parse_argv) {
Py_ssize_t opt_index;
- err = config_parse_cmdline(config, &cmdline_warnoptions, &opt_index);
- if (_Py_INIT_FAILED(err)) {
+ status = config_parse_cmdline(config, &cmdline_warnoptions, &opt_index);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
- err = config_update_argv(config, opt_index);
- if (_Py_INIT_FAILED(err)) {
+ status = config_update_argv(config, opt_index);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
}
if (config->use_environment) {
- err = config_init_env_warnoptions(config, &env_warnoptions);
- if (_Py_INIT_FAILED(err)) {
+ status = config_init_env_warnoptions(config, &env_warnoptions);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
}
- err = config_init_warnoptions(config,
+ status = config_init_warnoptions(config,
&cmdline_warnoptions, &env_warnoptions);
- if (_Py_INIT_FAILED(err)) {
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
- err = _Py_INIT_OK();
+ status = _PyStatus_OK();
done:
- _PyWstrList_Clear(&cmdline_warnoptions);
- _PyWstrList_Clear(&env_warnoptions);
- return err;
+ _PyWideStringList_Clear(&cmdline_warnoptions);
+ _PyWideStringList_Clear(&env_warnoptions);
+ return status;
}
-_PyInitError
-_PyCoreConfig_SetPyArgv(_PyCoreConfig *config, const _PyArgv *args)
+PyStatus
+_PyConfig_SetPyArgv(PyConfig *config, const _PyArgv *args)
{
- _PyInitError err = _Py_PreInitializeFromCoreConfig(config, args);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _Py_PreInitializeFromConfig(config, args);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
return _PyArgv_AsWstrList(args, &config->argv);
@@ -2242,57 +2250,57 @@ _PyCoreConfig_SetPyArgv(_PyCoreConfig *config, const _PyArgv *args)
/* Set config.argv: decode argv using Py_DecodeLocale(). Pre-initialize Python
if needed to ensure that encodings are properly configured. */
-_PyInitError
-_PyCoreConfig_SetArgv(_PyCoreConfig *config, Py_ssize_t argc, char * const *argv)
+PyStatus
+PyConfig_SetBytesArgv(PyConfig *config, Py_ssize_t argc, char * const *argv)
{
_PyArgv args = {
.argc = argc,
.use_bytes_argv = 1,
.bytes_argv = argv,
.wchar_argv = NULL};
- return _PyCoreConfig_SetPyArgv(config, &args);
+ return _PyConfig_SetPyArgv(config, &args);
}
-_PyInitError
-_PyCoreConfig_SetWideArgv(_PyCoreConfig *config, Py_ssize_t argc, wchar_t * const *argv)
+PyStatus
+PyConfig_SetArgv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv)
{
_PyArgv args = {
.argc = argc,
.use_bytes_argv = 0,
.bytes_argv = NULL,
.wchar_argv = argv};
- return _PyCoreConfig_SetPyArgv(config, &args);
+ return _PyConfig_SetPyArgv(config, &args);
}
-/* Read the configuration into _PyCoreConfig from:
+/* Read the configuration into PyConfig from:
* Command line arguments
* Environment variables
* Py_xxx global configuration variables
The only side effects are to modify config and to call _Py_SetArgcArgv(). */
-_PyInitError
-_PyCoreConfig_Read(_PyCoreConfig *config)
+PyStatus
+PyConfig_Read(PyConfig *config)
{
- _PyInitError err;
- _PyWstrList orig_argv = _PyWstrList_INIT;
+ PyStatus status;
+ PyWideStringList orig_argv = PyWideStringList_INIT;
- err = _Py_PreInitializeFromCoreConfig(config, NULL);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _Py_PreInitializeFromConfig(config, NULL);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- _PyCoreConfig_GetGlobalConfig(config);
+ config_get_global_vars(config);
- if (_PyWstrList_Copy(&orig_argv, &config->argv) < 0) {
- return _Py_INIT_NO_MEMORY();
+ if (_PyWideStringList_Copy(&orig_argv, &config->argv) < 0) {
+ return _PyStatus_NO_MEMORY();
}
_PyPreCmdline precmdline = _PyPreCmdline_INIT;
- err = core_read_precmdline(config, &precmdline);
- if (_Py_INIT_FAILED(err)) {
+ status = core_read_precmdline(config, &precmdline);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
@@ -2302,18 +2310,18 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
config->user_site_directory = 0;
}
- err = config_read_cmdline(config);
- if (_Py_INIT_FAILED(err)) {
+ status = config_read_cmdline(config);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
- err = config_read(config);
- if (_Py_INIT_FAILED(err)) {
+ status = config_read(config);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
if (_Py_SetArgcArgv(orig_argv.length, orig_argv.items) < 0) {
- err = _Py_INIT_NO_MEMORY();
+ status = _PyStatus_NO_MEMORY();
goto done;
}
@@ -2339,14 +2347,14 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
assert(config->configure_c_stdio >= 0);
assert(config->buffered_stdio >= 0);
assert(config->program_name != NULL);
- assert(_PyWstrList_CheckConsistency(&config->argv));
+ assert(_PyWideStringList_CheckConsistency(&config->argv));
/* sys.argv must be non-empty: empty argv is replaced with [''] */
assert(config->argv.length >= 1);
- assert(_PyWstrList_CheckConsistency(&config->xoptions));
- assert(_PyWstrList_CheckConsistency(&config->warnoptions));
- assert(_PyWstrList_CheckConsistency(&config->module_search_paths));
+ assert(_PyWideStringList_CheckConsistency(&config->xoptions));
+ assert(_PyWideStringList_CheckConsistency(&config->warnoptions));
+ assert(_PyWideStringList_CheckConsistency(&config->module_search_paths));
if (config->_install_importlib) {
- assert(config->use_module_search_paths != 0);
+ assert(config->module_search_paths_set != 0);
/* don't check config->module_search_paths */
assert(config->executable != NULL);
assert(config->prefix != NULL);
@@ -2367,63 +2375,63 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
assert(config->_install_importlib >= 0);
assert(config->pathconfig_warnings >= 0);
- err = _Py_INIT_OK();
+ status = _PyStatus_OK();
done:
- _PyWstrList_Clear(&orig_argv);
+ _PyWideStringList_Clear(&orig_argv);
_PyPreCmdline_Clear(&precmdline);
- return err;
+ return status;
}
PyObject*
_Py_GetConfigsAsDict(void)
{
- PyObject *config = NULL;
+ PyObject *result = NULL;
PyObject *dict = NULL;
- config = PyDict_New();
- if (config == NULL) {
+ result = PyDict_New();
+ if (result == NULL) {
goto error;
}
- /* global config */
+ /* global result */
dict = _Py_GetGlobalVariablesAsDict();
if (dict == NULL) {
goto error;
}
- if (PyDict_SetItemString(config, "global_config", dict) < 0) {
+ if (PyDict_SetItemString(result, "global_config", dict) < 0) {
goto error;
}
Py_CLEAR(dict);
/* pre config */
PyInterpreterState *interp = _PyInterpreterState_Get();
- const _PyPreConfig *pre_config = &_PyRuntime.preconfig;
+ const PyPreConfig *pre_config = &_PyRuntime.preconfig;
dict = _PyPreConfig_AsDict(pre_config);
if (dict == NULL) {
goto error;
}
- if (PyDict_SetItemString(config, "pre_config", dict) < 0) {
+ if (PyDict_SetItemString(result, "pre_config", dict) < 0) {
goto error;
}
Py_CLEAR(dict);
/* core config */
- const _PyCoreConfig *core_config = _PyInterpreterState_GetCoreConfig(interp);
- dict = _PyCoreConfig_AsDict(core_config);
+ const PyConfig *config = &interp->config;
+ dict = config_as_dict(config);
if (dict == NULL) {
goto error;
}
- if (PyDict_SetItemString(config, "core_config", dict) < 0) {
+ if (PyDict_SetItemString(result, "config", dict) < 0) {
goto error;
}
Py_CLEAR(dict);
- return config;
+ return result;
error:
- Py_XDECREF(config);
+ Py_XDECREF(result);
Py_XDECREF(dict);
return NULL;
}
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index bbf29b2..ec67405 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -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 */
diff --git a/Python/preconfig.c b/Python/preconfig.c
index a6d1346..8be6533 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -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();
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 9880c0d..10a2881 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -6,7 +6,7 @@
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_ceval.h"
#include "pycore_context.h"
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
#include "pycore_fileutils.h"
#include "pycore_hamt.h"
#include "pycore_pathconfig.h"
@@ -60,10 +60,10 @@ extern "C" {
extern grammar _PyParser_Grammar; /* From graminit.c */
/* Forward */
-static _PyInitError add_main_module(PyInterpreterState *interp);
-static _PyInitError init_import_size(void);
-static _PyInitError init_sys_streams(PyInterpreterState *interp);
-static _PyInitError init_signals(void);
+static PyStatus add_main_module(PyInterpreterState *interp);
+static PyStatus init_import_size(void);
+static PyStatus init_sys_streams(PyInterpreterState *interp);
+static PyStatus init_signals(void);
static void call_py_exitfuncs(PyInterpreterState *);
static void wait_for_thread_shutdown(void);
static void call_ll_exitfuncs(_PyRuntimeState *runtime);
@@ -72,7 +72,7 @@ int _Py_UnhandledKeyboardInterrupt = 0;
_PyRuntimeState _PyRuntime = _PyRuntimeState_INIT;
static int runtime_initialized = 0;
-_PyInitError
+PyStatus
_PyRuntime_Initialize(void)
{
/* XXX We only initialize once in the process, which aligns with
@@ -82,7 +82,7 @@ _PyRuntime_Initialize(void)
This is because the runtime state is not properly finalized
currently. */
if (runtime_initialized) {
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
runtime_initialized = 1;
@@ -145,58 +145,58 @@ Py_IsInitialized(void)
*/
-static _PyInitError
+static PyStatus
init_importlib(PyInterpreterState *interp, PyObject *sysmod)
{
PyObject *importlib;
PyObject *impmod;
PyObject *value;
- int verbose = interp->core_config.verbose;
+ int verbose = interp->config.verbose;
/* Import _importlib through its frozen version, _frozen_importlib. */
if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
- return _Py_INIT_ERR("can't import _frozen_importlib");
+ return _PyStatus_ERR("can't import _frozen_importlib");
}
else if (verbose) {
PySys_FormatStderr("import _frozen_importlib # frozen\n");
}
importlib = PyImport_AddModule("_frozen_importlib");
if (importlib == NULL) {
- return _Py_INIT_ERR("couldn't get _frozen_importlib from sys.modules");
+ return _PyStatus_ERR("couldn't get _frozen_importlib from sys.modules");
}
interp->importlib = importlib;
Py_INCREF(interp->importlib);
interp->import_func = PyDict_GetItemString(interp->builtins, "__import__");
if (interp->import_func == NULL)
- return _Py_INIT_ERR("__import__ not found");
+ return _PyStatus_ERR("__import__ not found");
Py_INCREF(interp->import_func);
/* Import the _imp module */
impmod = PyInit__imp();
if (impmod == NULL) {
- return _Py_INIT_ERR("can't import _imp");
+ return _PyStatus_ERR("can't import _imp");
}
else if (verbose) {
PySys_FormatStderr("import _imp # builtin\n");
}
if (_PyImport_SetModuleString("_imp", impmod) < 0) {
- return _Py_INIT_ERR("can't save _imp to sys.modules");
+ return _PyStatus_ERR("can't save _imp to sys.modules");
}
/* Install importlib as the implementation of import */
value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
if (value == NULL) {
PyErr_Print();
- return _Py_INIT_ERR("importlib install failed");
+ return _PyStatus_ERR("importlib install failed");
}
Py_DECREF(value);
Py_DECREF(impmod);
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
init_importlib_external(PyInterpreterState *interp)
{
PyObject *value;
@@ -204,7 +204,7 @@ init_importlib_external(PyInterpreterState *interp)
"_install_external_importers", "");
if (value == NULL) {
PyErr_Print();
- return _Py_INIT_ERR("external importer setup failed");
+ return _PyStatus_ERR("external importer setup failed");
}
Py_DECREF(value);
return _PyImportZip_Init(interp);
@@ -265,7 +265,7 @@ static const char *_C_LOCALE_WARNING =
static void
emit_stderr_warning_for_legacy_locale(_PyRuntimeState *runtime)
{
- const _PyPreConfig *preconfig = &runtime->preconfig;
+ const PyPreConfig *preconfig = &runtime->preconfig;
if (preconfig->coerce_c_locale_warn && _Py_LegacyLocaleDetected(1)) {
PySys_FormatStderr("%s", _C_LOCALE_WARNING);
}
@@ -437,7 +437,7 @@ _Py_SetLocaleFromEnv(int category)
/* Global initializations. Can be undone by Py_Finalize(). Don't
call this twice without an intervening Py_Finalize() call.
- Every call to _Py_InitializeFromConfig, Py_Initialize or Py_InitializeEx
+ Every call to Py_InitializeFromConfig, Py_Initialize or Py_InitializeEx
must have a corresponding call to Py_Finalize.
Locking: you must hold the interpreter lock while calling these APIs.
@@ -446,50 +446,50 @@ _Py_SetLocaleFromEnv(int category)
*/
-static _PyInitError
+static PyStatus
pyinit_core_reconfigure(_PyRuntimeState *runtime,
PyInterpreterState **interp_p,
- const _PyCoreConfig *core_config)
+ const PyConfig *config)
{
- _PyInitError err;
+ PyStatus status;
PyThreadState *tstate = _PyThreadState_GET();
if (!tstate) {
- return _Py_INIT_ERR("failed to read thread state");
+ return _PyStatus_ERR("failed to read thread state");
}
PyInterpreterState *interp = tstate->interp;
if (interp == NULL) {
- return _Py_INIT_ERR("can't make main interpreter");
+ return _PyStatus_ERR("can't make main interpreter");
}
*interp_p = interp;
- _PyCoreConfig_Write(core_config, runtime);
+ _PyConfig_Write(config, runtime);
- err = _PyCoreConfig_Copy(&interp->core_config, core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyConfig_Copy(&interp->config, config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- core_config = &interp->core_config;
+ config = &interp->config;
- if (core_config->_install_importlib) {
- err = _PyCoreConfig_SetPathConfig(core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->_install_importlib) {
+ status = _PyConfig_SetPathConfig(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
pycore_init_runtime(_PyRuntimeState *runtime,
- const _PyCoreConfig *core_config)
+ const PyConfig *config)
{
if (runtime->initialized) {
- return _Py_INIT_ERR("main interpreter already initialized");
+ return _PyStatus_ERR("main interpreter already initialized");
}
- _PyCoreConfig_Write(core_config, runtime);
+ _PyConfig_Write(config, runtime);
/* Py_Finalize leaves _Py_Finalizing set in order to help daemon
* threads behave a little more gracefully at interpreter shutdown.
@@ -502,39 +502,39 @@ pycore_init_runtime(_PyRuntimeState *runtime,
*/
runtime->finalizing = NULL;
- _PyInitError err = _Py_HashRandomization_Init(core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _Py_HashRandomization_Init(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyInterpreterState_Enable(runtime);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyInterpreterState_Enable(runtime);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
pycore_create_interpreter(_PyRuntimeState *runtime,
- const _PyCoreConfig *core_config,
+ const PyConfig *config,
PyInterpreterState **interp_p)
{
PyInterpreterState *interp = PyInterpreterState_New();
if (interp == NULL) {
- return _Py_INIT_ERR("can't make main interpreter");
+ return _PyStatus_ERR("can't make main interpreter");
}
*interp_p = interp;
- _PyInitError err = _PyCoreConfig_Copy(&interp->core_config, core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyConfig_Copy(&interp->config, config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- core_config = &interp->core_config;
+ config = &interp->config;
PyThreadState *tstate = PyThreadState_New(interp);
if (tstate == NULL)
- return _Py_INIT_ERR("can't make first thread");
+ return _PyStatus_ERR("can't make first thread");
(void) PyThreadState_Swap(tstate);
/* We can't call _PyEval_FiniThreads() in Py_FinalizeEx because
@@ -550,249 +550,249 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
/* Create the GIL */
PyEval_InitThreads();
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
pycore_init_types(void)
{
- _PyInitError err = _PyTypes_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyTypes_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyUnicode_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyUnicode_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
if (_PyStructSequence_Init() < 0) {
- return _Py_INIT_ERR("can't initialize structseq");
+ return _PyStatus_ERR("can't initialize structseq");
}
if (!_PyLong_Init()) {
- return _Py_INIT_ERR("can't init longs");
+ return _PyStatus_ERR("can't init longs");
}
- err = _PyExc_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyExc_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
if (!_PyFloat_Init()) {
- return _Py_INIT_ERR("can't init float");
+ return _PyStatus_ERR("can't init float");
}
if (!_PyContext_Init()) {
- return _Py_INIT_ERR("can't init context");
+ return _PyStatus_ERR("can't init context");
}
- err = _PyErr_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyErr_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
pycore_init_builtins(PyInterpreterState *interp)
{
PyObject *bimod = _PyBuiltin_Init();
if (bimod == NULL) {
- return _Py_INIT_ERR("can't initialize builtins modules");
+ return _PyStatus_ERR("can't initialize builtins modules");
}
_PyImport_FixupBuiltin(bimod, "builtins", interp->modules);
interp->builtins = PyModule_GetDict(bimod);
if (interp->builtins == NULL) {
- return _Py_INIT_ERR("can't initialize builtins dict");
+ return _PyStatus_ERR("can't initialize builtins dict");
}
Py_INCREF(interp->builtins);
- _PyInitError err = _PyBuiltins_AddExceptions(bimod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyBuiltins_AddExceptions(bimod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
+static PyStatus
pycore_init_import_warnings(PyInterpreterState *interp, PyObject *sysmod)
{
- _PyInitError err = _PyImport_Init(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyImport_Init(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyImportHooks_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyImportHooks_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* Initialize _warnings. */
if (_PyWarnings_Init() == NULL) {
- return _Py_INIT_ERR("can't initialize warnings");
+ return _PyStatus_ERR("can't initialize warnings");
}
- if (interp->core_config._install_importlib) {
- err = _PyCoreConfig_SetPathConfig(&interp->core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (interp->config._install_importlib) {
+ status = _PyConfig_SetPathConfig(&interp->config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
/* This call sets up builtin and frozen import support */
- if (interp->core_config._install_importlib) {
- err = init_importlib(interp, sysmod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (interp->config._install_importlib) {
+ status = init_importlib(interp, sysmod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-static _PyInitError
-pyinit_core_config(_PyRuntimeState *runtime,
- PyInterpreterState **interp_p,
- const _PyCoreConfig *core_config)
+static PyStatus
+pyinit_config(_PyRuntimeState *runtime,
+ PyInterpreterState **interp_p,
+ const PyConfig *config)
{
PyInterpreterState *interp;
- _PyCoreConfig_Write(core_config, runtime);
+ _PyConfig_Write(config, runtime);
- _PyInitError err = pycore_init_runtime(runtime, core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = pycore_init_runtime(runtime, config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = pycore_create_interpreter(runtime, core_config, &interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pycore_create_interpreter(runtime, config, &interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- core_config = &interp->core_config;
+ config = &interp->config;
*interp_p = interp;
- err = pycore_init_types();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pycore_init_types();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
PyObject *sysmod;
- err = _PySys_Create(runtime, interp, &sysmod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PySys_Create(runtime, interp, &sysmod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = pycore_init_builtins(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pycore_init_builtins(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = pycore_init_import_warnings(interp, sysmod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pycore_init_import_warnings(interp, sysmod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* Only when we get here is the runtime core fully initialized */
runtime->core_initialized = 1;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-_PyInitError
-_Py_PreInitializeFromPyArgv(const _PyPreConfig *src_config, const _PyArgv *args)
+PyStatus
+_Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
{
- _PyInitError err;
+ PyStatus status;
if (src_config == NULL) {
- return _Py_INIT_ERR("preinitialization config is NULL");
+ return _PyStatus_ERR("preinitialization config is NULL");
}
- err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
if (runtime->pre_initialized) {
/* If it's already configured: ignored the new configuration */
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
- _PyPreConfig config;
+ PyPreConfig config;
_PyPreConfig_InitFromPreConfig(&config, src_config);
- err = _PyPreConfig_Read(&config, args);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyPreConfig_Read(&config, args);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyPreConfig_Write(&config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyPreConfig_Write(&config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
runtime->pre_initialized = 1;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-_PyInitError
-_Py_PreInitializeFromArgs(const _PyPreConfig *src_config, Py_ssize_t argc, char **argv)
+PyStatus
+Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, char **argv)
{
_PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
return _Py_PreInitializeFromPyArgv(src_config, &args);
}
-_PyInitError
-_Py_PreInitializeFromWideArgs(const _PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
+PyStatus
+Py_PreInitializeFromArgs(const PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
{
_PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
return _Py_PreInitializeFromPyArgv(src_config, &args);
}
-_PyInitError
-_Py_PreInitialize(const _PyPreConfig *src_config)
+PyStatus
+Py_PreInitialize(const PyPreConfig *src_config)
{
return _Py_PreInitializeFromPyArgv(src_config, NULL);
}
-_PyInitError
-_Py_PreInitializeFromCoreConfig(const _PyCoreConfig *coreconfig,
- const _PyArgv *args)
+PyStatus
+_Py_PreInitializeFromConfig(const PyConfig *config,
+ const _PyArgv *args)
{
- assert(coreconfig != NULL);
+ assert(config != NULL);
- _PyInitError err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
if (runtime->pre_initialized) {
/* Already initialized: do nothing */
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
- _PyPreConfig preconfig;
- _PyPreConfig_InitFromCoreConfig(&preconfig, coreconfig);
+ PyPreConfig preconfig;
+ _PyPreConfig_InitFromConfig(&preconfig, config);
- if (!coreconfig->parse_argv) {
- return _Py_PreInitialize(&preconfig);
+ if (!config->parse_argv) {
+ return Py_PreInitialize(&preconfig);
}
else if (args == NULL) {
_PyArgv config_args = {
.use_bytes_argv = 0,
- .argc = coreconfig->argv.length,
- .wchar_argv = coreconfig->argv.items};
+ .argc = config->argv.length,
+ .wchar_argv = config->argv.items};
return _Py_PreInitializeFromPyArgv(&preconfig, &config_args);
}
else {
@@ -818,74 +818,66 @@ _Py_PreInitializeFromCoreConfig(const _PyCoreConfig *coreconfig,
* to the Python C API (unless the API is explicitly listed as being
* safe to call without calling Py_Initialize first)
*/
-static _PyInitError
+static PyStatus
pyinit_core(_PyRuntimeState *runtime,
- const _PyCoreConfig *src_config,
- const _PyArgv *args,
+ const PyConfig *src_config,
PyInterpreterState **interp_p)
{
- _PyInitError err;
+ PyStatus status;
- err = _Py_PreInitializeFromCoreConfig(src_config, args);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _Py_PreInitializeFromConfig(src_config, NULL);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- _PyCoreConfig config;
- _PyCoreConfig_InitCompatConfig(&config);
+ PyConfig config;
+ _PyConfig_InitCompatConfig(&config);
- err = _PyCoreConfig_Copy(&config, src_config);
- if (_Py_INIT_FAILED(err)) {
+ status = _PyConfig_Copy(&config, src_config);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
- if (args) {
- err = _PyCoreConfig_SetPyArgv(&config, args);
- if (_Py_INIT_FAILED(err)) {
- goto done;
- }
- }
-
- err = _PyCoreConfig_Read(&config);
- if (_Py_INIT_FAILED(err)) {
+ status = PyConfig_Read(&config);
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
if (!runtime->core_initialized) {
- err = pyinit_core_config(runtime, interp_p, &config);
+ status = pyinit_config(runtime, interp_p, &config);
}
else {
- err = pyinit_core_reconfigure(runtime, interp_p, &config);
+ status = pyinit_core_reconfigure(runtime, interp_p, &config);
}
- if (_Py_INIT_FAILED(err)) {
+ if (_PyStatus_EXCEPTION(status)) {
goto done;
}
done:
- _PyCoreConfig_Clear(&config);
- return err;
+ PyConfig_Clear(&config);
+ return status;
}
/* Py_Initialize() has already been called: update the main interpreter
configuration. Example of bpo-34008: Py_Main() called after
Py_Initialize(). */
-static _PyInitError
+static PyStatus
_Py_ReconfigureMainInterpreter(PyInterpreterState *interp)
{
- _PyCoreConfig *core_config = &interp->core_config;
+ PyConfig *config = &interp->config;
- PyObject *argv = _PyWstrList_AsList(&core_config->argv);
+ PyObject *argv = _PyWideStringList_AsList(&config->argv);
if (argv == NULL) {
- return _Py_INIT_NO_MEMORY(); \
+ return _PyStatus_NO_MEMORY(); \
}
int res = PyDict_SetItemString(interp->sysdict, "argv", argv);
Py_DECREF(argv);
if (res < 0) {
- return _Py_INIT_ERR("fail to set sys.argv");
+ return _PyStatus_ERR("fail to set sys.argv");
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* Update interpreter state based on supplied configuration settings
@@ -899,73 +891,73 @@ _Py_ReconfigureMainInterpreter(PyInterpreterState *interp)
* Other errors should be reported as normal Python exceptions with a
* non-zero return code.
*/
-static _PyInitError
+static PyStatus
pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
if (!runtime->core_initialized) {
- return _Py_INIT_ERR("runtime core not initialized");
+ return _PyStatus_ERR("runtime core not initialized");
}
/* Configure the main interpreter */
- _PyCoreConfig *core_config = &interp->core_config;
+ PyConfig *config = &interp->config;
if (runtime->initialized) {
return _Py_ReconfigureMainInterpreter(interp);
}
- if (!core_config->_install_importlib) {
+ if (!config->_install_importlib) {
/* Special mode for freeze_importlib: run with no import system
*
* This means anything which needs support from extension modules
* or pure Python code in the standard library won't work.
*/
runtime->initialized = 1;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
if (_PyTime_Init() < 0) {
- return _Py_INIT_ERR("can't initialize time");
+ return _PyStatus_ERR("can't initialize time");
}
if (_PySys_InitMain(runtime, interp) < 0) {
- return _Py_INIT_ERR("can't finish initializing sys");
+ return _PyStatus_ERR("can't finish initializing sys");
}
- _PyInitError err = init_importlib_external(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = init_importlib_external(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* initialize the faulthandler module */
- err = _PyFaulthandler_Init(core_config->faulthandler);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyFaulthandler_Init(config->faulthandler);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyUnicode_InitEncodings(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyUnicode_InitEncodings(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- if (core_config->install_signal_handlers) {
- err = init_signals();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->install_signal_handlers) {
+ status = init_signals();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- if (_PyTraceMalloc_Init(core_config->tracemalloc) < 0) {
- return _Py_INIT_ERR("can't initialize tracemalloc");
+ if (_PyTraceMalloc_Init(config->tracemalloc) < 0) {
+ return _PyStatus_ERR("can't initialize tracemalloc");
}
- err = add_main_module(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = add_main_module(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = init_sys_streams(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = init_sys_streams(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* Initialize warnings. */
@@ -982,10 +974,10 @@ pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
runtime->initialized = 1;
- if (core_config->site_import) {
- err = init_import_size(); /* Module site */
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->site_import) {
+ status = init_import_size(); /* Module site */
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
@@ -993,16 +985,16 @@ pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
emit_stderr_warning_for_legacy_locale(runtime);
#endif
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
-_PyInitError
+PyStatus
_Py_InitializeMain(void)
{
- _PyInitError err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
@@ -1011,74 +1003,47 @@ _Py_InitializeMain(void)
}
-#undef _INIT_DEBUG_PRINT
-
-static _PyInitError
-pyinit_python(const _PyCoreConfig *config, const _PyArgv *args)
+PyStatus
+Py_InitializeFromConfig(const PyConfig *config)
{
if (config == NULL) {
- return _Py_INIT_ERR("initialization config is NULL");
+ return _PyStatus_ERR("initialization config is NULL");
}
- _PyInitError err;
+ PyStatus status;
- err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
PyInterpreterState *interp = NULL;
- err = pyinit_core(runtime, config, args, &interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pyinit_core(runtime, config, &interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- config = &interp->core_config;
+ config = &interp->config;
if (config->_init_main) {
- err = pyinit_main(runtime, interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = pyinit_main(runtime, interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
- return _Py_INIT_OK();
-}
-
-
-_PyInitError
-_Py_InitializeFromArgs(const _PyCoreConfig *config,
- Py_ssize_t argc, char * const *argv)
-{
- _PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
- return pyinit_python(config, &args);
-}
-
-
-_PyInitError
-_Py_InitializeFromWideArgs(const _PyCoreConfig *config,
- Py_ssize_t argc, wchar_t * const *argv)
-{
- _PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
- return pyinit_python(config, &args);
-}
-
-
-_PyInitError
-_Py_InitializeFromConfig(const _PyCoreConfig *config)
-{
- return pyinit_python(config, NULL);
+ return _PyStatus_OK();
}
void
Py_InitializeEx(int install_sigs)
{
- _PyInitError err;
+ PyStatus status;
- err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- _Py_ExitInitError(err);
+ status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ Py_ExitStatusException(status);
}
_PyRuntimeState *runtime = &_PyRuntime;
@@ -1087,13 +1052,13 @@ Py_InitializeEx(int install_sigs)
return;
}
- _PyCoreConfig config;
- _PyCoreConfig_InitCompatConfig(&config);
+ PyConfig config;
+ _PyConfig_InitCompatConfig(&config);
config.install_signal_handlers = install_sigs;
- err = _Py_InitializeFromConfig(&config);
- if (_Py_INIT_FAILED(err)) {
- _Py_ExitInitError(err);
+ status = Py_InitializeFromConfig(&config);
+ if (_PyStatus_EXCEPTION(status)) {
+ Py_ExitStatusException(status);
}
}
@@ -1206,13 +1171,13 @@ Py_FinalizeEx(void)
/* Copy the core config, PyInterpreterState_Delete() free
the core config memory */
#ifdef Py_REF_DEBUG
- int show_ref_count = interp->core_config.show_ref_count;
+ int show_ref_count = interp->config.show_ref_count;
#endif
#ifdef Py_TRACE_REFS
- int dump_refs = interp->core_config.dump_refs;
+ int dump_refs = interp->config.dump_refs;
#endif
#ifdef WITH_PYMALLOC
- int malloc_stats = interp->core_config.malloc_stats;
+ int malloc_stats = interp->config.malloc_stats;
#endif
/* Remaining threads (e.g. daemon threads) will automatically exit
@@ -1412,19 +1377,19 @@ Py_Finalize(void)
*/
-static _PyInitError
+static PyStatus
new_interpreter(PyThreadState **tstate_p)
{
- _PyInitError err;
+ PyStatus status;
- err = _PyRuntime_Initialize();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyRuntime_Initialize();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
if (!runtime->initialized) {
- return _Py_INIT_ERR("Py_Initialize must be called first");
+ return _PyStatus_ERR("Py_Initialize must be called first");
}
/* Issue #10915, #15751: The GIL API doesn't work with multiple
@@ -1434,49 +1399,49 @@ new_interpreter(PyThreadState **tstate_p)
PyInterpreterState *interp = PyInterpreterState_New();
if (interp == NULL) {
*tstate_p = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
PyThreadState *tstate = PyThreadState_New(interp);
if (tstate == NULL) {
PyInterpreterState_Delete(interp);
*tstate_p = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
/* Copy the current interpreter config into the new interpreter */
- _PyCoreConfig *core_config;
+ PyConfig *config;
if (save_tstate != NULL) {
- core_config = &save_tstate->interp->core_config;
+ config = &save_tstate->interp->config;
} else {
/* No current thread state, copy from the main interpreter */
PyInterpreterState *main_interp = PyInterpreterState_Main();
- core_config = &main_interp->core_config;
+ config = &main_interp->config;
}
- err = _PyCoreConfig_Copy(&interp->core_config, core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyConfig_Copy(&interp->config, config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- core_config = &interp->core_config;
+ config = &interp->config;
- err = _PyExc_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyExc_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyErr_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyErr_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
/* XXX The following is lax in error checking */
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;
@@ -1489,7 +1454,7 @@ new_interpreter(PyThreadState **tstate_p)
Py_INCREF(interp->sysdict);
PyDict_SetItemString(interp->sysdict, "modules", modules);
if (_PySys_InitMain(runtime, interp) < 0) {
- return _Py_INIT_ERR("can't finish initializing sys");
+ return _PyStatus_ERR("can't finish initializing sys");
}
}
else if (PyErr_Occurred()) {
@@ -1508,50 +1473,50 @@ new_interpreter(PyThreadState **tstate_p)
}
if (bimod != NULL && sysmod != NULL) {
- err = _PyBuiltins_AddExceptions(bimod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyBuiltins_AddExceptions(bimod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PySys_SetPreliminaryStderr(interp->sysdict);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PySys_SetPreliminaryStderr(interp->sysdict);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyImportHooks_Init();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyImportHooks_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = init_importlib(interp, sysmod);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = init_importlib(interp, sysmod);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = init_importlib_external(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = init_importlib_external(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PyUnicode_InitEncodings(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PyUnicode_InitEncodings(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = init_sys_streams(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = init_sys_streams(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = add_main_module(interp);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = add_main_module(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- if (core_config->site_import) {
- err = init_import_size();
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->site_import) {
+ status = init_import_size();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
}
}
@@ -1561,7 +1526,7 @@ new_interpreter(PyThreadState **tstate_p)
}
*tstate_p = tstate;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
handle_error:
/* Oops, it didn't work. Undo it all. */
@@ -1573,16 +1538,16 @@ handle_error:
PyInterpreterState_Delete(interp);
*tstate_p = NULL;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
PyThreadState *
Py_NewInterpreter(void)
{
PyThreadState *tstate = NULL;
- _PyInitError err = new_interpreter(&tstate);
- if (_Py_INIT_FAILED(err)) {
- _Py_ExitInitError(err);
+ PyStatus status = new_interpreter(&tstate);
+ if (_PyStatus_EXCEPTION(status)) {
+ Py_ExitStatusException(status);
}
return tstate;
@@ -1627,29 +1592,29 @@ Py_EndInterpreter(PyThreadState *tstate)
/* Add the __main__ module */
-static _PyInitError
+static PyStatus
add_main_module(PyInterpreterState *interp)
{
PyObject *m, *d, *loader, *ann_dict;
m = PyImport_AddModule("__main__");
if (m == NULL)
- return _Py_INIT_ERR("can't create __main__ module");
+ return _PyStatus_ERR("can't create __main__ module");
d = PyModule_GetDict(m);
ann_dict = PyDict_New();
if ((ann_dict == NULL) ||
(PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) {
- return _Py_INIT_ERR("Failed to initialize __main__.__annotations__");
+ return _PyStatus_ERR("Failed to initialize __main__.__annotations__");
}
Py_DECREF(ann_dict);
if (PyDict_GetItemString(d, "__builtins__") == NULL) {
PyObject *bimod = PyImport_ImportModule("builtins");
if (bimod == NULL) {
- return _Py_INIT_ERR("Failed to retrieve builtins module");
+ return _PyStatus_ERR("Failed to retrieve builtins module");
}
if (PyDict_SetItemString(d, "__builtins__", bimod) < 0) {
- return _Py_INIT_ERR("Failed to initialize __main__.__builtins__");
+ return _PyStatus_ERR("Failed to initialize __main__.__builtins__");
}
Py_DECREF(bimod);
}
@@ -1665,28 +1630,28 @@ add_main_module(PyInterpreterState *interp)
PyObject *loader = PyObject_GetAttrString(interp->importlib,
"BuiltinImporter");
if (loader == NULL) {
- return _Py_INIT_ERR("Failed to retrieve BuiltinImporter");
+ return _PyStatus_ERR("Failed to retrieve BuiltinImporter");
}
if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
- return _Py_INIT_ERR("Failed to initialize __main__.__loader__");
+ return _PyStatus_ERR("Failed to initialize __main__.__loader__");
}
Py_DECREF(loader);
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* Import the site module (not into __main__ though) */
-static _PyInitError
+static PyStatus
init_import_size(void)
{
PyObject *m;
m = PyImport_ImportModule("site");
if (m == NULL) {
- return _Py_INIT_ERR("Failed to import the site module");
+ return _PyStatus_ERR("Failed to import the site module");
}
Py_DECREF(m);
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
/* Check if a file descriptor is valid or not.
@@ -1727,7 +1692,7 @@ is_valid_fd(int fd)
/* returns Py_None if the fd is not valid */
static PyObject*
-create_stdio(const _PyCoreConfig *config, PyObject* io,
+create_stdio(const PyConfig *config, PyObject* io,
int fd, int write_mode, const char* name,
const wchar_t* encoding, const wchar_t* errors)
{
@@ -1864,7 +1829,7 @@ error:
}
/* Initialize sys.stdin, stdout, stderr and builtins.open */
-static _PyInitError
+static PyStatus
init_sys_streams(PyInterpreterState *interp)
{
PyObject *iomod = NULL, *wrapper;
@@ -1873,8 +1838,8 @@ init_sys_streams(PyInterpreterState *interp)
PyObject *std = NULL;
int fd;
PyObject * encoding_attr;
- _PyInitError res = _Py_INIT_OK();
- _PyCoreConfig *config = &interp->core_config;
+ PyStatus res = _PyStatus_OK();
+ PyConfig *config = &interp->config;
/* Check that stdin is not a directory
Using shell redirection, you can redirect stdin to a directory,
@@ -1885,7 +1850,7 @@ init_sys_streams(PyInterpreterState *interp)
struct _Py_stat_struct sb;
if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 &&
S_ISDIR(sb.st_mode)) {
- return _Py_INIT_ERR("<stdin> is a directory, cannot continue");
+ return _PyStatus_ERR("<stdin> is a directory, cannot continue");
}
#endif
@@ -1981,7 +1946,7 @@ init_sys_streams(PyInterpreterState *interp)
goto done;
error:
- res = _Py_INIT_ERR("can't initialize sys standard streams");
+ res = _PyStatus_ERR("can't initialize sys standard streams");
done:
_Py_ClearStandardStreamEncoding();
@@ -2183,16 +2148,16 @@ Py_FatalError(const char *msg)
}
void _Py_NO_RETURN
-_Py_ExitInitError(_PyInitError err)
+Py_ExitStatusException(PyStatus status)
{
- if (_Py_INIT_IS_EXIT(err)) {
- exit(err.exitcode);
+ if (_PyStatus_IS_EXIT(status)) {
+ exit(status.exitcode);
}
- else if (_Py_INIT_IS_ERROR(err)) {
- fatal_error(err._func, err.err_msg, 1);
+ else if (_PyStatus_IS_ERROR(status)) {
+ fatal_error(status.func, status.err_msg, 1);
}
else {
- Py_FatalError("_Py_ExitInitError() must not be called on success");
+ Py_FatalError("Py_ExitStatusException() must not be called on success");
}
}
@@ -2284,7 +2249,7 @@ Py_Exit(int sts)
exit(sts);
}
-static _PyInitError
+static PyStatus
init_signals(void)
{
#ifdef SIGPIPE
@@ -2298,9 +2263,9 @@ init_signals(void)
#endif
PyOS_InitInterrupts(); /* May imply initsignal() */
if (PyErr_Occurred()) {
- return _Py_INIT_ERR("can't import signal");
+ return _PyStatus_ERR("can't import signal");
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
diff --git a/Python/pystate.c b/Python/pystate.c
index 41c6622..d1a8d24 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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,
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 26cb02a..665c9c9 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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. */
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 08a1a29..24018e2 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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) {