summaryrefslogtreecommitdiffstats
path: root/Python/pathconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-09-26 13:51:50 (GMT)
committerGitHub <noreply@github.com>2019-09-26 13:51:50 (GMT)
commit12f2f177fc483723406d7917194e7f655a20631b (patch)
treef3e1b4227b37efa25e0ca0a487e0d229deba8b95 /Python/pathconfig.c
parent3d984a1fd0c05903268542a216fc496074b2e6da (diff)
downloadcpython-12f2f177fc483723406d7917194e7f655a20631b.zip
cpython-12f2f177fc483723406d7917194e7f655a20631b.tar.gz
cpython-12f2f177fc483723406d7917194e7f655a20631b.tar.bz2
bpo-38234: Py_Initialize() sets global path configuration (GH-16421)
* Py_InitializeFromConfig() now writes PyConfig path configuration to the global path configuration (_Py_path_config). * Add test_embed.test_get_pathconfig(). * Fix typo in _PyWideStringList_Join().
Diffstat (limited to 'Python/pathconfig.c')
-rw-r--r--Python/pathconfig.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index f4e1498..8126145 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -133,7 +133,7 @@ _PyWideStringList_Join(const PyWideStringList *list, wchar_t sep)
for (Py_ssize_t i=0; i < list->length; i++) {
wchar_t *path = list->items[i];
if (i != 0) {
- *str++ = SEP;
+ *str++ = sep;
}
len = wcslen(path);
memcpy(str, path, len * sizeof(wchar_t));
@@ -145,11 +145,11 @@ _PyWideStringList_Join(const PyWideStringList *list, wchar_t sep)
}
+#ifdef MS_WINDOWS
/* Initialize _Py_dll_path on Windows. Do nothing on other platforms. */
-PyStatus
-_PyPathConfig_Init(void)
+static PyStatus
+_PyPathConfig_InitDLLPath(void)
{
-#ifdef MS_WINDOWS
if (_Py_dll_path == NULL) {
/* Already set: nothing to do */
return _PyStatus_OK();
@@ -165,9 +165,9 @@ _PyPathConfig_Init(void)
if (_Py_dll_path == NULL) {
return _PyStatus_NO_MEMORY();
}
-#endif
return _PyStatus_OK();
}
+#endif
static PyStatus
@@ -217,6 +217,20 @@ done:
}
+PyStatus
+_PyConfig_WritePathConfig(const PyConfig *config)
+{
+#ifdef MS_WINDOWS
+ PyStatus status = _PyPathConfig_InitDLLPath();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+#endif
+
+ return pathconfig_set_from_config(&_Py_path_config, config);
+}
+
+
static PyStatus
config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)
{
@@ -441,11 +455,12 @@ pathconfig_global_init(void)
{
PyStatus status;
- /* Initialize _Py_dll_path if needed */
- status = _PyPathConfig_Init();
+#ifdef MS_WINDOWS
+ status = _PyPathConfig_InitDLLPath();
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
}
+#endif
if (_Py_path_config.module_search_path == NULL) {
status = pathconfig_global_read(&_Py_path_config);