50f7bcc
To: vim_dev@googlegroups.com
50f7bcc
Subject: Patch 7.3.943
50f7bcc
Fcc: outbox
50f7bcc
From: Bram Moolenaar <Bram@moolenaar.net>
50f7bcc
Mime-Version: 1.0
50f7bcc
Content-Type: text/plain; charset=UTF-8
50f7bcc
Content-Transfer-Encoding: 8bit
50f7bcc
------------
50f7bcc
50f7bcc
Patch 7.3.943
50f7bcc
Problem:    Python: Negative indices were failing.
50f7bcc
Solution:   Fix negative indices. Add tests. (ZyX)
50f7bcc
Files:	    src/if_py_both.h, src/if_python3.c, src/testdir/test86.in,
50f7bcc
	    src/testdir/test86.ok, src/testdir/test87.in,
50f7bcc
	    src/testdir/test87.ok
50f7bcc
50f7bcc
50f7bcc
*** ../vim-7.3.942/src/if_py_both.h	2013-05-12 20:36:09.000000000 +0200
50f7bcc
--- src/if_py_both.h	2013-05-12 21:10:03.000000000 +0200
50f7bcc
***************
50f7bcc
*** 2394,2399 ****
50f7bcc
--- 2394,2402 ----
50f7bcc
      if (end == -1)
50f7bcc
  	end = self->buf->b_ml.ml_line_count;
50f7bcc
  
50f7bcc
+     if (n < 0)
50f7bcc
+ 	n += end - start + 1;
50f7bcc
+ 
50f7bcc
      if (n < 0 || n > end - start)
