summaryrefslogtreecommitdiffstats
path: root/Python/coreconfig.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2018-11-18 04:41:48 (GMT)
committerGitHub <noreply@github.com>2018-11-18 04:41:48 (GMT)
commit177a41a07b7d13c70d068ea0962f07e625ae171e (patch)
tree1f698c35899360fe3b73bc90b9556871b35813a0 /Python/coreconfig.c
parent689d555ec135d4115574addd063c358ac4897cc4 (diff)
downloadcpython-177a41a07b7d13c70d068ea0962f07e625ae171e.zip
cpython-177a41a07b7d13c70d068ea0962f07e625ae171e.tar.gz
cpython-177a41a07b7d13c70d068ea0962f07e625ae171e.tar.bz2
bpo-34725: Adds _Py_SetProgramFullPath so embedders may override sys.executable (GH-9860)
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r--Python/coreconfig.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index a040a86..ad22300 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -662,6 +662,23 @@ config_init_program_name(_PyCoreConfig *config)
return _Py_INIT_OK();
}
+static _PyInitError
+config_init_executable(_PyCoreConfig *config)
+{
+ assert(config->executable == NULL);
+
+ /* If Py_SetProgramFullPath() was called, use its value */
+ const wchar_t *program_full_path = _Py_path_config.program_full_path;
+ if (program_full_path != NULL) {
+ config->executable = _PyMem_RawWcsdup(program_full_path);
+ if (config->executable == NULL) {
+ return _Py_INIT_NO_MEMORY();
+ }
+ return _Py_INIT_OK();
+ }
+
+ return _Py_INIT_OK();
+}
static const wchar_t*
config_get_xoption(const _PyCoreConfig *config, wchar_t *name)
@@ -1370,6 +1387,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
}
}
+ if (config->executable == NULL) {
+ err = config_init_executable(config);
+ if (_Py_INIT_FAILED(err)) {
+ return err;
+ }
+ }
+
if (config->utf8_mode < 0 || config->coerce_c_locale < 0) {
config_init_locale(config);
}