@@ -128,6 +128,8 @@ typedef struct {
128128
129129 wchar_t argv0_path [MAXPATHLEN + 1 ];
130130 wchar_t zip_path [MAXPATHLEN + 1 ];
131+
132+ wchar_t * dll_path ;
131133} PyCalculatePath ;
132134
133135
@@ -666,28 +668,36 @@ read_pth_file(_PyPathConfig *pathconfig, wchar_t *prefix, const wchar_t *path)
666668}
667669
668670
669- static void
671+ static PyStatus
670672calculate_init (PyCalculatePath * calculate ,
671673 const PyConfig * config )
672674{
673675 calculate -> home = config -> home ;
674676 calculate -> path_env = _wgetenv (L"PATH" );
677+
678+ calculate -> dll_path = _Py_GetDLLPath ();
679+ if (calculate -> dll_path == NULL ) {
680+ return _PyStatus_NO_MEMORY ();
681+ }
682+
683+ return _PyStatus_OK ();
675684}
676685
677686
678687static int
679- get_pth_filename (wchar_t * spbuffer , _PyPathConfig * pathconfig )
688+ get_pth_filename (PyCalculatePath * calculate , wchar_t * filename ,
689+ const _PyPathConfig * pathconfig )
680690{
681- if (pathconfig -> dll_path [0 ]) {
682- if (!change_ext (spbuffer , pathconfig -> dll_path , L"._pth" ) &&
683- exists (spbuffer ))
691+ if (calculate -> dll_path [0 ]) {
692+ if (!change_ext (filename , calculate -> dll_path , L"._pth" ) &&
693+ exists (filename ))
684694 {
685695 return 1 ;
686696 }
687697 }
688698 if (pathconfig -> program_full_path [0 ]) {
689- if (!change_ext (spbuffer , pathconfig -> program_full_path , L"._pth" ) &&
690- exists (spbuffer ))
699+ if (!change_ext (filename , pathconfig -> program_full_path , L"._pth" ) &&
700+ exists (filename ))
691701 {
692702 return 1 ;
693703 }
@@ -697,15 +707,16 @@ get_pth_filename(wchar_t *spbuffer, _PyPathConfig *pathconfig)
697707
698708
699709static int
700- calculate_pth_file (_PyPathConfig * pathconfig , wchar_t * prefix )
710+ calculate_pth_file (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
711+ wchar_t * prefix )
701712{
702- wchar_t spbuffer [MAXPATHLEN + 1 ];
713+ wchar_t filename [MAXPATHLEN + 1 ];
703714
704- if (!get_pth_filename (spbuffer , pathconfig )) {
715+ if (!get_pth_filename (calculate , filename , pathconfig )) {
705716 return 0 ;
706717 }
707718
708- return read_pth_file (pathconfig , prefix , spbuffer );
719+ return read_pth_file (pathconfig , prefix , filename );
709720}
710721
711722
@@ -966,13 +977,6 @@ calculate_path_impl(const PyConfig *config,
966977{
967978 PyStatus status ;
968979
969- assert (pathconfig -> dll_path == NULL );
970-
971- pathconfig -> dll_path = _Py_GetDLLPath ();
972- if (pathconfig -> dll_path == NULL ) {
973- return _PyStatus_NO_MEMORY ();
974- }
975-
976980 status = get_program_full_path (config , calculate , pathconfig );
977981 if (_PyStatus_EXCEPTION (status )) {
978982 return status ;
@@ -986,22 +990,25 @@ calculate_path_impl(const PyConfig *config,
986990 memset (prefix , 0 , sizeof (prefix ));
987991
988992 /* Search for a sys.path file */
989- if (calculate_pth_file (pathconfig , prefix )) {
993+ if (calculate_pth_file (calculate , pathconfig , prefix )) {
990994 goto done ;
991995 }
992996
993997 calculate_pyvenv_file (calculate );
994998
995999 /* Calculate zip archive path from DLL or exe path */
9961000 change_ext (calculate -> zip_path ,
997- pathconfig -> dll_path [0 ] ? pathconfig -> dll_path : pathconfig -> program_full_path ,
1001+ calculate -> dll_path [0 ] ? calculate -> dll_path : pathconfig -> program_full_path ,
9981002 L".zip" );
9991003
10001004 calculate_home_prefix (calculate , prefix );
10011005
1002- status = calculate_module_search_path (config , calculate , pathconfig , prefix );
1003- if (_PyStatus_EXCEPTION (status )) {
1004- return status ;
1006+ if (pathconfig -> module_search_path == NULL ) {
1007+ status = calculate_module_search_path (config , calculate ,
1008+ pathconfig , prefix );
1009+ if (_PyStatus_EXCEPTION (status )) {
1010+ return status ;
1011+ }
10051012 }
10061013
10071014done :
@@ -1023,23 +1030,23 @@ calculate_free(PyCalculatePath *calculate)
10231030{
10241031 PyMem_RawFree (calculate -> machine_path );
10251032 PyMem_RawFree (calculate -> user_path );
1033+ PyMem_RawFree (calculate -> dll_path );
10261034}
10271035
10281036
10291037PyStatus
10301038_PyPathConfig_Calculate (_PyPathConfig * pathconfig , const PyConfig * config )
10311039{
1040+ PyStatus status ;
10321041 PyCalculatePath calculate ;
10331042 memset (& calculate , 0 , sizeof (calculate ));
10341043
1035- calculate_init (& calculate , config );
1036-
1037- PyStatus status = calculate_path_impl (config , & calculate , pathconfig );
1044+ status = calculate_init (& calculate , config );
10381045 if (_PyStatus_EXCEPTION (status )) {
10391046 goto done ;
10401047 }
10411048
1042- status = _PyStatus_OK ( );
1049+ status = calculate_path_impl ( config , & calculate , pathconfig );
10431050
10441051done :
10451052 calculate_free (& calculate );
@@ -1067,7 +1074,12 @@ _Py_CheckPython3(void)
10671074
10681075 /* If there is a python3.dll next to the python3y.dll,
10691076 assume this is a build tree; use that DLL */
1070- wcscpy (py3path , _Py_path_config .dll_path );
1077+ if (_Py_dll_path != NULL ) {
1078+ wcscpy (py3path , _Py_dll_path );
1079+ }
1080+ else {
1081+ wcscpy (py3path , L"" );
1082+ }
10711083 s = wcsrchr (py3path , L'\\' );
10721084 if (!s ) {
10731085 s = py3path ;
0 commit comments