Skip to content

Commit e267793

Browse files
authored
bpo-38234: Fix PyConfig_Read() when Py_SetPath() was called (GH-16298)
* If Py_SetPath() has been called, _PyConfig_InitPathConfig() now uses its value. * Py_Initialize() now longer copies path configuration from PyConfig to the global path configuration (_Py_path_config).
1 parent 77af229 commit e267793

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Python ignored path passed to :c:func:`Py_SetPath`, fix Python
2+
initialization to use the specified path.

Modules/getpath.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,10 +1213,12 @@ calculate_path_impl(const PyConfig *config,
12131213
"Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
12141214
}
12151215

1216-
status = calculate_module_search_path(config, calculate,
1217-
prefix, exec_prefix, pathconfig);
1218-
if (_PyStatus_EXCEPTION(status)) {
1219-
return status;
1216+
if (pathconfig->module_search_path == NULL) {
1217+
status = calculate_module_search_path(config, calculate,
1218+
prefix, exec_prefix, pathconfig);
1219+
if (_PyStatus_EXCEPTION(status)) {
1220+
return status;
1221+
}
12201222
}
12211223

12221224
status = calculate_reduce_prefix(calculate, prefix, Py_ARRAY_LENGTH(prefix));

PC/getpathp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,12 @@ calculate_path_impl(const PyConfig *config,
10031003

10041004
calculate_home_prefix(calculate, prefix);
10051005

1006-
status = calculate_module_search_path(config, calculate, pathconfig, prefix);
1007-
if (_PyStatus_EXCEPTION(status)) {
1008-
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+
}
10091012
}
10101013

10111014
done:

Python/pathconfig.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config)
7474
PyMemAllocatorEx old_alloc;
7575
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
7676

77+
if (copy_wstr(&new_config.module_search_path,
78+
_Py_path_config.module_search_path) < 0)
79+
{
80+
status = _PyStatus_NO_MEMORY();
81+
goto error;
82+
}
83+
7784
/* Calculate program_full_path, prefix, exec_prefix,
7885
dll_path (Windows), and module_search_path */
7986
status = _PyPathConfig_Calculate(&new_config, config);

0 commit comments

Comments
 (0)