]> granicus.if.org Git - python/commitdiff
bpo-38234: Fix PyConfig_Read() when Py_SetPath() was called (GH-16298)
authorVictor Stinner <vstinner@redhat.com>
Fri, 20 Sep 2019 23:50:16 +0000 (01:50 +0200)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2019 23:50:16 +0000 (01:50 +0200)
* 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).

Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst [new file with mode: 0644]
Modules/getpath.c
PC/getpathp.c
Python/pathconfig.c

diff --git a/Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst b/Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst
new file mode 100644 (file)
index 0000000..6310f19
--- /dev/null
@@ -0,0 +1,2 @@
+Python ignored path passed to :c:func:`Py_SetPath`, fix Python
+initialization to use the specified path.
index 36f9860ea13174f913e732a9c429067c2df8987e..3946623862cf35e70fdc4576604a76fbcf2a234f 100644 (file)
@@ -1213,10 +1213,12 @@ calculate_path_impl(const PyConfig *config,
                 "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
     }
 
-    status = calculate_module_search_path(config, calculate,
-                                       prefix, exec_prefix, pathconfig);
-    if (_PyStatus_EXCEPTION(status)) {
-        return status;
+    if (pathconfig->module_search_path == NULL) {
+        status = calculate_module_search_path(config, calculate,
+                                              prefix, exec_prefix, pathconfig);
+        if (_PyStatus_EXCEPTION(status)) {
+            return status;
+        }
     }
 
     status = calculate_reduce_prefix(calculate, prefix, Py_ARRAY_LENGTH(prefix));
index 01455a660be6050ccf5da00b2edfb7abd4312350..0ee53080bf3108834a640e8aee901dcaade56678 100644 (file)
@@ -1003,9 +1003,12 @@ calculate_path_impl(const PyConfig *config,
 
     calculate_home_prefix(calculate, prefix);
 
-    status = calculate_module_search_path(config, calculate, pathconfig, prefix);
-    if (_PyStatus_EXCEPTION(status)) {
-        return status;
+    if (pathconfig->module_search_path == NULL) {
+        status = calculate_module_search_path(config, calculate,
+                                              pathconfig, prefix);
+        if (_PyStatus_EXCEPTION(status)) {
+            return status;
+        }
     }
 
 done:
index ccab832742519211cbe69a7128f1090315c9b8b1..2d00f4b6b125bd5cd854ebbe35b257537bd1270b 100644 (file)
@@ -74,6 +74,13 @@ pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config)
     PyMemAllocatorEx old_alloc;
     _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
 
+    if (copy_wstr(&new_config.module_search_path,
+                  _Py_path_config.module_search_path) < 0)
+    {
+        status = _PyStatus_NO_MEMORY();
+        goto error;
+    }
+
     /* Calculate program_full_path, prefix, exec_prefix,
        dll_path (Windows), and module_search_path */
     status = _PyPathConfig_Calculate(&new_config, config);