@@ -117,10 +117,7 @@ extern "C" {
117117
118118typedef struct {
119119 wchar_t * path_env ; /* PATH environment variable */
120- wchar_t * home ; /* PYTHONHOME environment variable */
121- wchar_t * module_search_path_env ; /* PYTHONPATH environment variable */
122120
123- wchar_t * program_name ; /* Program name */
124121 wchar_t * pythonpath ; /* PYTHONPATH define */
125122 wchar_t * prefix ; /* PREFIX define */
126123 wchar_t * exec_prefix ; /* EXEC_PREFIX define */
@@ -360,14 +357,15 @@ find_env_config_value(FILE * env_file, const wchar_t * key, wchar_t * value)
360357 bytes long.
361358*/
362359static int
363- search_for_prefix (PyCalculatePath * calculate , wchar_t * prefix )
360+ search_for_prefix (const _PyMainInterpreterConfig * main_config ,
361+ PyCalculatePath * calculate , wchar_t * prefix )
364362{
365363 size_t n ;
366364 wchar_t * vpath ;
367365
368366 /* If PYTHONHOME is set, we believe it unconditionally */
369- if (calculate -> home ) {
370- wcsncpy (prefix , calculate -> home , MAXPATHLEN );
367+ if (main_config -> home ) {
368+ wcsncpy (prefix , main_config -> home , MAXPATHLEN );
371369 prefix [MAXPATHLEN ] = L'\0' ;
372370 wchar_t * delim = wcschr (prefix , DELIM );
373371 if (delim ) {
@@ -426,9 +424,10 @@ search_for_prefix(PyCalculatePath *calculate, wchar_t *prefix)
426424
427425
428426static void
429- calculate_prefix (PyCalculatePath * calculate , wchar_t * prefix )
427+ calculate_prefix (const _PyMainInterpreterConfig * main_config ,
428+ PyCalculatePath * calculate , wchar_t * prefix )
430429{
431- calculate -> prefix_found = search_for_prefix (calculate , prefix );
430+ calculate -> prefix_found = search_for_prefix (main_config , calculate , prefix );
432431 if (!calculate -> prefix_found ) {
433432 if (!Py_FrozenFlag ) {
434433 fprintf (stderr ,
@@ -470,18 +469,19 @@ calculate_reduce_prefix(PyCalculatePath *calculate, wchar_t *prefix)
470469 MAXPATHLEN bytes long.
471470*/
472471static int
473- search_for_exec_prefix (PyCalculatePath * calculate , wchar_t * exec_prefix )
472+ search_for_exec_prefix (const _PyMainInterpreterConfig * main_config ,
473+ PyCalculatePath * calculate , wchar_t * exec_prefix )
474474{
475475 size_t n ;
476476
477477 /* If PYTHONHOME is set, we believe it unconditionally */
478- if (calculate -> home ) {
479- wchar_t * delim = wcschr (calculate -> home , DELIM );
478+ if (main_config -> home ) {
479+ wchar_t * delim = wcschr (main_config -> home , DELIM );
480480 if (delim ) {
481481 wcsncpy (exec_prefix , delim + 1 , MAXPATHLEN );
482482 }
483483 else {
484- wcsncpy (exec_prefix , calculate -> home , MAXPATHLEN );
484+ wcsncpy (exec_prefix , main_config -> home , MAXPATHLEN );
485485 }
486486 exec_prefix [MAXPATHLEN ] = L'\0' ;
487487 joinpath (exec_prefix , calculate -> lib_python );
@@ -552,9 +552,12 @@ search_for_exec_prefix(PyCalculatePath *calculate, wchar_t *exec_prefix)
552552
553553
554554static void
555- calculate_exec_prefix (PyCalculatePath * calculate , wchar_t * exec_prefix )
555+ calculate_exec_prefix (const _PyMainInterpreterConfig * main_config ,
556+ PyCalculatePath * calculate , wchar_t * exec_prefix )
556557{
557- calculate -> exec_prefix_found = search_for_exec_prefix (calculate , exec_prefix );
558+ calculate -> exec_prefix_found = search_for_exec_prefix (main_config ,
559+ calculate ,
560+ exec_prefix );
558561 if (!calculate -> exec_prefix_found ) {
559562 if (!Py_FrozenFlag ) {
560563 fprintf (stderr ,
@@ -585,7 +588,8 @@ calculate_reduce_exec_prefix(PyCalculatePath *calculate, wchar_t *exec_prefix)
585588
586589
587590static _PyInitError
588- calculate_program_full_path (PyCalculatePath * calculate , _PyPathConfig * config )
591+ calculate_program_full_path (const _PyMainInterpreterConfig * main_config ,
592+ PyCalculatePath * calculate , _PyPathConfig * config )
589593{
590594 wchar_t program_full_path [MAXPATHLEN + 1 ];
591595 memset (program_full_path , 0 , sizeof (program_full_path ));
@@ -604,8 +608,8 @@ calculate_program_full_path(PyCalculatePath *calculate, _PyPathConfig *config)
604608 * other way to find a directory to start the search from. If
605609 * $PATH isn't exported, you lose.
606610 */
607- if (wcschr (calculate -> program_name , SEP )) {
608- wcsncpy (program_full_path , calculate -> program_name , MAXPATHLEN );
611+ if (wcschr (main_config -> program_name , SEP )) {
612+ wcsncpy (program_full_path , main_config -> program_name , MAXPATHLEN );
609613 }
610614#ifdef __APPLE__
611615 /* On Mac OS X, if a script uses an interpreter of the form
@@ -645,7 +649,7 @@ calculate_program_full_path(PyCalculatePath *calculate, _PyPathConfig *config)
645649 wcsncpy (program_full_path , path , MAXPATHLEN );
646650 }
647651
648- joinpath (program_full_path , calculate -> program_name );
652+ joinpath (program_full_path , main_config -> program_name );
649653 if (isxfile (program_full_path )) {
650654 break ;
651655 }
@@ -810,14 +814,15 @@ calculate_zip_path(PyCalculatePath *calculate, const wchar_t *prefix)
810814
811815
812816static _PyInitError
813- calculate_module_search_path (PyCalculatePath * calculate ,
817+ calculate_module_search_path (const _PyMainInterpreterConfig * main_config ,
818+ PyCalculatePath * calculate ,
814819 const wchar_t * prefix , const wchar_t * exec_prefix ,
815820 _PyPathConfig * config )
816821{
817822 /* Calculate size of return buffer */
818823 size_t bufsz = 0 ;
819- if (calculate -> module_search_path_env != NULL ) {
820- bufsz += wcslen (calculate -> module_search_path_env ) + 1 ;
824+ if (main_config -> module_search_path_env != NULL ) {
825+ bufsz += wcslen (main_config -> module_search_path_env ) + 1 ;
821826 }
822827
823828 wchar_t * defpath = calculate -> pythonpath ;
@@ -851,8 +856,8 @@ calculate_module_search_path(PyCalculatePath *calculate,
851856 buf [0 ] = '\0' ;
852857
853858 /* Run-time value of $PYTHONPATH goes first */
854- if (calculate -> module_search_path_env ) {
855- wcscpy (buf , calculate -> module_search_path_env );
859+ if (main_config -> module_search_path_env ) {
860+ wcscpy (buf , main_config -> module_search_path_env );
856861 wcscat (buf , delimiter );
857862 }
858863
@@ -903,10 +908,6 @@ static _PyInitError
903908calculate_init (PyCalculatePath * calculate ,
904909 const _PyMainInterpreterConfig * main_config )
905910{
906- calculate -> home = main_config -> home ;
907- calculate -> module_search_path_env = main_config -> module_search_path_env ;
908- calculate -> program_name = main_config -> program_name ;
909-
910911 size_t len ;
911912 char * path = getenv ("PATH" );
912913 if (path ) {
@@ -948,9 +949,12 @@ calculate_free(PyCalculatePath *calculate)
948949
949950
950951static _PyInitError
951- calculate_path_impl (PyCalculatePath * calculate , _PyPathConfig * config )
952+ calculate_path_impl (const _PyMainInterpreterConfig * main_config ,
953+ PyCalculatePath * calculate , _PyPathConfig * config )
952954{
953- _PyInitError err = calculate_program_full_path (calculate , config );
955+ _PyInitError err ;
956+
957+ err = calculate_program_full_path (main_config , calculate , config );
954958 if (_Py_INIT_FAILED (err )) {
955959 return err ;
956960 }
@@ -964,13 +968,13 @@ calculate_path_impl(PyCalculatePath *calculate, _PyPathConfig *config)
964968
965969 wchar_t prefix [MAXPATHLEN + 1 ];
966970 memset (prefix , 0 , sizeof (prefix ));
967- calculate_prefix (calculate , prefix );
971+ calculate_prefix (main_config , calculate , prefix );
968972
969973 calculate_zip_path (calculate , prefix );
970974
971975 wchar_t exec_prefix [MAXPATHLEN + 1 ];
972976 memset (exec_prefix , 0 , sizeof (exec_prefix ));
973- calculate_exec_prefix (calculate , exec_prefix );
977+ calculate_exec_prefix (main_config , calculate , exec_prefix );
974978
975979 if ((!calculate -> prefix_found || !calculate -> exec_prefix_found ) &&
976980 !Py_FrozenFlag )
@@ -979,8 +983,8 @@ calculate_path_impl(PyCalculatePath *calculate, _PyPathConfig *config)
979983 "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n" );
980984 }
981985
982- err = calculate_module_search_path (calculate , prefix , exec_prefix ,
983- config );
986+ err = calculate_module_search_path (main_config , calculate ,
987+ prefix , exec_prefix , config );
984988 if (_Py_INIT_FAILED (err )) {
985989 return err ;
986990 }
@@ -1041,7 +1045,7 @@ _PyPathConfig_Init(const _PyMainInterpreterConfig *main_config)
10411045 _PyPathConfig new_path_config ;
10421046 memset (& new_path_config , 0 , sizeof (new_path_config ));
10431047
1044- err = calculate_path_impl (& calculate , & new_path_config );
1048+ err = calculate_path_impl (main_config , & calculate , & new_path_config );
10451049 if (_Py_INIT_FAILED (err )) {
10461050 pathconfig_clear (& new_path_config );
10471051 goto done ;
@@ -1068,14 +1072,26 @@ pathconfig_global_init(void)
10681072 _PyMainInterpreterConfig config = _PyMainInterpreterConfig_INIT ;
10691073
10701074 err = _PyMainInterpreterConfig_ReadEnv (& config );
1071- if (!_Py_INIT_FAILED (err )) {
1072- err = _PyPathConfig_Init (& config );
1075+ if (_Py_INIT_FAILED (err )) {
1076+ goto error ;
1077+ }
1078+
1079+ err = _PyMainInterpreterConfig_Read (& config );
1080+ if (_Py_INIT_FAILED (err )) {
1081+ goto error ;
10731082 }
1074- _PyMainInterpreterConfig_Clear (& config );
10751083
1084+ err = _PyPathConfig_Init (& config );
10761085 if (_Py_INIT_FAILED (err )) {
1077- _Py_FatalInitError ( err ) ;
1086+ goto error ;
10781087 }
1088+
1089+ _PyMainInterpreterConfig_Clear (& config );
1090+ return ;
1091+
1092+ error :
1093+ _PyMainInterpreterConfig_Clear (& config );
1094+ _Py_FatalInitError (err );
10791095}
10801096
10811097
0 commit comments