]> git.pld-linux.org Git - packages/vim.git/blob - 6.2.297
- initial import
[packages/vim.git] / 6.2.297
1 To: vim-dev@vim.org
2 Subject: Patch 6.2.297
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
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
15
16
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
19 ***************
20 *** 363,395 ****
21   typedef PyObject PyThreadState;
22   #endif /* Python 1.4 */
23   
24   static PyThreadState* saved_python_thread = NULL;
25   
26 ! /* suspend a thread of the python interpreter
27 !    - other threads are allowed to run */
28
29   static void Python_SaveThread(void)
30   {
31       saved_python_thread = PyEval_SaveThread();
32   }
33   
34 ! /* restore a thread of the python interpreter
35 !    - waits for other threads to block */
36
37   static void Python_RestoreThread(void)
38   {
39 !     PyEval_RestoreThread( saved_python_thread );
40       saved_python_thread = NULL;
41   }
42   
43 ! /* obtain a lock on the Vim data structures */
44
45   static void Python_Lock_Vim(void)
46   {
47   }
48   
49 ! /* release a lock on the Vim data structures */
50
51   static void Python_Release_Vim(void)
52   {
53   }
54 --- 363,404 ----
55   typedef PyObject PyThreadState;
56   #endif /* Python 1.4 */
57   
58 + #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0
59 +   /* Python 2.3: can invoke ":python" recursively. */
60 + # define PY_CAN_RECURSE
61 + #else
62   static PyThreadState* saved_python_thread = NULL;
63   
64 ! /*
65 !  * Suspend a thread of the Python interpreter, other threads are allowed to
66 !  * run.
67 !  */
68   static void Python_SaveThread(void)
69   {
70       saved_python_thread = PyEval_SaveThread();
71   }
72   
73 ! /*
74 !  * Restore a thread of the Python interpreter, waits for other threads to
75 !  * block.
76 !  */
77   static void Python_RestoreThread(void)
78   {
79 !     PyEval_RestoreThread(saved_python_thread);
80       saved_python_thread = NULL;
81   }
82 + #endif
83   
84 ! /*
85 !  * obtain a lock on the Vim data structures
86 !  */
87   static void Python_Lock_Vim(void)
88   {
89   }
90   
91 ! /*
92 !  * release a lock on the Vim data structures
93 !  */
94   static void Python_Release_Vim(void)
95   {
96   }
97 ***************
98 *** 433,440 ****
99 --- 442,451 ----
100         if (PythonMod_Init())
101             goto fail;
102   
103 + #ifndef PY_CAN_RECURSE
104         /* the first python thread is vim's */
105         Python_SaveThread();
106 + #endif
107   
108         initialised = 1;
109       }
110 ***************
111 *** 457,476 ****
112       static void
113   DoPythonCommand(exarg_T *eap, const char *cmd)
114   {
115 !     static int recursive = 0;
116   
117       if (recursive)
118       {
119         EMSG(_("E659: Cannot invoke Python recursively"));
120         return;
121       }
122       ++recursive;
123   
124   #if defined(MACOS) && !defined(MACOS_X_UNIX)
125 !     GrafPtr oldPort;
126 !     GetPort (&oldPort);
127       /* Check if the Python library is available */
128 !     if ( (Ptr) PyMac_Initialize == (Ptr) kUnresolvedCFragSymbolAddress)
129         goto theend;
130   #endif
131       if (Python_Init())
132 --- 468,495 ----
133       static void
134   DoPythonCommand(exarg_T *eap, const char *cmd)
135   {
136 ! #ifdef PY_CAN_RECURSE
137 !     PyGILState_STATE  pygilstate;
138 ! #else
139 !     static int                recursive = 0;
140 ! #endif
141 ! #if defined(MACOS) && !defined(MACOS_X_UNIX)
142 !     GrafPtr           oldPort;
143 ! #endif
144   
145 + #ifndef PY_CAN_RECURSE
146       if (recursive)
147       {
148         EMSG(_("E659: Cannot invoke Python recursively"));
149         return;
150       }
151       ++recursive;
152 + #endif
153   
154   #if defined(MACOS) && !defined(MACOS_X_UNIX)
155 !     GetPort(&oldPort);
156       /* Check if the Python library is available */
157 !     if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
158         goto theend;
159   #endif
160       if (Python_Init())
161 ***************
162 *** 479,495 ****
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 */
170       PythonIO_Flush();
171   #if defined(MACOS) && !defined(MACOS_X_UNIX)
172 !     SetPort (oldPort);
173   #endif
174   
175   theend:
176 !     --recursive;
177   }
178   
179   /*
180 --- 498,529 ----
181       RangeStart = eap->line1;
182       RangeEnd = eap->line2;
183       Python_Release_Vim();         /* leave vim */
184
185 + #ifdef PY_CAN_RECURSE
186 +     pygilstate = PyGILState_Ensure();
187 + #else
188       Python_RestoreThread();       /* enter python */
189 + #endif
190
191       PyRun_SimpleString((char *)(cmd));
192
193 + #ifdef PY_CAN_RECURSE
194 +     PyGILState_Release(pygilstate);
195 + #else
196       Python_SaveThread();          /* leave python */
197 + #endif
198
199       Python_Lock_Vim();                    /* enter vim */
200       PythonIO_Flush();
201   #if defined(MACOS) && !defined(MACOS_X_UNIX)
202 !     SetPort(oldPort);
203   #endif
204   
205   theend:
206 ! #ifndef PY_CAN_RECURSE
207 !     --recursive
208 ! #endif
209 !     return;       /* keeps lint happy */
210   }
211   
212   /*
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
215 ***************
216 *** 639,640 ****
217 --- 639,642 ----
218   {   /* Add new patch number below this line */
219 + /**/
220 +     297,
221   /**/
222
223 -- 
224 I have to exercise early in the morning before my brain
225 figures out what I'm doing.
226
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 ///
This page took 0.049723 seconds and 3 git commands to generate.