@@ -650,7 +650,7 @@ pymain_free_raw(_PyMain *pymain)
650
650
configuration options set before Py_Initialize() which should
651
651
remain valid after Py_Finalize(), since
652
652
Py_Initialize()-Py_Finalize() can be called multiple times. */
653
- _PyPathConfig_Clear ( & _Py_path_config );
653
+ _PyPathConfig_ClearGlobal ( );
654
654
655
655
pymain_clear_config (pymain );
656
656
@@ -701,9 +701,13 @@ pymain_run_main_from_importer(_PyMain *pymain)
701
701
}
702
702
703
703
704
- static _PyInitError
705
- wstrlist_append (int * len , wchar_t * * * list , const wchar_t * str )
704
+ _PyInitError
705
+ _Py_wstrlist_append (int * len , wchar_t * * * list , const wchar_t * str )
706
706
{
707
+ if (* len == INT_MAX ) {
708
+ /* len+1 would overflow */
709
+ return _Py_INIT_NO_MEMORY ();
710
+ }
707
711
wchar_t * str2 = _PyMem_RawWcsdup (str );
708
712
if (str2 == NULL ) {
709
713
return _Py_INIT_NO_MEMORY ();
@@ -725,7 +729,7 @@ wstrlist_append(int *len, wchar_t ***list, const wchar_t *str)
725
729
static int
726
730
pymain_wstrlist_append (_PyMain * pymain , int * len , wchar_t * * * list , const wchar_t * str )
727
731
{
728
- _PyInitError err = wstrlist_append (len , list , str );
732
+ _PyInitError err = _Py_wstrlist_append (len , list , str );
729
733
if (_Py_INIT_FAILED (err )) {
730
734
pymain -> err = err ;
731
735
return -1 ;
@@ -972,9 +976,9 @@ static _PyInitError
972
976
config_add_warnings_optlist (_PyCoreConfig * config , int len , wchar_t * * options )
973
977
{
974
978
for (int i = 0 ; i < len ; i ++ ) {
975
- _PyInitError err = wstrlist_append (& config -> nwarnoption ,
976
- & config -> warnoptions ,
977
- options [i ]);
979
+ _PyInitError err = _Py_wstrlist_append (& config -> nwarnoption ,
980
+ & config -> warnoptions ,
981
+ options [i ]);
978
982
if (_Py_INIT_FAILED (err )) {
979
983
return err ;
980
984
}
@@ -1006,9 +1010,9 @@ config_init_warnoptions(_PyCoreConfig *config, _Py_CommandLineDetails *cmdline)
1006
1010
*/
1007
1011
1008
1012
if (config -> dev_mode ) {
1009
- err = wstrlist_append (& config -> nwarnoption ,
1010
- & config -> warnoptions ,
1011
- L"default" );
1013
+ err = _Py_wstrlist_append (& config -> nwarnoption ,
1014
+ & config -> warnoptions ,
1015
+ L"default" );
1012
1016
if (_Py_INIT_FAILED (err )) {
1013
1017
return err ;
1014
1018
}
@@ -1040,9 +1044,9 @@ config_init_warnoptions(_PyCoreConfig *config, _Py_CommandLineDetails *cmdline)
1040
1044
else {
1041
1045
filter = L"default::BytesWarning" ;
1042
1046
}
1043
- err = wstrlist_append (& config -> nwarnoption ,
1044
- & config -> warnoptions ,
1045
- filter );
1047
+ err = _Py_wstrlist_append (& config -> nwarnoption ,
1048
+ & config -> warnoptions ,
1049
+ filter );
1046
1050
if (_Py_INIT_FAILED (err )) {
1047
1051
return err ;
1048
1052
}
@@ -1077,9 +1081,9 @@ cmdline_init_env_warnoptions(_Py_CommandLineDetails *cmdline)
1077
1081
warning != NULL ;
1078
1082
warning = WCSTOK (NULL , L"," , & context ))
1079
1083
{
1080
- _PyInitError err = wstrlist_append (& cmdline -> nenv_warnoption ,
1081
- & cmdline -> env_warnoptions ,
1082
- warning );
1084
+ _PyInitError err = _Py_wstrlist_append (& cmdline -> nenv_warnoption ,
1085
+ & cmdline -> env_warnoptions ,
1086
+ warning );
1083
1087
if (_Py_INIT_FAILED (err )) {
1084
1088
PyMem_RawFree (env );
1085
1089
return err ;
@@ -2099,101 +2103,6 @@ config_init_locale(_PyCoreConfig *config)
2099
2103
}
2100
2104
2101
2105
2102
- static _PyInitError
2103
- config_init_module_search_paths (_PyCoreConfig * config )
2104
- {
2105
- assert (config -> module_search_paths == NULL );
2106
- assert (config -> nmodule_search_path < 0 );
2107
-
2108
- config -> nmodule_search_path = 0 ;
2109
-
2110
- const wchar_t * sys_path = Py_GetPath ();
2111
- const wchar_t delim = DELIM ;
2112
- const wchar_t * p = sys_path ;
2113
- while (1 ) {
2114
- p = wcschr (sys_path , delim );
2115
- if (p == NULL ) {
2116
- p = sys_path + wcslen (sys_path ); /* End of string */
2117
- }
2118
-
2119
- size_t path_len = (p - sys_path );
2120
- wchar_t * path = PyMem_RawMalloc ((path_len + 1 ) * sizeof (wchar_t ));
2121
- if (path == NULL ) {
2122
- return _Py_INIT_NO_MEMORY ();
2123
- }
2124
- memcpy (path , sys_path , path_len * sizeof (wchar_t ));
2125
- path [path_len ] = L'\0' ;
2126
-
2127
- _PyInitError err = wstrlist_append (& config -> nmodule_search_path ,
2128
- & config -> module_search_paths ,
2129
- path );
2130
- PyMem_RawFree (path );
2131
- if (_Py_INIT_FAILED (err )) {
2132
- return err ;
2133
- }
2134
-
2135
- if (* p == '\0' ) {
2136
- break ;
2137
- }
2138
- sys_path = p + 1 ;
2139
- }
2140
- return _Py_INIT_OK ();
2141
- }
2142
-
2143
-
2144
- static _PyInitError
2145
- config_init_path_config (_PyCoreConfig * config )
2146
- {
2147
- _PyInitError err = _PyPathConfig_Init (config );
2148
- if (_Py_INIT_FAILED (err )) {
2149
- return err ;
2150
- }
2151
-
2152
- if (config -> nmodule_search_path < 0 ) {
2153
- err = config_init_module_search_paths (config );
2154
- if (_Py_INIT_FAILED (err )) {
2155
- return err ;
2156
- }
2157
- }
2158
-
2159
- if (config -> executable == NULL ) {
2160
- config -> executable = _PyMem_RawWcsdup (Py_GetProgramFullPath ());
2161
- if (config -> executable == NULL ) {
2162
- return _Py_INIT_NO_MEMORY ();
2163
- }
2164
- }
2165
-
2166
- if (config -> prefix == NULL ) {
2167
- config -> prefix = _PyMem_RawWcsdup (Py_GetPrefix ());
2168
- if (config -> prefix == NULL ) {
2169
- return _Py_INIT_NO_MEMORY ();
2170
- }
2171
- }
2172
-
2173
- if (config -> exec_prefix == NULL ) {
2174
- config -> exec_prefix = _PyMem_RawWcsdup (Py_GetExecPrefix ());
2175
- if (config -> exec_prefix == NULL ) {
2176
- return _Py_INIT_NO_MEMORY ();
2177
- }
2178
- }
2179
-
2180
- if (config -> base_prefix == NULL ) {
2181
- config -> base_prefix = _PyMem_RawWcsdup (config -> prefix );
2182
- if (config -> base_prefix == NULL ) {
2183
- return _Py_INIT_NO_MEMORY ();
2184
- }
2185
- }
2186
-
2187
- if (config -> base_exec_prefix == NULL ) {
2188
- config -> base_exec_prefix = _PyMem_RawWcsdup (config -> exec_prefix );
2189
- if (config -> base_exec_prefix == NULL ) {
2190
- return _Py_INIT_NO_MEMORY ();
2191
- }
2192
- }
2193
-
2194
- return _Py_INIT_OK ();
2195
- }
2196
-
2197
2106
/* Read configuration settings from standard locations
2198
2107
*
2199
2108
* This function doesn't make any changes to the interpreter state - it
@@ -2252,7 +2161,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
2252
2161
}
2253
2162
2254
2163
if (!config -> _disable_importlib ) {
2255
- err = config_init_path_config (config );
2164
+ err = _PyCoreConfig_InitPathConfig (config );
2256
2165
if (_Py_INIT_FAILED (err )) {
2257
2166
return err ;
2258
2167
}
@@ -2294,6 +2203,9 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)
2294
2203
CLEAR (config -> prefix );
2295
2204
CLEAR (config -> base_prefix );
2296
2205
CLEAR (config -> exec_prefix );
2206
+ #ifdef MS_WINDOWS
2207
+ CLEAR (config -> dll_path );
2208
+ #endif
2297
2209
CLEAR (config -> base_exec_prefix );
2298
2210
#undef CLEAR
2299
2211
#undef CLEAR_WSTRLIST
@@ -2356,6 +2268,9 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
2356
2268
COPY_STR_ATTR (prefix );
2357
2269
COPY_STR_ATTR (base_prefix );
2358
2270
COPY_STR_ATTR (exec_prefix );
2271
+ #ifdef MS_WINDOWS
2272
+ COPY_STR_ATTR (dll_path );
2273
+ #endif
2359
2274
COPY_STR_ATTR (base_exec_prefix );
2360
2275
2361
2276
#undef COPY_ATTR
0 commit comments