diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-27 14:39:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 14:39:22 (GMT) |
commit | 331a6a56e9a9c72f3e4605987fabdaec72677702 (patch) | |
tree | 49d20cedd9df4371f2410b2fb24255535ca02c50 /Programs | |
parent | 8cd5165ba05ff57cfdbbc71c393bddad1ce1ab87 (diff) | |
download | cpython-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 'Programs')
-rw-r--r-- | Programs/_freeze_importlib.c | 34 | ||||
-rw-r--r-- | Programs/_testembed.c | 420 | ||||
-rw-r--r-- | Programs/python.c | 2 |
3 files changed, 228 insertions, 228 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index 8cf44d3..13375b0 100644 --- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -36,7 +36,7 @@ main(int argc, char *argv[]) const char *name, *inpath, *outpath; char buf[100]; FILE *infile = NULL, *outfile = NULL; - struct _Py_stat_struct status; + struct _Py_stat_struct stat; size_t text_size, data_size, i, n; char *text = NULL; unsigned char *data; @@ -56,11 +56,11 @@ main(int argc, char *argv[]) fprintf(stderr, "cannot open '%s' for reading\n", inpath); goto error; } - if (_Py_fstat_noraise(fileno(infile), &status)) { + if (_Py_fstat_noraise(fileno(infile), &stat)) { fprintf(stderr, "cannot fstat '%s'\n", inpath); goto error; } - text_size = (size_t)status.st_size; + text_size = (size_t)stat.st_size; text = (char *) malloc(text_size + 1); if (text == NULL) { fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size); @@ -76,32 +76,32 @@ main(int argc, char *argv[]) } text[text_size] = '\0'; - _PyInitError err; - _PyCoreConfig config; + PyStatus status; + PyConfig config; - err = _PyCoreConfig_InitIsolatedConfig(&config); - if (_PyInitError_Failed(err)) { - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + status = PyConfig_InitIsolatedConfig(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); } config.site_import = 0; - err = _PyCoreConfig_SetString(&config, &config.program_name, + status = PyConfig_SetString(&config, &config.program_name, L"./_freeze_importlib"); - if (_PyInitError_Failed(err)) { - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); } /* Don't install importlib, since it could execute outdated bytecode. */ config._install_importlib = 0; config._init_main = 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); } sprintf(buf, "<frozen %s>", name); diff --git a/Programs/_testembed.c b/Programs/_testembed.c index de1c587..3e1210e 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -4,7 +4,7 @@ #endif #include <Python.h> -#include "pycore_coreconfig.h" /* FIXME: PEP 587 makes these functions public */ +#include "pycore_initconfig.h" /* FIXME: PEP 587 makes these functions public */ #include <Python.h> #include "pythread.h" #include <inttypes.h> @@ -328,25 +328,25 @@ static int test_init_initialize_config(void) static int check_init_compat_config(int preinit) { - _PyInitError err; + PyStatus status; if (preinit) { - _PyPreConfig preconfig; + PyPreConfig preconfig; _PyPreConfig_InitCompatConfig(&preconfig); - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } } - _PyCoreConfig config; - _PyCoreConfig_InitCompatConfig(&config); + PyConfig config; + _PyConfig_InitCompatConfig(&config); config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); @@ -418,9 +418,9 @@ static int test_init_global_config(void) static int test_init_from_config(void) { - _PyInitError err; + PyStatus status; - _PyPreConfig preconfig; + PyPreConfig preconfig; _PyPreConfig_InitCompatConfig(&preconfig); putenv("PYTHONMALLOC=malloc_debug"); @@ -430,14 +430,14 @@ static int test_init_from_config(void) Py_UTF8Mode = 0; preconfig.utf8_mode = 1; - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - /* Test _Py_InitializeFromConfig() */ - _PyCoreConfig config; - _PyCoreConfig_InitCompatConfig(&config); + /* Test Py_InitializeFromConfig() */ + PyConfig config; + _PyConfig_InitCompatConfig(&config); config.install_signal_handlers = 0; /* FIXME: test use_environment */ @@ -481,9 +481,9 @@ static int test_init_from_config(void) config.parse_argv = 1; static wchar_t* xoptions[3] = { - L"core_xoption1=3", - L"core_xoption2=", - L"core_xoption3", + L"xoption1=3", + L"xoption2=", + L"xoption3", }; config.xoptions.length = Py_ARRAY_LENGTH(xoptions); config.xoptions.items = xoptions; @@ -494,7 +494,7 @@ static int test_init_from_config(void) config.warnoptions.length = Py_ARRAY_LENGTH(warnoptions); config.warnoptions.items = warnoptions; - /* FIXME: test module_search_path_env */ + /* FIXME: test pythonpath_env */ /* FIXME: test home */ /* FIXME: test path config: module_search_path .. dll_path */ @@ -553,9 +553,9 @@ static int test_init_from_config(void) Py_FrozenFlag = 0; config.pathconfig_warnings = 0; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -565,12 +565,12 @@ static int test_init_from_config(void) static int check_init_parse_argv(int parse_argv) { - _PyInitError err; + PyStatus status; - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } static wchar_t* argv[] = { @@ -587,9 +587,9 @@ static int check_init_parse_argv(int parse_argv) config.argv.items = argv; config.parse_argv = parse_argv; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -652,20 +652,20 @@ static int test_init_compat_env(void) static int test_init_python_env(void) { - _PyInitError err; + PyStatus status; set_all_env_vars(); - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -708,13 +708,13 @@ static int test_init_env_dev_mode_alloc(void) static int test_init_isolated_flag(void) { - _PyInitError err; + PyStatus status; - /* Test _PyCoreConfig.isolated=1 */ - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + /* Test PyConfig.isolated=1 */ + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } Py_IsolatedFlag = 0; @@ -724,9 +724,9 @@ static int test_init_isolated_flag(void) config.program_name = L"./_testembed"; set_all_env_vars(); - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -734,28 +734,28 @@ static int test_init_isolated_flag(void) } -/* _PyPreConfig.isolated=1, _PyCoreConfig.isolated=0 */ +/* PyPreConfig.isolated=1, PyConfig.isolated=0 */ static int test_preinit_isolated1(void) { - _PyInitError err; + PyStatus status; - _PyPreConfig preconfig; + PyPreConfig preconfig; _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 1; - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - _PyCoreConfig config; - _PyCoreConfig_InitCompatConfig(&config); + PyConfig config; + _PyConfig_InitCompatConfig(&config); config.program_name = L"./_testembed"; set_all_env_vars(); - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -763,23 +763,23 @@ static int test_preinit_isolated1(void) } -/* _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1 */ +/* PyPreConfig.isolated=0, PyConfig.isolated=1 */ static int test_preinit_isolated2(void) { - _PyInitError err; + PyStatus status; - _PyPreConfig preconfig; + PyPreConfig preconfig; _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 0; - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - /* Test _PyCoreConfig.isolated=1 */ - _PyCoreConfig config; - _PyCoreConfig_InitCompatConfig(&config); + /* Test PyConfig.isolated=1 */ + PyConfig config; + _PyConfig_InitCompatConfig(&config); Py_IsolatedFlag = 0; config.isolated = 1; @@ -788,9 +788,9 @@ static int test_preinit_isolated2(void) config.program_name = L"./_testembed"; set_all_env_vars(); - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -800,10 +800,10 @@ static int test_preinit_isolated2(void) static int test_preinit_dont_parse_argv(void) { - _PyInitError err; + PyStatus status; - _PyPreConfig preconfig; - _PyPreConfig_InitIsolatedConfig(&preconfig); + PyPreConfig preconfig; + PyPreConfig_InitIsolatedConfig(&preconfig); preconfig.isolated = 0; @@ -814,15 +814,15 @@ static int test_preinit_dont_parse_argv(void) L"-X", L"dev", L"-X", L"utf8", L"script.py"}; - err = _Py_PreInitializeFromWideArgs(&preconfig, Py_ARRAY_LENGTH(argv), argv); - if (_PyInitError_Failed(err)) { + status = Py_PreInitializeFromArgs(&preconfig, Py_ARRAY_LENGTH(argv), argv); + if (PyStatus_Exception(status)) { goto failed; } - _PyCoreConfig config; + PyConfig config; - err = _PyCoreConfig_InitIsolatedConfig(&config); - if (_PyInitError_Failed(err)) { + status = PyConfig_InitIsolatedConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } @@ -830,70 +830,70 @@ static int test_preinit_dont_parse_argv(void) /* Pre-initialize implicitly using argv: make sure that -X dev is used to configure the allocation in preinitialization */ - err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv); - if (_PyInitError_Failed(err)) { + status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv); + if (PyStatus_Exception(status)) { goto failed; } - err = _PyCoreConfig_SetString(&config, &config.program_name, + status = PyConfig_SetString(&config, &config.program_name, L"./_testembed"); - if (_PyInitError_Failed(err)) { + if (PyStatus_Exception(status)) { goto failed; } - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } - _PyCoreConfig_Clear(&config); + PyConfig_Clear(&config); dump_config(); Py_Finalize(); return 0; failed: - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + PyConfig_Clear(&config); + Py_ExitStatusException(status); } static int test_preinit_parse_argv(void) { - _PyInitError err; - _PyCoreConfig config; + PyStatus status; + PyConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } /* Pre-initialize implicitly using argv: make sure that -X dev is used to configure the allocation in preinitialization */ wchar_t *argv[] = {L"python3", L"-X", L"dev", L"script.py"}; - err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv); - if (_PyInitError_Failed(err)) { + status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv); + if (PyStatus_Exception(status)) { goto failed; } - err = _PyCoreConfig_SetString(&config, &config.program_name, + status = PyConfig_SetString(&config, &config.program_name, L"./_testembed"); - if (_PyInitError_Failed(err)) { + if (PyStatus_Exception(status)) { goto failed; } - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } - _PyCoreConfig_Clear(&config); + PyConfig_Clear(&config); dump_config(); Py_Finalize(); return 0; failed: - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + PyConfig_Clear(&config); + Py_ExitStatusException(status); } @@ -923,8 +923,8 @@ static void set_all_global_config_variables(void) static int check_preinit_isolated_config(int preinit) { - _PyInitError err; - _PyPreConfig *rt_preconfig; + PyStatus status; + PyPreConfig *rt_preconfig; /* environment variables must be ignored */ set_all_env_vars(); @@ -933,12 +933,12 @@ static int check_preinit_isolated_config(int preinit) set_all_global_config_variables(); if (preinit) { - _PyPreConfig preconfig; - _PyPreConfig_InitIsolatedConfig(&preconfig); + PyPreConfig preconfig; + PyPreConfig_InitIsolatedConfig(&preconfig); - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } rt_preconfig = &_PyRuntime.preconfig; @@ -946,18 +946,18 @@ static int check_preinit_isolated_config(int preinit) assert(rt_preconfig->use_environment == 0); } - _PyCoreConfig config; - err = _PyCoreConfig_InitIsolatedConfig(&config); - if (_PyInitError_Failed(err)) { - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + PyConfig config; + status = PyConfig_InitIsolatedConfig(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); } config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); } rt_preconfig = &_PyRuntime.preconfig; @@ -984,7 +984,7 @@ static int test_init_isolated_config(void) static int check_init_python_config(int preinit) { - _PyInitError err; + PyStatus status; /* global configuration variables must be ignored */ set_all_global_config_variables(); @@ -1000,25 +1000,25 @@ static int check_init_python_config(int preinit) #endif if (preinit) { - _PyPreConfig preconfig; - _PyPreConfig_InitPythonConfig(&preconfig); + PyPreConfig preconfig; + PyPreConfig_InitPythonConfig(&preconfig); - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } } - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -1040,28 +1040,28 @@ static int test_init_python_config(void) static int test_init_dont_configure_locale(void) { - _PyInitError err; + PyStatus status; - _PyPreConfig preconfig; - _PyPreConfig_InitPythonConfig(&preconfig); + PyPreConfig preconfig; + PyPreConfig_InitPythonConfig(&preconfig); preconfig.configure_locale = 0; preconfig.coerce_c_locale = 1; preconfig.coerce_c_locale_warn = 1; - err = _Py_PreInitialize(&preconfig); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); @@ -1072,19 +1072,19 @@ static int test_init_dont_configure_locale(void) static int test_init_dev_mode(void) { - _PyInitError err; - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyStatus status; + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } putenv("PYTHONFAULTHANDLER="); putenv("PYTHONMALLOC="); config.dev_mode = 1; config.program_name = L"./_testembed"; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } dump_config(); Py_Finalize(); @@ -1250,39 +1250,39 @@ static int test_audit_subinterpreter(void) static int test_init_read_set(void) { - _PyInitError err; - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyStatus status; + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - err = _PyCoreConfig_DecodeLocale(&config, &config.program_name, + status = PyConfig_SetBytesString(&config, &config.program_name, "./init_read_set"); - if (_PyInitError_Failed(err)) { + if (PyStatus_Exception(status)) { goto fail; } - err = _PyCoreConfig_Read(&config); - if (_PyInitError_Failed(err)) { + status = PyConfig_Read(&config); + if (PyStatus_Exception(status)) { goto fail; } - if (_PyWstrList_Append(&config.module_search_paths, - L"init_read_set_path") < 0) { - err = _PyInitError_NoMemory(); + status = PyWideStringList_Append(&config.module_search_paths, + L"init_read_set_path"); + if (PyStatus_Exception(status)) { goto fail; } - /* override executable computed by _PyCoreConfig_Read() */ - err = _PyCoreConfig_SetString(&config, &config.executable, L"my_executable"); - if (_PyInitError_Failed(err)) { + /* override executable computed by PyConfig_Read() */ + status = PyConfig_SetString(&config, &config.executable, L"my_executable"); + if (PyStatus_Exception(status)) { goto fail; } - err = _Py_InitializeFromConfig(&config); - _PyCoreConfig_Clear(&config); - if (_PyInitError_Failed(err)) { + status = Py_InitializeFromConfig(&config); + PyConfig_Clear(&config); + if (PyStatus_Exception(status)) { goto fail; } dump_config(); @@ -1290,7 +1290,7 @@ static int test_init_read_set(void) return 0; fail: - _Py_ExitInitError(err); + Py_ExitStatusException(status); } @@ -1301,7 +1301,7 @@ wchar_t *init_main_argv[] = { L"arg2"}; -static void configure_init_main(_PyCoreConfig *config) +static void configure_init_main(PyConfig *config) { config->argv.length = Py_ARRAY_LENGTH(init_main_argv); config->argv.items = init_main_argv; @@ -1312,38 +1312,38 @@ static void configure_init_main(_PyCoreConfig *config) static int test_init_run_main(void) { - _PyInitError err; - _PyCoreConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + PyStatus status; + PyConfig config; + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } configure_init_main(&config); - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - return _Py_RunMain(); + return Py_RunMain(); } static int test_init_main(void) { - _PyInitError err; - _PyCoreConfig config; + PyStatus status; + PyConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } configure_init_main(&config); config._init_main = 0; - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } /* sys.stdout don't exist yet: it is created by _Py_InitializeMain() */ @@ -1355,51 +1355,51 @@ static int test_init_main(void) exit(1); } - err = _Py_InitializeMain(); - if (_PyInitError_Failed(err)) { - _Py_ExitInitError(err); + status = _Py_InitializeMain(); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); } - return _Py_RunMain(); + return Py_RunMain(); } static int test_run_main(void) { - _PyInitError err; - _PyCoreConfig config; + PyStatus status; + PyConfig config; - err = _PyCoreConfig_InitPythonConfig(&config); - if (_PyInitError_Failed(err)) { + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } wchar_t *argv[] = {L"python3", L"-c", (L"import sys; " - L"print(f'_Py_RunMain(): sys.argv={sys.argv}')"), + L"print(f'Py_RunMain(): sys.argv={sys.argv}')"), L"arg2"}; - err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv); - if (_PyInitError_Failed(err)) { + status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv); + if (PyStatus_Exception(status)) { goto failed; } - err = _PyCoreConfig_SetString(&config, &config.program_name, + status = PyConfig_SetString(&config, &config.program_name, L"./python3"); - if (_PyInitError_Failed(err)) { + if (PyStatus_Exception(status)) { goto failed; } - err = _Py_InitializeFromConfig(&config); - if (_PyInitError_Failed(err)) { + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { goto failed; } - _PyCoreConfig_Clear(&config); + PyConfig_Clear(&config); - return _Py_RunMain(); + return Py_RunMain(); failed: - _PyCoreConfig_Clear(&config); - _Py_ExitInitError(err); + PyConfig_Clear(&config); + Py_ExitStatusException(status); } diff --git a/Programs/python.c b/Programs/python.c index 4c12d38c..1cc3c42 100644 --- a/Programs/python.c +++ b/Programs/python.c @@ -13,6 +13,6 @@ wmain(int argc, wchar_t **argv) int main(int argc, char **argv) { - return _Py_UnixMain(argc, argv); + return Py_BytesMain(argc, argv); } #endif |