4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
10 Patch 6.2.297 (after 6.2.232)
11 Problem: Cannot invoke Python commands recursively.
12 Solution: With Python 2.3 and later use the available mechanisms to invoke
13 Python recursively. (Matthew Mueller)
14 Files: src/if_python.c
17 *** ../vim-6.2.296/src/if_python.c Tue Feb 3 19:59:05 2004
18 --- src/if_python.c Sat Feb 28 21:11:15 2004
21 typedef PyObject PyThreadState;
22 #endif /* Python 1.4 */
24 static PyThreadState* saved_python_thread = NULL;
26 ! /* suspend a thread of the python interpreter
27 ! - other threads are allowed to run */
29 static void Python_SaveThread(void)
31 saved_python_thread = PyEval_SaveThread();
34 ! /* restore a thread of the python interpreter
35 ! - waits for other threads to block */
37 static void Python_RestoreThread(void)
39 ! PyEval_RestoreThread( saved_python_thread );
40 saved_python_thread = NULL;
43 ! /* obtain a lock on the Vim data structures */
45 static void Python_Lock_Vim(void)
49 ! /* release a lock on the Vim data structures */
51 static void Python_Release_Vim(void)
55 typedef PyObject PyThreadState;
56 #endif /* Python 1.4 */
58 + #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0
59 + /* Python 2.3: can invoke ":python" recursively. */
60 + # define PY_CAN_RECURSE
62 static PyThreadState* saved_python_thread = NULL;
65 ! * Suspend a thread of the Python interpreter, other threads are allowed to
68 static void Python_SaveThread(void)
70 saved_python_thread = PyEval_SaveThread();
74 ! * Restore a thread of the Python interpreter, waits for other threads to
77 static void Python_RestoreThread(void)
79 ! PyEval_RestoreThread(saved_python_thread);
80 saved_python_thread = NULL;
85 ! * obtain a lock on the Vim data structures
87 static void Python_Lock_Vim(void)
92 ! * release a lock on the Vim data structures
94 static void Python_Release_Vim(void)
100 if (PythonMod_Init())
103 + #ifndef PY_CAN_RECURSE
104 /* the first python thread is vim's */
113 DoPythonCommand(exarg_T *eap, const char *cmd)
115 ! static int recursive = 0;
119 EMSG(_("E659: Cannot invoke Python recursively"));
124 #if defined(MACOS) && !defined(MACOS_X_UNIX)
126 ! GetPort (&oldPort);
127 /* Check if the Python library is available */
128 ! if ( (Ptr) PyMac_Initialize == (Ptr) kUnresolvedCFragSymbolAddress)
134 DoPythonCommand(exarg_T *eap, const char *cmd)
136 ! #ifdef PY_CAN_RECURSE
137 ! PyGILState_STATE pygilstate;
139 ! static int recursive = 0;
141 ! #if defined(MACOS) && !defined(MACOS_X_UNIX)
145 + #ifndef PY_CAN_RECURSE
148 EMSG(_("E659: Cannot invoke Python recursively"));
154 #if defined(MACOS) && !defined(MACOS_X_UNIX)
156 /* Check if the Python library is available */
157 ! if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
163 RangeStart = eap->line1;
164 RangeEnd = eap->line2;
165 Python_Release_Vim(); /* leave vim */
166 Python_RestoreThread(); /* enter python */
167 PyRun_SimpleString((char *)(cmd));
168 Python_SaveThread(); /* leave python */
169 Python_Lock_Vim(); /* enter vim */
171 #if defined(MACOS) && !defined(MACOS_X_UNIX)
181 RangeStart = eap->line1;
182 RangeEnd = eap->line2;
183 Python_Release_Vim(); /* leave vim */
185 + #ifdef PY_CAN_RECURSE
186 + pygilstate = PyGILState_Ensure();
188 Python_RestoreThread(); /* enter python */
191 PyRun_SimpleString((char *)(cmd));
193 + #ifdef PY_CAN_RECURSE
194 + PyGILState_Release(pygilstate);
196 Python_SaveThread(); /* leave python */
199 Python_Lock_Vim(); /* enter vim */
201 #if defined(MACOS) && !defined(MACOS_X_UNIX)
206 ! #ifndef PY_CAN_RECURSE
209 ! return; /* keeps lint happy */
213 *** ../vim-6.2.296/src/version.c Sun Feb 29 14:48:02 2004
214 --- src/version.c Sun Feb 29 14:52:02 2004
218 { /* Add new patch number below this line */
224 I have to exercise early in the morning before my brain
225 figures out what I'm doing.
227 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
228 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
229 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
230 \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///