bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673) · python/cpython@af5a895 (original) (raw)
`@@ -876,6 +876,16 @@ static _PyInitError
`
876
876
`config_get_program_name(_PyMainInterpreterConfig *config)
`
877
877
`{
`
878
878
`assert(config->program_name == NULL);
`
``
879
+
``
880
`+
/* If Py_SetProgramName() was called, use its value */
`
``
881
`+
wchar_t *program_name = _Py_path_config.program_name;
`
``
882
`+
if (program_name != NULL) {
`
``
883
`+
config->program_name = _PyMem_RawWcsdup(program_name);
`
``
884
`+
if (config->program_name == NULL) {
`
``
885
`+
return _Py_INIT_NO_MEMORY();
`
``
886
`+
}
`
``
887
`+
}
`
``
888
+
879
889
`#ifdef APPLE
`
880
890
`char *p;
`
881
891
`/* On MacOS X, when the Python interpreter is embedded in an
`
`@@ -914,6 +924,7 @@ config_get_program_name(_PyMainInterpreterConfig *config)
`
914
924
` }
`
915
925
`#endif /* WITH_NEXT_FRAMEWORK */
`
916
926
`#endif /* APPLE */
`
``
927
+
917
928
`return _Py_INIT_OK();
`
918
929
`}
`
919
930
``
`@@ -948,13 +959,6 @@ pymain_init_main_interpreter(_PyMain *pymain)
`
948
959
`{
`
949
960
`_PyInitError err;
`
950
961
``
951
``
`-
/* TODO: Print any exceptions raised by these operations */
`
952
``
`-
err = _PyMainInterpreterConfig_Read(&pymain->config);
`
953
``
`-
if (_Py_INIT_FAILED(err)) {
`
954
``
`-
pymain->err = err;
`
955
``
`-
return -1;
`
956
``
`-
}
`
957
``
-
958
962
`err = _Py_InitializeMainInterpreter(&pymain->config);
`
959
963
`if (_Py_INIT_FAILED(err)) {
`
960
964
`pymain->err = err;
`
`@@ -1412,14 +1416,13 @@ config_init_pythonpath(_PyMainInterpreterConfig *config)
`
1412
1416
``
1413
1417
``
1414
1418
`static _PyInitError
`
1415
``
`-
config_init_pythonhome(_PyMainInterpreterConfig *config)
`
``
1419
`+
config_init_home(_PyMainInterpreterConfig *config)
`
1416
1420
`{
`
1417
1421
`wchar_t *home;
`
1418
1422
``
1419
``
`-
home = Py_GetPythonHome();
`
``
1423
`+
/* If Py_SetPythonHome() was called, use its value */
`
``
1424
`+
home = _Py_path_config.home;
`
1420
1425
`if (home) {
`
1421
``
`-
/* Py_SetPythonHome() has been called before Py_Main(),
`
1422
``
`-
use its value */
`
1423
1426
`config->home = _PyMem_RawWcsdup(home);
`
1424
1427
`if (config->home == NULL) {
`
1425
1428
`return _Py_INIT_NO_MEMORY();
`
`@@ -1439,7 +1442,7 @@ config_init_pythonhome(_PyMainInterpreterConfig *config)
`
1439
1442
`_PyInitError
`
1440
1443
`_PyMainInterpreterConfig_ReadEnv(_PyMainInterpreterConfig *config)
`
1441
1444
`{
`
1442
``
`-
_PyInitError err = config_init_pythonhome(config);
`
``
1445
`+
_PyInitError err = config_init_home(config);
`
1443
1446
`if (_Py_INIT_FAILED(err)) {
`
1444
1447
`return err;
`
1445
1448
` }
`
`@@ -1543,6 +1546,12 @@ pymain_parse_cmdline_envvars_impl(_PyMain *pymain)
`
1543
1546
`return -1;
`
1544
1547
` }
`
1545
1548
``
``
1549
`+
_PyInitError err = _PyMainInterpreterConfig_Read(&pymain->config);
`
``
1550
`+
if (_Py_INIT_FAILED(err)) {
`
``
1551
`+
pymain->err = err;
`
``
1552
`+
return -1;
`
``
1553
`+
}
`
``
1554
+
1546
1555
`return 0;
`
1547
1556
`}
`
1548
1557
``
`@@ -1566,11 +1575,6 @@ pymain_init_python(_PyMain *pymain)
`
1566
1575
`{
`
1567
1576
`pymain_init_stdio(pymain);
`
1568
1577
``
1569
``
`-
Py_SetProgramName(pymain->config.program_name);
`
1570
``
`-
/* Don't free program_name here: the argument to Py_SetProgramName
`
1571
``
`-
must remain valid until Py_FinalizeEx is called. The string is freed
`
1572
``
`-
by pymain_free(). */
`
1573
``
-
1574
1578
`pymain->err = _Py_InitializeCore(&pymain->core_config);
`
1575
1579
`if (_Py_INIT_FAILED(pymain->err)) {
`
1576
1580
`return -1;
`