50f7bcc
      {
50f7bcc
  	PyErr_SetString(PyExc_IndexError, _("line number out of range"));
50f7bcc
***************
50f7bcc
*** 2441,2446 ****
50f7bcc
--- 2444,2452 ----
50f7bcc
      if (end == -1)
50f7bcc
  	end = self->buf->b_ml.ml_line_count;
50f7bcc
  
50f7bcc
+     if (n < 0)
50f7bcc
+ 	n += end - start + 1;
50f7bcc
+ 
50f7bcc
      if (n < 0 || n > end - start)
50f7bcc
      {
50f7bcc
  	PyErr_SetString(PyExc_IndexError, _("line number out of range"));
50f7bcc
*** ../vim-7.3.942/src/if_python3.c	2013-05-12 20:36:09.000000000 +0200
50f7bcc
--- src/if_python3.c	2013-05-12 21:10:03.000000000 +0200
50f7bcc
***************
50f7bcc
*** 1114,1120 ****
50f7bcc
  	    return NULL;
50f7bcc
  
50f7bcc
  	if (PySlice_GetIndicesEx((PyObject *)idx,
50f7bcc
! 	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
50f7bcc
  	      &start, &stop,
50f7bcc
  	      &step, &slicelen) < 0)
50f7bcc
  	{
50f7bcc
--- 1114,1120 ----
50f7bcc
  	    return NULL;
50f7bcc
  
50f7bcc
  	if (PySlice_GetIndicesEx((PyObject *)idx,
50f7bcc
! 	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
50f7bcc
  	      &start, &stop,
50f7bcc
  	      &step, &slicelen) < 0)
50f7bcc
  	{
50f7bcc
***************
50f7bcc
*** 1146,1152 ****
50f7bcc
  	    return -1;
50f7bcc
  
50f7bcc
  	if (PySlice_GetIndicesEx((PyObject *)idx,
50f7bcc
! 	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
50f7bcc
  	      &start, &stop,
50f7bcc
  	      &step, &slicelen) < 0)
50f7bcc
  	{
50f7bcc
--- 1146,1152 ----
50f7bcc
  	    return -1;
50f7bcc
  
50f7bcc
  	if (PySlice_GetIndicesEx((PyObject *)idx,
50f7bcc
! 	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
50f7bcc
  	      &start, &stop,
50f7bcc
  	      &step, &slicelen) < 0)
50f7bcc
  	{
50f7bcc
*** ../vim-7.3.942/src/testdir/test86.in	2013-05-06 03:52:44.000000000 +0200
50f7bcc
--- src/testdir/test86.in	2013-05-12 21:11:43.000000000 +0200
50f7bcc
***************
50f7bcc
*** 475,483 ****
50f7bcc
  :       endtry
50f7bcc
  :   endfor
50f7bcc
  :   call RecVars(oname)
50f7bcc
- endtry
50f7bcc
  :endfor
50f7bcc
  :only
50f7bcc
  :endfun
50f7bcc
  :"
50f7bcc
  :call Test()
50f7bcc
--- 475,524 ----
50f7bcc
  :       endtry
50f7bcc
  :   endfor
50f7bcc
  :   call RecVars(oname)
50f7bcc
  :endfor
50f7bcc
  :only
50f7bcc
+ :"
50f7bcc
+ :" Test buffer object
50f7bcc
+ :vnew
50f7bcc
+ :put ='First line'
50f7bcc
+ :put ='Second line'
50f7bcc
+ :put ='Third line'
50f7bcc
+ :1 delete _
50f7bcc
+ :py b=vim.current.buffer
50f7bcc
+ :wincmd w
50f7bcc
+ :mark a
50f7bcc
+ py << EOF
50f7bcc
+ cb = vim.current.buffer
50f7bcc
+ # Tests BufferAppend and BufferItem
50f7bcc
+ cb.append(b[0])
50f7bcc
+ # Tests BufferSlice and BufferAssSlice
50f7bcc
+ cb.append('abc') # Will be overwritten
50f7bcc
+ cb[-1:] = b[:-2]
50f7bcc
+ # Test BufferLength and BufferAssSlice
50f7bcc
+ cb.append('def') # Will not be overwritten
50f7bcc
+ cb[len(cb):] = b[:]
50f7bcc
+ # Test BufferAssItem and BufferMark
50f7bcc
+ cb.append('ghi') # Will be overwritten
50f7bcc
+ cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
50f7bcc
+ # Test BufferRepr
50f7bcc
+ cb.append(repr(cb) + repr(b))
50f7bcc
+ # Modify foreign buffer
50f7bcc
+ b.append('foo')
50f7bcc
+ b[0]='bar'
50f7bcc
+ b[0:0]=['baz']
50f7bcc
+ vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
50f7bcc
+ # Test CheckBuffer
50f7bcc
+ vim.command('bwipeout! ' + str(b.number))
50f7bcc
+ for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
50f7bcc
+     try:
50f7bcc
+         exec(expr)
50f7bcc
+     except vim.error:
50f7bcc
+         pass
50f7bcc
+     else:
50f7bcc
+         # Usually a SEGV here
50f7bcc
+         # Should not happen in any case
50f7bcc
+         cb.append('No exception for ' + expr)
50f7bcc
+ EOF
50f7bcc
  :endfun
50f7bcc
  :"
50f7bcc
  :call Test()
50f7bcc
*** ../vim-7.3.942/src/testdir/test86.ok	2013-05-06 03:52:44.000000000 +0200
50f7bcc
--- src/testdir/test86.ok	2013-05-12 21:11:43.000000000 +0200
50f7bcc
***************
50f7bcc
*** 306,308 ****
50f7bcc
--- 306,321 ----
50f7bcc
    G: '.,,'
50f7bcc
    W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
50f7bcc
    B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
50f7bcc
+ First line
50f7bcc
+ First line
50f7bcc
+ def
50f7bcc
+ First line
50f7bcc
+ Second line
50f7bcc
+ Third line
50f7bcc
+ (7, 2)
50f7bcc
+ <buffer test86.in><buffer >
50f7bcc
+ baz
50f7bcc
+ bar
50f7bcc
+ Second line
50f7bcc
+ Third line
50f7bcc
+ foo
50f7bcc
*** ../vim-7.3.942/src/testdir/test87.in	2013-05-06 03:52:44.000000000 +0200
50f7bcc
--- src/testdir/test87.in	2013-05-12 21:11:43.000000000 +0200
50f7bcc
***************
50f7bcc
*** 444,452 ****
50f7bcc
  :       endtry
50f7bcc
  :   endfor
50f7bcc
  :   call RecVars(oname)
50f7bcc
- endtry
50f7bcc
  :endfor
50f7bcc
  :only
50f7bcc
  :endfun
50f7bcc
  :"
50f7bcc
  :call Test()
50f7bcc
--- 444,493 ----
50f7bcc
  :       endtry
50f7bcc
  :   endfor
50f7bcc
  :   call RecVars(oname)
50f7bcc
  :endfor
50f7bcc
  :only
50f7bcc
+ :"
50f7bcc
+ :" Test buffer object
50f7bcc
+ :vnew
50f7bcc
+ :put ='First line'
50f7bcc
+ :put ='Second line'
50f7bcc
+ :put ='Third line'
50f7bcc
+ :1 delete _
50f7bcc
+ :py3 b=vim.current.buffer
50f7bcc
+ :wincmd w
50f7bcc
+ :mark a
50f7bcc
+ py3 << EOF
50f7bcc
+ cb = vim.current.buffer
50f7bcc
+ # Tests BufferAppend and BufferItem
50f7bcc
+ cb.append(b[0])
50f7bcc
+ # Tests BufferSlice and BufferAssSlice
50f7bcc
+ cb.append('abc') # Will be overwritten
50f7bcc
+ cb[-1:] = b[:-2]
50f7bcc
+ # Test BufferLength and BufferAssSlice
50f7bcc
+ cb.append('def') # Will not be overwritten
50f7bcc
+ cb[len(cb):] = b[:]
50f7bcc
+ # Test BufferAssItem and BufferMark
50f7bcc
+ cb.append('ghi') # Will be overwritten
50f7bcc
+ cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
50f7bcc
+ # Test BufferRepr
50f7bcc
+ cb.append(repr(cb) + repr(b))
50f7bcc
+ # Modify foreign buffer
50f7bcc
+ b.append('foo')
50f7bcc
+ b[0]='bar'
50f7bcc
+ b[0:0]=['baz']
50f7bcc
+ vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
50f7bcc
+ # Test CheckBuffer
50f7bcc
+ vim.command('bwipeout! ' + str(b.number))
50f7bcc
+ for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
50f7bcc
+     try:
50f7bcc
+         exec(expr)
50f7bcc
+     except vim.error:
50f7bcc
+         pass
50f7bcc
+     else:
50f7bcc
+         # Usually a SEGV here
50f7bcc
+         # Should not happen in any case
50f7bcc
+         cb.append('No exception for ' + expr)
50f7bcc
+ EOF
50f7bcc
  :endfun
50f7bcc
  :"
50f7bcc
  :call Test()
50f7bcc
*** ../vim-7.3.942/src/testdir/test87.ok	2013-05-06 03:52:44.000000000 +0200
50f7bcc
--- src/testdir/test87.ok	2013-05-12 21:11:43.000000000 +0200
50f7bcc
***************
50f7bcc
*** 295,297 ****
50f7bcc
--- 295,310 ----
50f7bcc
    G: '.,,'
50f7bcc
    W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
50f7bcc
    B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
50f7bcc
+ First line
50f7bcc
+ First line
50f7bcc
+ def
50f7bcc
+ First line
50f7bcc
+ Second line
50f7bcc
+ Third line
50f7bcc
+ (7, 2)
50f7bcc
+ <buffer test87.in><buffer >
50f7bcc
+ baz
50f7bcc
+ bar
50f7bcc
+ Second line
50f7bcc
+ Third line
50f7bcc
+ foo
50f7bcc
*** ../vim-7.3.942/src/version.c	2013-05-12 20:36:09.000000000 +0200
50f7bcc
--- src/version.c	2013-05-12 21:11:53.000000000 +0200
50f7bcc
***************
50f7bcc
*** 730,731 ****
50f7bcc
--- 730,733 ----
50f7bcc
  {   /* Add new patch number below this line */
50f7bcc
+ /**/
50f7bcc
+     943,
50f7bcc
  /**/
50f7bcc
50f7bcc
-- 
50f7bcc
Q: Is selling software the same as selling hardware?
50f7bcc
A: No, good hardware is sold new, good software has already been used by many.
50f7bcc
50f7bcc
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
50f7bcc
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
50f7bcc
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
50f7bcc
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///