diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-10 12:21:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 12:21:52 (GMT) |
commit | 9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba (patch) | |
tree | 6062eedbc8405d7a9d20caad2080c41ae01cdd00 /Python/sysmodule.c | |
parent | 38811d68caf9b782ea7168479acb09557e126efe (diff) | |
download | cpython-9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba.zip cpython-9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba.tar.gz cpython-9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba.tar.bz2 |
bpo-42260: Compute the path config in the main init (GH-23211)
The path configuration is now computed in the "main" initialization.
The core initialization no longer computes it.
* Add _PyConfig_Read() function to read the configuration without
computing the path configuration.
* pyinit_core() no longer computes the path configuration: it is now
computed by init_interp_main().
* The path configuration output members of PyConfig are now optional:
* executable
* base_executable
* prefix
* base_prefix
* exec_prefix
* base_exec_prefix
* _PySys_UpdateConfig() now skips NULL strings in PyConfig.
* _testembed: Rename test_set_config() to test_init_set_config() for
consistency with other tests.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ae4f0ee..61741f7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2922,17 +2922,22 @@ _PySys_UpdateConfig(PyThreadState *tstate) #define SET_SYS_FROM_WSTR(KEY, VALUE) \ SET_SYS(KEY, PyUnicode_FromWideChar(VALUE, -1)); +#define COPY_WSTR(SYS_ATTR, WSTR) \ + if (WSTR != NULL) { \ + SET_SYS_FROM_WSTR(SYS_ATTR, WSTR); \ + } + if (config->module_search_paths_set) { COPY_LIST("path", config->module_search_paths); } - SET_SYS_FROM_WSTR("executable", config->executable); - SET_SYS_FROM_WSTR("_base_executable", config->base_executable); - SET_SYS_FROM_WSTR("prefix", config->prefix); - SET_SYS_FROM_WSTR("base_prefix", config->base_prefix); - SET_SYS_FROM_WSTR("exec_prefix", config->exec_prefix); - SET_SYS_FROM_WSTR("base_exec_prefix", config->base_exec_prefix); - SET_SYS_FROM_WSTR("platlibdir", config->platlibdir); + COPY_WSTR("executable", config->executable); + COPY_WSTR("_base_executable", config->base_executable); + COPY_WSTR("prefix", config->prefix); + COPY_WSTR("base_prefix", config->base_prefix); + COPY_WSTR("exec_prefix", config->exec_prefix); + COPY_WSTR("base_exec_prefix", config->base_exec_prefix); + COPY_WSTR("platlibdir", config->platlibdir); if (config->pycache_prefix != NULL) { SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix); @@ -2946,8 +2951,9 @@ _PySys_UpdateConfig(PyThreadState *tstate) SET_SYS("_xoptions", sys_create_xoptions_dict(config)); -#undef COPY_LIST #undef SET_SYS_FROM_WSTR +#undef COPY_LIST +#undef COPY_WSTR // sys.flags PyObject *flags = _PySys_GetObject(tstate, "flags"); // borrowed ref |