]> granicus.if.org Git - python/commitdiff
bpo-32030: Move PYTHONPATH to _PyMainInterpreterConfig (#4511)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 23 Nov 2017 00:49:45 +0000 (01:49 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2017 00:49:45 +0000 (01:49 +0100)
Move _PyCoreConfig.module_search_path_env to _PyMainInterpreterConfig
structure.

Include/pylifecycle.h
Include/pystate.h
Modules/getpath.c
Modules/main.c
PC/getpathp.c
Python/pylifecycle.c

index 2a5e73a79cac42454efa3ce004bb856efea235e3..5eaa74edab8f98d711aa5d0a7770ce895a7ea03e 100644 (file)
@@ -94,7 +94,7 @@ PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
 PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
 PyAPI_FUNC(wchar_t *) Py_GetPath(void);
 #ifdef Py_BUILD_CORE
-PyAPI_FUNC(wchar_t *) _Py_GetPathWithConfig(_PyCoreConfig *config);
+PyAPI_FUNC(wchar_t *) _Py_GetPathWithConfig(_PyMainInterpreterConfig *config);
 #endif
 PyAPI_FUNC(void)      Py_SetPath(const wchar_t *);
 #ifdef MS_WINDOWS
index c5d3c3345f0050cc31ca62e07473925e3b39c36a..b2739f1db25390cd345a53469c1c7bd8b4829611 100644 (file)
@@ -30,7 +30,6 @@ typedef struct {
     unsigned long hash_seed;
     int _disable_importlib; /* Needed by freeze_importlib */
     const char *allocator;  /* Memory allocator: _PyMem_SetupAllocators() */
-    wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
     int dev_mode;           /* -X dev */
     int faulthandler;       /* -X faulthandler */
     int tracemalloc;        /* -X tracemalloc=N */
@@ -46,7 +45,6 @@ typedef struct {
      .hash_seed = 0, \
      ._disable_importlib = 0, \
      .allocator = NULL, \
-     .module_search_path_env = NULL, \
      .dev_mode = 0, \
      .faulthandler = 0, \
      .tracemalloc = 0, \
@@ -62,11 +60,13 @@ typedef struct {
  */
 typedef struct {
     int install_signal_handlers;
+    wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
 } _PyMainInterpreterConfig;
 
 #define _PyMainInterpreterConfig_INIT \
     (_PyMainInterpreterConfig){\
-     .install_signal_handlers = -1}
+     .install_signal_handlers = -1, \
+     .module_search_path_env = NULL}
 
 typedef struct _is {
 
index ad4a4e5e718d034469771859a763e9f1238bbe56..ead143280b74e1ea6f9260e59c9c6d28b36ecbba 100644 (file)
@@ -456,7 +456,7 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home,
 }
 
 static void
-calculate_path(_PyCoreConfig *core_config)
+calculate_path(_PyMainInterpreterConfig *config)
 {
     extern wchar_t *Py_GetProgramName(void);
 
@@ -706,9 +706,9 @@ calculate_path(_PyCoreConfig *core_config)
     bufsz = 0;
 
     wchar_t *env_path = NULL;
-    if (core_config) {
-        if (core_config->module_search_path_env) {
-            bufsz += wcslen(core_config->module_search_path_env) + 1;
+    if (config) {
+        if (config->module_search_path_env) {
+            bufsz += wcslen(config->module_search_path_env) + 1;
         }
     }
     else {
@@ -752,9 +752,9 @@ calculate_path(_PyCoreConfig *core_config)
 
     /* Run-time value of $PYTHONPATH goes first */
     buf[0] = '\0';
-    if (core_config) {
-        if (core_config->module_search_path_env) {
-            wcscpy(buf, core_config->module_search_path_env);
+    if (config) {
+        if (config->module_search_path_env) {
+            wcscpy(buf, config->module_search_path_env);
             wcscat(buf, delimiter);
         }
     }
@@ -858,10 +858,10 @@ Py_SetPath(const wchar_t *path)
 }
 
 wchar_t *
-_Py_GetPathWithConfig(_PyCoreConfig *core_config)
+_Py_GetPathWithConfig(_PyMainInterpreterConfig *config)
 {
     if (!module_search_path) {
-        calculate_path(core_config);
+        calculate_path(config);
     }
     return module_search_path;
 }
index 3bd93e37601931020824ed2f766a9823c2596786..8390af292383ce1ca9c954a3e3339bb6be268f05 100644 (file)
@@ -389,6 +389,7 @@ typedef struct {
     /* non-zero is stdin is a TTY or if -i option is used */
     int stdin_is_interactive;
     _PyCoreConfig core_config;
+    _PyMainInterpreterConfig config;
     _Py_CommandLineDetails cmdline;
     PyObject *main_importer_path;
     /* non-zero if filename, command (-c) or module (-m) is set
@@ -409,6 +410,7 @@ typedef struct {
     {.status = 0, \
      .cf = {.cf_flags = 0}, \
      .core_config = _PyCoreConfig_INIT, \
+     .config = _PyMainInterpreterConfig_INIT, \
      .main_importer_path = NULL, \
      .run_code = -1, \
      .program_name = NULL, \
@@ -442,7 +444,7 @@ pymain_free_impl(_PyMain *pymain)
     Py_CLEAR(pymain->main_importer_path);
     PyMem_RawFree(pymain->program_name);
 
-    PyMem_RawFree(pymain->core_config.module_search_path_env);
+    PyMem_RawFree(pymain->config.module_search_path_env);
 
 #ifdef __INSURE__
     /* Insure++ is a memory analysis tool that aids in discovering
@@ -957,20 +959,16 @@ pymain_get_program_name(_PyMain *pymain)
 static int
 pymain_init_main_interpreter(_PyMain *pymain)
 {
-    _PyMainInterpreterConfig config = _PyMainInterpreterConfig_INIT;
     _PyInitError err;
 
-    /* TODO: Moar config options! */
-    config.install_signal_handlers = 1;
-
     /* TODO: Print any exceptions raised by these operations */
-    err = _Py_ReadMainInterpreterConfig(&config);
+    err = _Py_ReadMainInterpreterConfig(&pymain->config);
     if (_Py_INIT_FAILED(err)) {
         pymain->err = err;
         return -1;
     }
 
-    err = _Py_InitializeMainInterpreter(&config);
+    err = _Py_InitializeMainInterpreter(&pymain->config);
     if (_Py_INIT_FAILED(err)) {
         pymain->err = err;
         return -1;
@@ -1387,7 +1385,7 @@ pymain_init_pythonpath(_PyMain *pymain)
         return -1;
     }
 
-    pymain->core_config.module_search_path_env = path2;
+    pymain->config.module_search_path_env = path2;
 #else
     char *path = pymain_get_env_var("PYTHONPATH");
     if (!path) {
@@ -1405,7 +1403,7 @@ pymain_init_pythonpath(_PyMain *pymain)
         }
         return -1;
     }
-    pymain->core_config.module_search_path_env = wpath;
+    pymain->config.module_search_path_env = wpath;
 #endif
     return 0;
 }
@@ -1574,6 +1572,8 @@ pymain_init(_PyMain *pymain)
     }
 
     pymain->core_config._disable_importlib = 0;
+    /* TODO: Moar config options! */
+    pymain->config.install_signal_handlers = 1;
 
     orig_argc = pymain->argc;           /* For Py_GetArgcArgv() */
     orig_argv = pymain->argv;
index b182ae6a58df689976a3e205c340315446631b55..1d18faed4500ed77f6022ab134a0fb45988b7f57 100644 (file)
@@ -624,7 +624,7 @@ error:
 
 
 static void
-calculate_path(_PyCoreConfig *core_config)
+calculate_path(_PyMainInterpreterConfig *config)
 {
     wchar_t argv0_path[MAXPATHLEN+1];
     wchar_t *buf;
@@ -637,8 +637,8 @@ calculate_path(_PyCoreConfig *core_config)
     wchar_t *userpath = NULL;
     wchar_t zip_path[MAXPATHLEN+1];
 
-    if (core_config) {
-        envpath = core_config->module_search_path_env;
+    if (config) {
+        envpath = config->module_search_path_env;
     }
     else if (!Py_IgnoreEnvironmentFlag) {
         envpath = _wgetenv(L"PYTHONPATH");
@@ -899,10 +899,10 @@ Py_SetPath(const wchar_t *path)
 }
 
 wchar_t *
-_Py_GetPathWithConfig(_PyCoreConfig *core_config)
+_Py_GetPathWithConfig(_PyMainInterpreterConfig *config)
 {
     if (!module_search_path) {
-        calculate_path(core_config);
+        calculate_path(config);
     }
     return module_search_path;
 }
index 9eeac9d33be60171080aef1e77a6b241885f8b71..552501d23ca531b03b837c4293ff5bb3e13e058b 100644 (file)
@@ -843,7 +843,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
     /* GetPath may initialize state that _PySys_EndInit locks
        in, and so has to be called first. */
     /* TODO: Call Py_GetPath() in Py_ReadConfig, rather than here */
-    wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config);
+    wchar_t *sys_path = _Py_GetPathWithConfig(&interp->config);
 
     if (interp->core_config._disable_importlib) {
         /* Special mode for freeze_importlib: run with no import system
@@ -1301,7 +1301,7 @@ new_interpreter(PyThreadState **tstate_p)
 
     /* XXX The following is lax in error checking */
 
-    wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config);
+    wchar_t *sys_path = _Py_GetPathWithConfig(&interp->config);
 
     PyObject *modules = PyDict_New();
     if (modules == NULL) {