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.943 < prev    next >
Encoding:
Internet Message Format  |  2013-05-11  |  6.7 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.943
  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.943
  11. Problem:    Python: Negative indices were failing.
  12. Solution:   Fix negative indices. Add tests. (ZyX)
  13. Files:        src/if_py_both.h, 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.942/src/if_py_both.h    2013-05-12 20:36:09.000000000 +0200
  19. --- src/if_py_both.h    2013-05-12 21:10:03.000000000 +0200
  20. ***************
  21. *** 2394,2399 ****
  22. --- 2394,2402 ----
  23.       if (end == -1)
  24.       end = self->buf->b_ml.ml_line_count;
  25.   
  26. +     if (n < 0)
  27. +     n += end - start + 1;
  28.       if (n < 0 || n > end - start)
  29.       {
  30.       PyErr_SetString(PyExc_IndexError, _("line number out of range"));
  31. ***************
  32. *** 2441,2446 ****
  33. --- 2444,2452 ----
  34.       if (end == -1)
  35.       end = self->buf->b_ml.ml_line_count;
  36.   
  37. +     if (n < 0)
  38. +     n += end - start + 1;
  39.       if (n < 0 || n > end - start)
  40.       {
  41.       PyErr_SetString(PyExc_IndexError, _("line number out of range"));
  42. *** ../vim-7.3.942/src/if_python3.c    2013-05-12 20:36:09.000000000 +0200
  43. --- src/if_python3.c    2013-05-12 21:10:03.000000000 +0200
  44. ***************
  45. *** 1114,1120 ****
  46.           return NULL;
  47.   
  48.       if (PySlice_GetIndicesEx((PyObject *)idx,
  49. !           (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
  50.             &start, &stop,
  51.             &step, &slicelen) < 0)
  52.       {
  53. --- 1114,1120 ----
  54.           return NULL;
  55.   
  56.       if (PySlice_GetIndicesEx((PyObject *)idx,
  57. !           (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
  58.             &start, &stop,
  59.             &step, &slicelen) < 0)
  60.       {
  61. ***************
  62. *** 1146,1152 ****
  63.           return -1;
  64.   
  65.       if (PySlice_GetIndicesEx((PyObject *)idx,
  66. !           (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
  67.             &start, &stop,
  68.             &step, &slicelen) < 0)
  69.       {
  70. --- 1146,1152 ----
  71.           return -1;
  72.   
  73.       if (PySlice_GetIndicesEx((PyObject *)idx,
  74. !           (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
  75.             &start, &stop,
  76.             &step, &slicelen) < 0)
  77.       {
  78. *** ../vim-7.3.942/src/testdir/test86.in    2013-05-06 03:52:44.000000000 +0200
  79. --- src/testdir/test86.in    2013-05-12 21:11:43.000000000 +0200
  80. ***************
  81. *** 475,483 ****
  82.   :       endtry
  83.   :   endfor
  84.   :   call RecVars(oname)
  85. - endtry
  86.   :endfor
  87.   :only
  88.   :endfun
  89.   :"
  90.   :call Test()
  91. --- 475,524 ----
  92.   :       endtry
  93.   :   endfor
  94.   :   call RecVars(oname)
  95.   :endfor
  96.   :only
  97. + :"
  98. + :" Test buffer object
  99. + :vnew
  100. + :put ='First line'
  101. + :put ='Second line'
  102. + :put ='Third line'
  103. + :1 delete _
  104. + :py b=vim.current.buffer
  105. + :wincmd w
  106. + :mark a
  107. + py << EOF
  108. + cb = vim.current.buffer
  109. + # Tests BufferAppend and BufferItem
  110. + cb.append(b[0])
  111. + # Tests BufferSlice and BufferAssSlice
  112. + cb.append('abc') # Will be overwritten
  113. + cb[-1:] = b[:-2]
  114. + # Test BufferLength and BufferAssSlice
  115. + cb.append('def') # Will not be overwritten
  116. + cb[len(cb):] = b[:]
  117. + # Test BufferAssItem and BufferMark
  118. + cb.append('ghi') # Will be overwritten
  119. + cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
  120. + # Test BufferRepr
  121. + cb.append(repr(cb) + repr(b))
  122. + # Modify foreign buffer
  123. + b.append('foo')
  124. + b[0]='bar'
  125. + b[0:0]=['baz']
  126. + vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
  127. + # Test CheckBuffer
  128. + vim.command('bwipeout! ' + str(b.number))
  129. + for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
  130. +     try:
  131. +         exec(expr)
  132. +     except vim.error:
  133. +         pass
  134. +     else:
  135. +         # Usually a SEGV here
  136. +         # Should not happen in any case
  137. +         cb.append('No exception for ' + expr)
  138. + EOF
  139.   :endfun
  140.   :"
  141.   :call Test()
  142. *** ../vim-7.3.942/src/testdir/test86.ok    2013-05-06 03:52:44.000000000 +0200
  143. --- src/testdir/test86.ok    2013-05-12 21:11:43.000000000 +0200
  144. ***************
  145. *** 306,308 ****
  146. --- 306,321 ----
  147.     G: '.,,'
  148.     W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
  149.     B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
  150. + First line
  151. + First line
  152. + def
  153. + First line
  154. + Second line
  155. + Third line
  156. + (7, 2)
  157. + <buffer test86.in><buffer >
  158. + baz
  159. + bar
  160. + Second line
  161. + Third line
  162. + foo
  163. *** ../vim-7.3.942/src/testdir/test87.in    2013-05-06 03:52:44.000000000 +0200
  164. --- src/testdir/test87.in    2013-05-12 21:11:43.000000000 +0200
  165. ***************
  166. *** 444,452 ****
  167.   :       endtry
  168.   :   endfor
  169.   :   call RecVars(oname)
  170. - endtry
  171.   :endfor
  172.   :only
  173.   :endfun
  174.   :"
  175.   :call Test()
  176. --- 444,493 ----
  177.   :       endtry
  178.   :   endfor
  179.   :   call RecVars(oname)
  180.   :endfor
  181.   :only
  182. + :"
  183. + :" Test buffer object
  184. + :vnew
  185. + :put ='First line'
  186. + :put ='Second line'
  187. + :put ='Third line'
  188. + :1 delete _
  189. + :py3 b=vim.current.buffer
  190. + :wincmd w
  191. + :mark a
  192. + py3 << EOF
  193. + cb = vim.current.buffer
  194. + # Tests BufferAppend and BufferItem
  195. + cb.append(b[0])
  196. + # Tests BufferSlice and BufferAssSlice
  197. + cb.append('abc') # Will be overwritten
  198. + cb[-1:] = b[:-2]
  199. + # Test BufferLength and BufferAssSlice
  200. + cb.append('def') # Will not be overwritten
  201. + cb[len(cb):] = b[:]
  202. + # Test BufferAssItem and BufferMark
  203. + cb.append('ghi') # Will be overwritten
  204. + cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
  205. + # Test BufferRepr
  206. + cb.append(repr(cb) + repr(b))
  207. + # Modify foreign buffer
  208. + b.append('foo')
  209. + b[0]='bar'
  210. + b[0:0]=['baz']
  211. + vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
  212. + # Test CheckBuffer
  213. + vim.command('bwipeout! ' + str(b.number))
  214. + for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
  215. +     try:
  216. +         exec(expr)
  217. +     except vim.error:
  218. +         pass
  219. +     else:
  220. +         # Usually a SEGV here
  221. +         # Should not happen in any case
  222. +         cb.append('No exception for ' + expr)
  223. + EOF
  224.   :endfun
  225.   :"
  226.   :call Test()
  227. *** ../vim-7.3.942/src/testdir/test87.ok    2013-05-06 03:52:44.000000000 +0200
  228. --- src/testdir/test87.ok    2013-05-12 21:11:43.000000000 +0200
  229. ***************
  230. *** 295,297 ****
  231. --- 295,310 ----
  232.     G: '.,,'
  233.     W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
  234.     B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
  235. + First line
  236. + First line
  237. + def
  238. + First line
  239. + Second line
  240. + Third line
  241. + (7, 2)
  242. + <buffer test87.in><buffer >
  243. + baz
  244. + bar
  245. + Second line
  246. + Third line
  247. + foo
  248. *** ../vim-7.3.942/src/version.c    2013-05-12 20:36:09.000000000 +0200
  249. --- src/version.c    2013-05-12 21:11:53.000000000 +0200
  250. ***************
  251. *** 730,731 ****
  252. --- 730,733 ----
  253.   {   /* Add new patch number below this line */
  254. + /**/
  255. +     943,
  256.   /**/
  257.  
  258. -- 
  259. Q: Is selling software the same as selling hardware?
  260. A: No, good hardware is sold new, good software has already been used by many.
  261.  
  262.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  263. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  264. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  265.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  266.