diff src/if_python.c @ 13154:53cc7ea77c54 v8.0.1451

patch 8.0.1451: difficult to set the python home directories properly commit https://github.com/vim/vim/commit/94073167e3aa8cbe18380e93a2fc8e8165438cc8 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 31 21:49:05 2018 +0100 patch 8.0.1451: difficult to set the python home directories properly Problem: It is difficult to set the python home directory properly for Python 2.7 and 3.5 since both use $PYTHONHOME. Solution: Add the 'pythonhome' and 'pythonthreehome' options. (Kazuki Sakamoto, closes #1266)
author Christian Brabandt <cb@256bit.org>
date Wed, 31 Jan 2018 22:00:07 +0100
parents 351cf7c67bbe
children 8412df1479a3
line wrap: on
line diff
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -912,6 +912,8 @@ python_loaded(void)
 }
 #endif
 
+static char *py_home_buf = NULL;
+
     static int
 Python_Init(void)
 {
@@ -929,10 +931,15 @@ Python_Init(void)
 	}
 #endif
 
+	if (*p_pyhome != NUL)
+	{
+	    /* The string must not change later, make a copy in static memory. */
+	    py_home_buf = (char *)vim_strsave(p_pyhome);
+	    if (py_home_buf != NULL)
+		Py_SetPythonHome(py_home_buf);
+	}
 #ifdef PYTHON_HOME
-# ifdef DYNAMIC_PYTHON
-	if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
-# endif
+	else if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
 	    Py_SetPythonHome(PYTHON_HOME);
 #endif