home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.808 < prev    next >
Encoding:
Internet Message Format  |  2013-02-12  |  8.0 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.808
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.808
  11. Problem:    Python threads still do not work properly.
  12. Solution:   Fix both Python 2 and 3.  Add tests. (Ken Takata)
  13. Files:        src/if_python.c, src/if_python3.c, src/testdir/test86.in,
  14.         src/testdir/test86.ok, src/testdir/test87.in,
  15.         src/testdir/test87.ok
  16.  
  17.  
  18. *** ../vim-7.3.807/src/if_python.c    2013-01-30 11:44:33.000000000 +0100
  19. --- src/if_python.c    2013-02-13 14:07:28.000000000 +0100
  20. ***************
  21. *** 741,747 ****
  22.       PyMac_Initialize();
  23.   #endif
  24.       /* Initialise threads, and below save the state using
  25. !      * PyGILState_Ensure.  Without the call to PyGILState_Ensure, thread
  26.        * specific state (such as the system trace hook), will be lost
  27.        * between invocations of Python code. */
  28.       PyEval_InitThreads();
  29. --- 741,747 ----
  30.       PyMac_Initialize();
  31.   #endif
  32.       /* Initialise threads, and below save the state using
  33. !      * PyEval_SaveThread.  Without the call to PyEval_SaveThread, thread
  34.        * specific state (such as the system trace hook), will be lost
  35.        * between invocations of Python code. */
  36.       PyEval_InitThreads();
  37. ***************
  38. *** 755,764 ****
  39.       if (PythonMod_Init())
  40.           goto fail;
  41.   
  42. -     /* The first python thread is vim's, release the lock. */
  43. -     Python_SaveThread();
  44. -     pygilstate = PyGILState_Ensure();
  45.       globals = PyModule_GetDict(PyImport_AddModule("__main__"));
  46.   
  47.       /* Remove the element from sys.path that was added because of our
  48. --- 755,760 ----
  49. ***************
  50. *** 767,773 ****
  51.        * the current directory in sys.path. */
  52.       PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
  53.   
  54. !     PyGILState_Release(pygilstate);
  55.   
  56.       initialised = 1;
  57.       }
  58. --- 763,776 ----
  59.        * the current directory in sys.path. */
  60.       PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
  61.   
  62. !     /* lock is created and acquired in PyEval_InitThreads() and thread
  63. !      * state is created in Py_Initialize()
  64. !      * there _PyGILState_NoteThreadState() also sets gilcounter to 1
  65. !      * (python must have threads enabled!)
  66. !      * so the following does both: unlock GIL and save thread state in TLS
  67. !      * without deleting thread state
  68. !      */
  69. !     PyEval_SaveThread();
  70.   
  71.       initialised = 1;
  72.       }
  73. *** ../vim-7.3.807/src/if_python3.c    2012-11-28 15:33:10.000000000 +0100
  74. --- src/if_python3.c    2013-02-13 14:07:28.000000000 +0100
  75. ***************
  76. *** 729,741 ****
  77.   #else
  78.       PyMac_Initialize();
  79.   #endif
  80. !     /* Initialise threads, and save the state using PyGILState_Ensure.
  81. !      * Without the call to PyGILState_Ensure, thread specific state (such
  82. !      * as the system trace hook), will be lost between invocations of
  83. !      * Python code. */
  84.       PyEval_InitThreads();
  85. -     pygilstate = PyGILState_Ensure();
  86.   #ifdef DYNAMIC_PYTHON3
  87.       get_py3_exceptions();
  88.   #endif
  89. --- 729,739 ----
  90.   #else
  91.       PyMac_Initialize();
  92.   #endif
  93. !     /* Initialise threads, and below save the state using
  94. !      * PyEval_SaveThread.  Without the call to PyEval_SaveThread, thread
  95. !      * specific state (such as the system trace hook), will be lost
  96. !      * between invocations of Python code. */
  97.       PyEval_InitThreads();
  98.   #ifdef DYNAMIC_PYTHON3
  99.       get_py3_exceptions();
  100.   #endif
  101. ***************
  102. *** 754,766 ****
  103.        */
  104.       PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
  105.   
  106. !     // lock is created and acquired in PyEval_InitThreads() and thread
  107. !     // state is created in Py_Initialize()
  108. !     // there _PyGILState_NoteThreadState() also sets gilcounter to 1
  109. !     // (python must have threads enabled!)
  110. !     // so the following does both: unlock GIL and save thread state in TLS
  111. !     // without deleting thread state
  112. !     PyGILState_Release(pygilstate);
  113.   
  114.       py3initialised = 1;
  115.       }
  116. --- 752,765 ----
  117.        */
  118.       PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
  119.   
  120. !     /* lock is created and acquired in PyEval_InitThreads() and thread
  121. !      * state is created in Py_Initialize()
  122. !      * there _PyGILState_NoteThreadState() also sets gilcounter to 1
  123. !      * (python must have threads enabled!)
  124. !      * so the following does both: unlock GIL and save thread state in TLS
  125. !      * without deleting thread state
  126. !      */
  127. !     PyEval_SaveThread();
  128.   
  129.       py3initialised = 1;
  130.       }
  131. *** ../vim-7.3.807/src/testdir/test86.in    2012-09-21 14:00:05.000000000 +0200
  132. --- src/testdir/test86.in    2013-02-13 13:58:25.000000000 +0100
  133. ***************
  134. *** 267,272 ****
  135. --- 267,320 ----
  136.   :      $put =toput
  137.   :   endtry
  138.   :endfor
  139. + :"
  140. + :" threading
  141. + :let l = [0]
  142. + :py l=vim.bindeval('l')
  143. + :py <<EOF
  144. + import threading
  145. + import time
  146. + class T(threading.Thread):
  147. +     def __init__(self):
  148. +         threading.Thread.__init__(self)
  149. +         self.t = 0
  150. +         self.running = True
  151. +     def run(self):
  152. +         while self.running:
  153. +             self.t += 1
  154. +             time.sleep(0.1)
  155. + t = T()
  156. + t.start()
  157. + EOF
  158. + :sleep 1
  159. + :py t.running = False
  160. + :py t.join()
  161. + :py l[0] = t.t > 8  # check if the background thread is working
  162. + :$put =string(l)
  163. + :"
  164. + :" settrace
  165. + :let l = []
  166. + :py l=vim.bindeval('l')
  167. + :py <<EOF
  168. + import sys
  169. + def traceit(frame, event, arg):
  170. +     global l
  171. +     if event == "line":
  172. +         l.extend([frame.f_lineno])
  173. +     return traceit
  174. + def trace_main():
  175. +     for i in range(5):
  176. +         pass
  177. + EOF
  178. + :py sys.settrace(traceit)
  179. + :py trace_main()
  180. + :py sys.settrace(None)
  181. + :$put =string(l)
  182.   :endfun
  183.   :"
  184.   :call Test()
  185. *** ../vim-7.3.807/src/testdir/test86.ok    2012-09-21 14:00:05.000000000 +0200
  186. --- src/testdir/test86.ok    2013-02-13 13:58:25.000000000 +0100
  187. ***************
  188. *** 63,65 ****
  189. --- 63,67 ----
  190.   {"\0": 1}:    Vim(let):E859:
  191.   undefined_name:    Vim(let):E858:
  192.   vim:    Vim(let):E859:
  193. + [1]
  194. + [1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1]
  195. *** ../vim-7.3.807/src/testdir/test87.in    2012-09-21 14:00:05.000000000 +0200
  196. --- src/testdir/test87.in    2013-02-13 13:58:25.000000000 +0100
  197. ***************
  198. *** 267,272 ****
  199. --- 267,320 ----
  200.   :      $put =toput
  201.   :   endtry
  202.   :endfor
  203. + :"
  204. + :" threading
  205. + :let l = [0]
  206. + :py3 l=vim.bindeval('l')
  207. + :py3 <<EOF
  208. + import threading
  209. + import time
  210. + class T(threading.Thread):
  211. +     def __init__(self):
  212. +         threading.Thread.__init__(self)
  213. +         self.t = 0
  214. +         self.running = True
  215. +     def run(self):
  216. +         while self.running:
  217. +             self.t += 1
  218. +             time.sleep(0.1)
  219. + t = T()
  220. + t.start()
  221. + EOF
  222. + :sleep 1
  223. + :py3 t.running = False
  224. + :py3 t.join()
  225. + :py3 l[0] = t.t > 8  # check if the background thread is working
  226. + :$put =string(l)
  227. + :"
  228. + :" settrace
  229. + :let l = []
  230. + :py3 l=vim.bindeval('l')
  231. + :py3 <<EOF
  232. + import sys
  233. + def traceit(frame, event, arg):
  234. +     global l
  235. +     if event == "line":
  236. +         l += [frame.f_lineno]
  237. +     return traceit
  238. + def trace_main():
  239. +     for i in range(5):
  240. +         pass
  241. + EOF
  242. + :py3 sys.settrace(traceit)
  243. + :py3 trace_main()
  244. + :py3 sys.settrace(None)
  245. + :$put =string(l)
  246.   :endfun
  247.   :"
  248.   :call Test()
  249. *** ../vim-7.3.807/src/testdir/test87.ok    2012-09-21 14:00:05.000000000 +0200
  250. --- src/testdir/test87.ok    2013-02-13 13:58:25.000000000 +0100
  251. ***************
  252. *** 63,65 ****
  253. --- 63,67 ----
  254.   {"\0": 1}:    Vim(let):E861:
  255.   undefined_name:    Vim(let):E860:
  256.   vim:    Vim(let):E861:
  257. + [1]
  258. + [1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1]
  259. *** ../vim-7.3.807/src/version.c    2013-02-13 12:15:59.000000000 +0100
  260. --- src/version.c    2013-02-13 14:10:53.000000000 +0100
  261. ***************
  262. *** 727,728 ****
  263. --- 727,730 ----
  264.   {   /* Add new patch number below this line */
  265. + /**/
  266. +     808,
  267.   /**/
  268.  
  269. -- 
  270. Lawmakers made it obligatory for everybody to take at least one bath
  271. each week -- on Saturday night.
  272.         [real standing law in Vermont, United States of America]
  273.  
  274.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  275. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  276. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  277.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  278.