summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-25 00:01:23 +0100
committerGitHub <noreply@github.com>2017-11-25 00:01:23 +0100
commitf04ebe2a4d68b194deeb438e9185efdafc10a832 (patch)
treea6c6eb6febcdedcb094d8409d2f9ef7cc8716a32 /Python/pylifecycle.c
parent46972b7bc385ec2bdc7f567bbd22c9e56ffdf003 (diff)
downloadcpython-git-f04ebe2a4d68b194deeb438e9185efdafc10a832.tar.gz
bpo-32030: Add _PyMainInterpreterConfig.program_name (#4548)
* Py_Main() now calls Py_SetProgramName() earlier to be able to get the program name in _PyMainInterpreterConfig_ReadEnv(). * Rename prog to program_name * Rename progpath to program_name
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index e36b6c1b05..714be3768f 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -802,6 +802,14 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *config)
if (config->install_signal_handlers < 0) {
config->install_signal_handlers = 1;
}
+
+ if (config->program_name == NULL) {
+ config->program_name = _PyMem_RawWcsdup(Py_GetProgramName());
+ if (config->program_name == NULL) {
+ return _Py_INIT_NO_MEMORY();
+ }
+ }
+
return _Py_INIT_OK();
}
@@ -809,10 +817,16 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *config)
void
_PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *config)
{
- PyMem_RawFree(config->module_search_path_env);
- config->module_search_path_env = NULL;
- PyMem_RawFree(config->home);
- config->home = NULL;
+#define CLEAR(ATTR) \
+ do { \
+ PyMem_RawFree(ATTR); \
+ ATTR = NULL; \
+ } while (0)
+
+ CLEAR(config->module_search_path_env);
+ CLEAR(config->home);
+ CLEAR(config->program_name);
+#undef CLEAR
}