@@ -133,6 +133,9 @@ typedef struct {
133
133
134
134
int prefix_found ; /* found platform independent libraries? */
135
135
int exec_prefix_found ; /* found the platform dependent libraries? */
136
+
137
+ int warnings ;
138
+ const wchar_t * pythonpath_env ;
136
139
} PyCalculatePath ;
137
140
138
141
static const wchar_t delimiter [2 ] = {DELIM , '\0' };
@@ -365,17 +368,16 @@ add_exe_suffix(wchar_t *progpath, size_t progpathlen)
365
368
bytes long.
366
369
*/
367
370
static PyStatus
368
- search_for_prefix (const PyConfig * config , PyCalculatePath * calculate ,
369
- wchar_t * prefix , size_t prefix_len ,
370
- int * found )
371
+ search_for_prefix (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
372
+ wchar_t * prefix , size_t prefix_len , int * found )
371
373
{
372
374
PyStatus status ;
373
375
size_t n ;
374
376
wchar_t * vpath ;
375
377
376
378
/* If PYTHONHOME is set, we believe it unconditionally */
377
- if (config -> home ) {
378
- if (safe_wcscpy (prefix , config -> home , prefix_len ) < 0 ) {
379
+ if (pathconfig -> home ) {
380
+ if (safe_wcscpy (prefix , pathconfig -> home , prefix_len ) < 0 ) {
379
381
return PATHLEN_ERR ();
380
382
}
381
383
wchar_t * delim = wcschr (prefix , DELIM );
@@ -482,19 +484,19 @@ search_for_prefix(const PyConfig *config, PyCalculatePath *calculate,
482
484
483
485
484
486
static PyStatus
485
- calculate_prefix (const PyConfig * config ,
486
- PyCalculatePath * calculate , wchar_t * prefix , size_t prefix_len )
487
+ calculate_prefix (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
488
+ wchar_t * prefix , size_t prefix_len )
487
489
{
488
490
PyStatus status ;
489
491
490
- status = search_for_prefix (config , calculate , prefix , prefix_len ,
491
- & calculate -> prefix_found );
492
+ status = search_for_prefix (calculate , pathconfig , prefix , prefix_len ,
493
+ & calculate -> prefix_found );
492
494
if (_PyStatus_EXCEPTION (status )) {
493
495
return status ;
494
496
}
495
497
496
498
if (!calculate -> prefix_found ) {
497
- if (config -> pathconfig_warnings ) {
499
+ if (calculate -> warnings ) {
498
500
fprintf (stderr ,
499
501
"Could not find platform independent libraries <prefix>\n" );
500
502
}
@@ -544,24 +546,23 @@ calculate_reduce_prefix(PyCalculatePath *calculate,
544
546
MAXPATHLEN bytes long.
545
547
*/
546
548
static PyStatus
547
- search_for_exec_prefix (const PyConfig * config ,
548
- PyCalculatePath * calculate ,
549
+ search_for_exec_prefix (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
549
550
wchar_t * exec_prefix , size_t exec_prefix_len ,
550
551
int * found )
551
552
{
552
553
PyStatus status ;
553
554
size_t n ;
554
555
555
556
/* If PYTHONHOME is set, we believe it unconditionally */
556
- if (config -> home ) {
557
- wchar_t * delim = wcschr (config -> home , DELIM );
557
+ if (pathconfig -> home ) {
558
+ wchar_t * delim = wcschr (pathconfig -> home , DELIM );
558
559
if (delim ) {
559
560
if (safe_wcscpy (exec_prefix , delim + 1 , exec_prefix_len ) < 0 ) {
560
561
return PATHLEN_ERR ();
561
562
}
562
563
}
563
564
else {
564
- if (safe_wcscpy (exec_prefix , config -> home , exec_prefix_len ) < 0 ) {
565
+ if (safe_wcscpy (exec_prefix , pathconfig -> home , exec_prefix_len ) < 0 ) {
565
566
return PATHLEN_ERR ();
566
567
}
567
568
}
@@ -668,21 +669,20 @@ search_for_exec_prefix(const PyConfig *config,
668
669
669
670
670
671
static PyStatus
671
- calculate_exec_prefix (const PyConfig * config ,
672
- PyCalculatePath * calculate ,
672
+ calculate_exec_prefix (PyCalculatePath * calculate , _PyPathConfig * pathconfig ,
673
673
wchar_t * exec_prefix , size_t exec_prefix_len )
674
674
{
675
675
PyStatus status ;
676
676
677
- status = search_for_exec_prefix (config , calculate ,
678
- exec_prefix , exec_prefix_len ,
679
- & calculate -> exec_prefix_found );
677
+ status = search_for_exec_prefix (calculate , pathconfig ,
678
+ exec_prefix , exec_prefix_len ,
679
+ & calculate -> exec_prefix_found );
680
680
if (_PyStatus_EXCEPTION (status )) {
681
681
return status ;
682
682
}
683
683
684
684
if (!calculate -> exec_prefix_found ) {
685
- if (config -> pathconfig_warnings ) {
685
+ if (calculate -> warnings ) {
686
686
fprintf (stderr ,
687
687
"Could not find platform dependent libraries <exec_prefix>\n" );
688
688
}
@@ -721,8 +721,7 @@ calculate_reduce_exec_prefix(PyCalculatePath *calculate,
721
721
722
722
723
723
static PyStatus
724
- calculate_program_full_path (const PyConfig * config ,
725
- PyCalculatePath * calculate , _PyPathConfig * pathconfig )
724
+ calculate_program_full_path (PyCalculatePath * calculate , _PyPathConfig * pathconfig )
726
725
{
727
726
PyStatus status ;
728
727
wchar_t program_full_path [MAXPATHLEN + 1 ];
@@ -743,8 +742,8 @@ calculate_program_full_path(const PyConfig *config,
743
742
* other way to find a directory to start the search from. If
744
743
* $PATH isn't exported, you lose.
745
744
*/
746
- if (wcschr (config -> program_name , SEP )) {
747
- if (safe_wcscpy (program_full_path , config -> program_name ,
745
+ if (wcschr (pathconfig -> program_name , SEP )) {
746
+ if (safe_wcscpy (program_full_path , pathconfig -> program_name ,
748
747
program_full_path_len ) < 0 ) {
749
748
return PATHLEN_ERR ();
750
749
}
@@ -795,8 +794,8 @@ calculate_program_full_path(const PyConfig *config,
795
794
}
796
795
}
797
796
798
- status = joinpath (program_full_path , config -> program_name ,
799
- program_full_path_len );
797
+ status = joinpath (program_full_path , pathconfig -> program_name ,
798
+ program_full_path_len );
800
799
if (_PyStatus_EXCEPTION (status )) {
801
800
return status ;
802
801
}
@@ -1030,15 +1029,14 @@ calculate_zip_path(PyCalculatePath *calculate, const wchar_t *prefix)
1030
1029
1031
1030
1032
1031
static PyStatus
1033
- calculate_module_search_path (const PyConfig * config ,
1034
- PyCalculatePath * calculate ,
1035
- const wchar_t * prefix , const wchar_t * exec_prefix ,
1036
- _PyPathConfig * pathconfig )
1032
+ calculate_module_search_path (PyCalculatePath * calculate ,
1033
+ _PyPathConfig * pathconfig ,
1034
+ const wchar_t * prefix , const wchar_t * exec_prefix )
1037
1035
{
1038
1036
/* Calculate size of return buffer */
1039
1037
size_t bufsz = 0 ;
1040
- if (config -> pythonpath_env != NULL ) {
1041
- bufsz += wcslen (config -> pythonpath_env ) + 1 ;
1038
+ if (calculate -> pythonpath_env != NULL ) {
1039
+ bufsz += wcslen (calculate -> pythonpath_env ) + 1 ;
1042
1040
}
1043
1041
1044
1042
wchar_t * defpath = calculate -> pythonpath ;
@@ -1072,8 +1070,8 @@ calculate_module_search_path(const PyConfig *config,
1072
1070
buf [0 ] = '\0' ;
1073
1071
1074
1072
/* Run-time value of $PYTHONPATH goes first */
1075
- if (config -> pythonpath_env ) {
1076
- wcscpy (buf , config -> pythonpath_env );
1073
+ if (calculate -> pythonpath_env ) {
1074
+ wcscpy (buf , calculate -> pythonpath_env );
1077
1075
wcscat (buf , delimiter );
1078
1076
}
1079
1077
@@ -1149,6 +1147,10 @@ calculate_init(PyCalculatePath *calculate,
1149
1147
if (!calculate -> lib_python ) {
1150
1148
return DECODE_LOCALE_ERR ("EXEC_PREFIX define" , len );
1151
1149
}
1150
+
1151
+ calculate -> warnings = config -> pathconfig_warnings ;
1152
+ calculate -> pythonpath_env = config -> pythonpath_env ;
1153
+
1152
1154
return _PyStatus_OK ();
1153
1155
}
1154
1156
@@ -1165,14 +1167,15 @@ calculate_free(PyCalculatePath *calculate)
1165
1167
1166
1168
1167
1169
static PyStatus
1168
- calculate_path_impl (const PyConfig * config ,
1169
- PyCalculatePath * calculate , _PyPathConfig * pathconfig )
1170
+ calculate_path (PyCalculatePath * calculate , _PyPathConfig * pathconfig )
1170
1171
{
1171
1172
PyStatus status ;
1172
1173
1173
- status = calculate_program_full_path (config , calculate , pathconfig );
1174
- if (_PyStatus_EXCEPTION (status )) {
1175
- return status ;
1174
+ if (pathconfig -> program_full_path == NULL ) {
1175
+ status = calculate_program_full_path (calculate , pathconfig );
1176
+ if (_PyStatus_EXCEPTION (status )) {
1177
+ return status ;
1178
+ }
1176
1179
}
1177
1180
1178
1181
status = calculate_argv0_path (calculate , pathconfig -> program_full_path );
@@ -1187,8 +1190,8 @@ calculate_path_impl(const PyConfig *config,
1187
1190
1188
1191
wchar_t prefix [MAXPATHLEN + 1 ];
1189
1192
memset (prefix , 0 , sizeof (prefix ));
1190
- status = calculate_prefix (config , calculate ,
1191
- prefix , Py_ARRAY_LENGTH (prefix ));
1193
+ status = calculate_prefix (calculate , pathconfig ,
1194
+ prefix , Py_ARRAY_LENGTH (prefix ));
1192
1195
if (_PyStatus_EXCEPTION (status )) {
1193
1196
return status ;
1194
1197
}
@@ -1200,52 +1203,65 @@ calculate_path_impl(const PyConfig *config,
1200
1203
1201
1204
wchar_t exec_prefix [MAXPATHLEN + 1 ];
1202
1205
memset (exec_prefix , 0 , sizeof (exec_prefix ));
1203
- status = calculate_exec_prefix (config , calculate ,
1204
- exec_prefix , Py_ARRAY_LENGTH (exec_prefix ));
1206
+ status = calculate_exec_prefix (calculate , pathconfig ,
1207
+ exec_prefix , Py_ARRAY_LENGTH (exec_prefix ));
1205
1208
if (_PyStatus_EXCEPTION (status )) {
1206
1209
return status ;
1207
1210
}
1208
1211
1209
1212
if ((!calculate -> prefix_found || !calculate -> exec_prefix_found ) &&
1210
- config -> pathconfig_warnings )
1213
+ calculate -> warnings )
1211
1214
{
1212
1215
fprintf (stderr ,
1213
1216
"Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n" );
1214
1217
}
1215
1218
1216
1219
if (pathconfig -> module_search_path == NULL ) {
1217
- status = calculate_module_search_path (config , calculate ,
1218
- prefix , exec_prefix , pathconfig );
1220
+ status = calculate_module_search_path (calculate , pathconfig ,
1221
+ prefix , exec_prefix );
1219
1222
if (_PyStatus_EXCEPTION (status )) {
1220
1223
return status ;
1221
1224
}
1222
1225
}
1223
1226
1224
- status = calculate_reduce_prefix (calculate , prefix , Py_ARRAY_LENGTH (prefix ));
1225
- if (_PyStatus_EXCEPTION (status )) {
1226
- return status ;
1227
- }
1228
-
1229
- pathconfig -> prefix = _PyMem_RawWcsdup (prefix );
1230
1227
if (pathconfig -> prefix == NULL ) {
1231
- return _PyStatus_NO_MEMORY ();
1232
- }
1228
+ status = calculate_reduce_prefix (calculate , prefix , Py_ARRAY_LENGTH (prefix ));
1229
+ if (_PyStatus_EXCEPTION (status )) {
1230
+ return status ;
1231
+ }
1233
1232
1234
- status = calculate_reduce_exec_prefix ( calculate ,
1235
- exec_prefix , Py_ARRAY_LENGTH ( exec_prefix ));
1236
- if ( _PyStatus_EXCEPTION ( status )) {
1237
- return status ;
1233
+ pathconfig -> prefix = _PyMem_RawWcsdup ( prefix );
1234
+ if ( pathconfig -> prefix == NULL ) {
1235
+ return _PyStatus_NO_MEMORY ();
1236
+ }
1238
1237
}
1239
1238
1240
- pathconfig -> exec_prefix = _PyMem_RawWcsdup (exec_prefix );
1241
1239
if (pathconfig -> exec_prefix == NULL ) {
1242
- return _PyStatus_NO_MEMORY ();
1240
+ status = calculate_reduce_exec_prefix (calculate ,
1241
+ exec_prefix ,
1242
+ Py_ARRAY_LENGTH (exec_prefix ));
1243
+ if (_PyStatus_EXCEPTION (status )) {
1244
+ return status ;
1245
+ }
1246
+
1247
+ pathconfig -> exec_prefix = _PyMem_RawWcsdup (exec_prefix );
1248
+ if (pathconfig -> exec_prefix == NULL ) {
1249
+ return _PyStatus_NO_MEMORY ();
1250
+ }
1243
1251
}
1244
1252
1245
1253
return _PyStatus_OK ();
1246
1254
}
1247
1255
1248
1256
1257
+ /* Calculate 'pathconfig' attributes:
1258
+
1259
+ - program_full_path
1260
+ - module_search_path
1261
+ - prefix
1262
+ - exec_prefix
1263
+
1264
+ If an attribute is already set (non NULL), it is left unchanged. */
1249
1265
PyStatus
1250
1266
_PyPathConfig_Calculate (_PyPathConfig * pathconfig , const PyConfig * config )
1251
1267
{
@@ -1258,7 +1274,7 @@ _PyPathConfig_Calculate(_PyPathConfig *pathconfig, const PyConfig *config)
1258
1274
goto done ;
1259
1275
}
1260
1276
1261
- status = calculate_path_impl ( config , & calculate , pathconfig );
1277
+ status = calculate_path ( & calculate , pathconfig );
1262
1278
if (_PyStatus_EXCEPTION (status )) {
1263
1279
goto done ;
1264
1280
}
0 commit comments