summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-24 21:55:40 (GMT)
committerGitHub <noreply@github.com>2017-11-24 21:55:40 (GMT)
commit46972b7bc385ec2bdc7f567bbd22c9e56ffdf003 (patch)
treee55f61feac1afb22e18bb33274a5e3f0beec5355 /Python/pylifecycle.c
parent84c4b1938fade2b425ac906730beabd413de094d (diff)
downloadcpython-46972b7bc385ec2bdc7f567bbd22c9e56ffdf003.zip
cpython-46972b7bc385ec2bdc7f567bbd22c9e56ffdf003.tar.gz
cpython-46972b7bc385ec2bdc7f567bbd22c9e56ffdf003.tar.bz2
bpo-32030: Add _PyMainInterpreterConfig_ReadEnv() (#4542)
Py_GetPath() and Py_Main() now call _PyMainInterpreterConfig_ReadEnv() to share the same code to get environment variables. Changes: * Add _PyMainInterpreterConfig_ReadEnv() * Add _PyMainInterpreterConfig_Clear() * Add _PyMem_RawWcsdup() * _PyMainInterpreterConfig: rename pythonhome to home * Rename _Py_ReadMainInterpreterConfig() to _PyMainInterpreterConfig_Read() * Use _Py_INIT_USER_ERR(), instead of _Py_INIT_ERR(), for decoding errors: the user is able to fix the issue, it's not a bug in Python. Same change was made in _Py_INIT_NO_MEMORY(). * Remove _Py_GetPythonHomeWithConfig()
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index b079990..e36b6c1 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -796,7 +796,7 @@ _Py_InitializeCore(const _PyCoreConfig *config)
*/
_PyInitError
-_Py_ReadMainInterpreterConfig(_PyMainInterpreterConfig *config)
+_PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *config)
{
/* Signal handlers are installed by default */
if (config->install_signal_handlers < 0) {
@@ -805,6 +805,17 @@ _Py_ReadMainInterpreterConfig(_PyMainInterpreterConfig *config)
return _Py_INIT_OK();
}
+
+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;
+}
+
+
/* Update interpreter state based on supplied configuration settings
*
* After calling this function, most of the restrictions on the interpreter
@@ -943,7 +954,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
}
/* TODO: Print any exceptions raised by these operations */
- err = _Py_ReadMainInterpreterConfig(&config);
+ err = _PyMainInterpreterConfig_Read(&config);
if (_Py_INIT_FAILED(err)) {
return err;
}
@@ -1477,8 +1488,8 @@ Py_SetPythonHome(wchar_t *home)
}
-_PyInitError
-_Py_GetPythonHomeWithConfig(const _PyMainInterpreterConfig *config, wchar_t **homep)
+wchar_t*
+Py_GetPythonHome(void)
{
/* Use a static buffer to avoid heap memory allocation failure.
Py_GetPythonHome() doesn't allow to report error, and the caller
@@ -1486,40 +1497,22 @@ _Py_GetPythonHomeWithConfig(const _PyMainInterpreterConfig *config, wchar_t **ho
static wchar_t buffer[MAXPATHLEN+1];
if (default_home) {
- *homep = default_home;
- return _Py_INIT_OK();
- }
-
- if (config) {
- *homep = config->pythonhome;
- return _Py_INIT_OK();
+ return default_home;
}
char *home = Py_GETENV("PYTHONHOME");
if (!home) {
- *homep = NULL;
- return _Py_INIT_OK();
+ return NULL;
}
size_t size = Py_ARRAY_LENGTH(buffer);
size_t r = mbstowcs(buffer, home, size);
if (r == (size_t)-1 || r >= size) {
/* conversion failed or the static buffer is too small */
- *homep = NULL;
- return _Py_INIT_ERR("failed to decode PYTHONHOME environment variable");
+ return NULL;
}
- *homep = buffer;
- return _Py_INIT_OK();
-}
-
-wchar_t *
-Py_GetPythonHome(void)
-{
- wchar_t *home;
- /* Ignore error */
- (void)_Py_GetPythonHomeWithConfig(NULL, &home);
- return home;
+ return buffer;
}
/* Add the __main__ module */