@@ -2005,9 +2005,14 @@ void
20052005_PyMainInterpreterConfig_Clear (_PyMainInterpreterConfig * config )
20062006{
20072007 Py_CLEAR (config -> argv );
2008- Py_CLEAR (config -> module_search_path );
2008+ Py_CLEAR (config -> executable );
2009+ Py_CLEAR (config -> prefix );
2010+ Py_CLEAR (config -> base_prefix );
2011+ Py_CLEAR (config -> exec_prefix );
2012+ Py_CLEAR (config -> base_exec_prefix );
20092013 Py_CLEAR (config -> warnoptions );
20102014 Py_CLEAR (config -> xoptions );
2015+ Py_CLEAR (config -> module_search_path );
20112016}
20122017
20132018
@@ -2052,9 +2057,14 @@ _PyMainInterpreterConfig_Copy(_PyMainInterpreterConfig *config,
20522057 } while (0)
20532058
20542059 COPY_ATTR (argv );
2055- COPY_ATTR (module_search_path );
2060+ COPY_ATTR (executable );
2061+ COPY_ATTR (prefix );
2062+ COPY_ATTR (base_prefix );
2063+ COPY_ATTR (exec_prefix );
2064+ COPY_ATTR (base_exec_prefix );
20562065 COPY_ATTR (warnoptions );
20572066 COPY_ATTR (xoptions );
2067+ COPY_ATTR (module_search_path );
20582068#undef COPY_ATTR
20592069 return 0 ;
20602070}
@@ -2099,39 +2109,60 @@ config_create_path_list(const wchar_t *path, wchar_t delim)
20992109}
21002110
21012111
2102- static _PyInitError
2103- config_init_module_search_path (_PyMainInterpreterConfig * config , _PyCoreConfig * core_config )
2112+ _PyInitError
2113+ _PyMainInterpreterConfig_Read (_PyMainInterpreterConfig * config , _PyCoreConfig * core_config )
21042114{
21052115 _PyInitError err = _PyPathConfig_Init (core_config );
21062116 if (_Py_INIT_FAILED (err )) {
21072117 return err ;
21082118 }
2109- wchar_t * sys_path = Py_GetPath ();
21102119
2111- config -> module_search_path = config_create_path_list (sys_path , DELIM );
2112- if (config -> module_search_path == NULL ) {
2113- return _Py_INIT_NO_MEMORY ();
2114- }
2115- return _Py_INIT_OK ();
2116- }
2117-
2118-
2119- _PyInitError
2120- _PyMainInterpreterConfig_Read (_PyMainInterpreterConfig * config , _PyCoreConfig * core_config )
2121- {
21222120 /* Signal handlers are installed by default */
21232121 if (config -> install_signal_handlers < 0 ) {
21242122 config -> install_signal_handlers = 1 ;
21252123 }
21262124
21272125 if (config -> module_search_path == NULL &&
21282126 !core_config -> _disable_importlib )
2127+
21292128 {
2130- _PyInitError err = config_init_module_search_path (config , core_config );
2131- if (_Py_INIT_FAILED (err )) {
2132- return err ;
2129+ wchar_t * sys_path = Py_GetPath ();
2130+ config -> module_search_path = config_create_path_list (sys_path , DELIM );
2131+ if (config -> module_search_path == NULL ) {
2132+ return _Py_INIT_NO_MEMORY ();
21332133 }
21342134 }
2135+
2136+ if (config -> executable == NULL ) {
2137+ config -> executable = PyUnicode_FromWideChar (Py_GetProgramFullPath (), -1 );
2138+ if (config -> executable == NULL ) {
2139+ return _Py_INIT_NO_MEMORY ();
2140+ }
2141+ }
2142+
2143+ if (config -> prefix == NULL ) {
2144+ config -> prefix = PyUnicode_FromWideChar (Py_GetPrefix (), -1 );
2145+ if (config -> prefix == NULL ) {
2146+ return _Py_INIT_NO_MEMORY ();
2147+ }
2148+ }
2149+
2150+ if (config -> exec_prefix == NULL ) {
2151+ config -> exec_prefix = PyUnicode_FromWideChar (Py_GetExecPrefix (), -1 );
2152+ if (config -> exec_prefix == NULL ) {
2153+ return _Py_INIT_NO_MEMORY ();
2154+ }
2155+ }
2156+
2157+ if (config -> base_prefix == NULL ) {
2158+ Py_INCREF (config -> prefix );
2159+ config -> base_prefix = config -> prefix ;
2160+ }
2161+
2162+ if (config -> base_exec_prefix == NULL ) {
2163+ Py_INCREF (config -> exec_prefix );
2164+ config -> base_exec_prefix = config -> exec_prefix ;
2165+ }
21352166 return _Py_INIT_OK ();
21362167}
21372168
0 commit comments