diff options
author | Steve Dower <steve.dower@microsoft.com> | 2018-11-17 20:42:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-17 20:42:08 -0800 |
commit | e851049e0e045b5e0f9d5c6b8a64d7f6b8ecc9c7 (patch) | |
tree | 55603ae6528fd90aa70608e9e23f49440b86131d /Python | |
parent | d1a97b36595726074a83452e5c476806936becba (diff) | |
download | cpython-git-e851049e0e045b5e0f9d5c6b8a64d7f6b8ecc9c7.tar.gz |
bpo-34725: Adds _Py_SetProgramFullPath so embedders may override sys.executable (GH-9861)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pathconfig.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 07aa01c030..aacc5f5a5f 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -205,6 +205,27 @@ Py_SetProgramName(const wchar_t *program_name) } +void +_Py_SetProgramFullPath(const wchar_t *program_full_path) +{ + if (program_full_path == NULL || program_full_path[0] == L'\0') { + return; + } + + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + + PyMem_RawFree(_Py_path_config.program_full_path); + _Py_path_config.program_full_path = _PyMem_RawWcsdup(program_full_path); + + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + + if (_Py_path_config.program_full_path == NULL) { + Py_FatalError("Py_SetProgramFullPath() failed: out of memory"); + } +} + + wchar_t * Py_GetPath(void) { |