@@ -128,6 +128,8 @@ typedef struct {
128
128
129
129
wchar_t argv0_path [MAXPATHLEN + 1 ];
130
130
wchar_t zip_path [MAXPATHLEN + 1 ];
131
+
132
+ wchar_t * dll_path ;
131
133
} PyCalculatePath ;
132
134
133
135
@@ -666,28 +668,36 @@ read_pth_file(_PyPathConfig *pathconfig, wchar_t *prefix, const wchar_t *path)
666
668
}
667
669
668
670
669
- static void
671
+ static PyStatus
670
672
calculate_init (PyCalculatePath * calculate ,
671
673
const PyConfig * config )
672
674
{
673
675
calculate -> home = config -> home ;
674
676
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 ();
675
684
}
676
685
677
686
678
687
static int
679
- get_pth_filename (wchar_t * spbuffer , _PyPathConfig * pathconfig )
688
+ get_pth_filename (PyCalculatePath * calculate , wchar_t * filename ,
689
+ const _PyPathConfig * pathconfig )
680
690
{
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 ))
684
694
{
685
695
return 1 ;
686
696
}
687
697
}
688
698
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 ))
691
701
{
692
702
return 1 ;
693
703
}
@@ -697,15 +707,16 @@ get_pth_filename(wchar_t *spbuffer, _PyPathConfig *pathconfig)
697
707
698
708
699
709
static int
700
- calculate_pth_file (_PyPathConfig * pathconfig , wchar_t * prefix )
710
+ calculate_pth_file (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
711
+ wchar_t * prefix )
701
712
{
702
- wchar_t spbuffer [MAXPATHLEN + 1 ];
713
+ wchar_t filename [MAXPATHLEN + 1 ];
703
714
704
- if (!get_pth_filename (spbuffer , pathconfig )) {
715
+ if (!get_pth_filename (calculate , filename , pathconfig )) {
705
716
return 0 ;
706
717
}
707
718
708
- return read_pth_file (pathconfig , prefix , spbuffer );
719
+ return read_pth_file (pathconfig , prefix , filename );
709
720
}
710
721
711
722
@@ -966,13 +977,6 @@ calculate_path_impl(const PyConfig *config,
966
977
{
967
978
PyStatus status ;
968
979
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
-
976
980
status = get_program_full_path (config , calculate , pathconfig );
977
981
if (_PyStatus_EXCEPTION (status )) {
978
982
return status ;
@@ -986,22 +990,25 @@ calculate_path_impl(const PyConfig *config,
986
990
memset (prefix , 0 , sizeof (prefix ));
987
991
988
992
/* Search for a sys.path file */
989
- if (calculate_pth_file (pathconfig , prefix )) {
993
+ if (calculate_pth_file (calculate , pathconfig , prefix )) {
990
994
goto done ;
991
995
}
992
996
993
997
calculate_pyvenv_file (calculate );
994
998
995
999
/* Calculate zip archive path from DLL or exe path */
996
1000
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 ,
998
1002
L".zip" );
999
1003
1000
1004
calculate_home_prefix (calculate , prefix );
1001
1005
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
+ }
1005
1012
}
1006
1013
1007
1014
done :
@@ -1023,23 +1030,23 @@ calculate_free(PyCalculatePath *calculate)
1023
1030
{
1024
1031
PyMem_RawFree (calculate -> machine_path );
1025
1032
PyMem_RawFree (calculate -> user_path );
1033
+ PyMem_RawFree (calculate -> dll_path );
1026
1034
}
1027
1035
1028
1036
1029
1037
PyStatus
1030
1038
_PyPathConfig_Calculate (_PyPathConfig * pathconfig , const PyConfig * config )
1031
1039
{
1040
+ PyStatus status ;
1032
1041
PyCalculatePath calculate ;
1033
1042
memset (& calculate , 0 , sizeof (calculate ));
1034
1043
1035
- calculate_init (& calculate , config );
1036
-
1037
- PyStatus status = calculate_path_impl (config , & calculate , pathconfig );
1044
+ status = calculate_init (& calculate , config );
1038
1045
if (_PyStatus_EXCEPTION (status )) {
1039
1046
goto done ;
1040
1047
}
1041
1048
1042
- status = _PyStatus_OK ( );
1049
+ status = calculate_path_impl ( config , & calculate , pathconfig );
1043
1050
1044
1051
done :
1045
1052
calculate_free (& calculate );
@@ -1067,7 +1074,12 @@ _Py_CheckPython3(void)
1067
1074
1068
1075
/* If there is a python3.dll next to the python3y.dll,
1069
1076
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
+ }
1071
1083
s = wcsrchr (py3path , L'\\' );
1072
1084
if (!s ) {
1073
1085
s = py3path ;
0 commit comments