diff src/if_python.c @ 4415:0bbacb6a83bd v7.3.956

updated for version 7.3.956 Problem: Python vim.bindeval() causes SIGABRT. Solution: Make pygilstate a local variable. (Yukihiro Nakadaira)
author Bram Moolenaar <bram@vim.org>
date Wed, 15 May 2013 17:49:05 +0200
parents 7b789d337820
children 7d81f4e96728
line wrap: on
line diff
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -676,11 +676,8 @@ static int SetBufferLineList(buf_T *, Py
 typedef PyObject PyThreadState;
 #endif
 
-#ifdef PY_CAN_RECURSE
-static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
-#else
+#ifndef PY_CAN_RECURSE
 static PyThreadState *saved_python_thread = NULL;
-#endif
 
 /*
  * Suspend a thread of the Python interpreter, other threads are allowed to
@@ -689,11 +686,7 @@ static PyThreadState *saved_python_threa
     static void
 Python_SaveThread(void)
 {
-#ifdef PY_CAN_RECURSE
-    PyGILState_Release(pygilstate);
-#else
     saved_python_thread = PyEval_SaveThread();
-#endif
 }
 
 /*
@@ -703,13 +696,10 @@ Python_SaveThread(void)
     static void
 Python_RestoreThread(void)
 {
-#ifdef PY_CAN_RECURSE
-    pygilstate = PyGILState_Ensure();
-#else
     PyEval_RestoreThread(saved_python_thread);
     saved_python_thread = NULL;
+}
 #endif
-}
 
     void
 python_end()
@@ -725,14 +715,22 @@ python_end()
 #ifdef DYNAMIC_PYTHON
     if (hinstPython && Py_IsInitialized())
     {
+# ifdef PY_CAN_RECURSE
+	PyGILState_Ensure();
+# else
 	Python_RestoreThread();	    /* enter python */
+# endif
 	Py_Finalize();
     }
     end_dynamic_python();
 #else
     if (Py_IsInitialized())
     {
+# ifdef PY_CAN_RECURSE
+	PyGILState_Ensure();
+# else
 	Python_RestoreThread();	    /* enter python */
+# endif
 	Py_Finalize();
     }
 #endif
@@ -837,6 +835,9 @@ DoPythonCommand(exarg_T *eap, const char
 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
     char		*saved_locale;
 #endif
+#ifdef PY_CAN_RECURSE
+    PyGILState_STATE	pygilstate;
+#endif
 
 #ifndef PY_CAN_RECURSE
     if (recursive)
@@ -881,7 +882,11 @@ DoPythonCommand(exarg_T *eap, const char
     }
 #endif
 
+#ifdef PY_CAN_RECURSE
+    pygilstate = PyGILState_Ensure();
+#else
     Python_RestoreThread();	    /* enter python */
+#endif
 
     if (rettv == NULL)
 	PyRun_SimpleString((char *)(cmd));
@@ -905,7 +910,11 @@ DoPythonCommand(exarg_T *eap, const char
 	PyErr_Clear();
     }
 
+#ifdef PY_CAN_RECURSE
+    PyGILState_Release(pygilstate);
+#else
     Python_SaveThread();	    /* leave python */
+#endif
 
 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
     if (saved_locale != NULL)