summaryrefslogblamecommitdiffstats
path: root/patches/source/vim/patches/7.4.249
blob: 9f290a29bb20715f28d9fe8a451217c5121bde4b (plain) (tree)







































































































































































































                                                                                                  
To: vim_dev@googlegroups.com
Subject: Patch 7.4.249
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.4.249
Problem:    Using setreg() with a list of numbers does not work.
Solution:   Use a separate buffer for numbers. (ZyX)
Files:	    src/eval.c, src/testdir/test_eval.in, src/testdir/test_eval.ok


*** ../vim-7.4.248/src/eval.c	2014-04-05 19:44:36.903160723 +0200
--- src/eval.c	2014-04-05 21:24:21.263173795 +0200
***************
*** 16827,16850 ****
      if (argvars[1].v_type == VAR_LIST)
      {
  	char_u		**lstval;
  	char_u		**curval;
  	int		len = argvars[1].vval.v_list->lv_len;
  	listitem_T	*li;
  
! 	lstval = (char_u **)alloc(sizeof(char_u *) * (len + 1));
  	if (lstval == NULL)
  	    return;
  	curval = lstval;
  
  	for (li = argvars[1].vval.v_list->lv_first; li != NULL;
  							     li = li->li_next)
  	{
! 	    /* TODO: this may use a static buffer several times. */
! 	    strval = get_tv_string_chk(&li->li_tv);
  	    if (strval == NULL)
  	    {
! 		vim_free(lstval);
! 		return;
  	    }
  	    *curval++ = strval;
  	}
--- 16827,16862 ----
      if (argvars[1].v_type == VAR_LIST)
      {
  	char_u		**lstval;
+ 	char_u		**allocval;
+ 	char_u		buf[NUMBUFLEN];
  	char_u		**curval;
+ 	char_u		**curallocval;
  	int		len = argvars[1].vval.v_list->lv_len;
  	listitem_T	*li;
  
! 	/* First half: use for pointers to result lines; second half: use for
! 	 * pointers to allocated copies. */
! 	lstval = (char_u **)alloc(sizeof(char_u *) * ((len + 1) * 2));
  	if (lstval == NULL)
  	    return;
  	curval = lstval;
+ 	allocval = lstval + len + 2;
+ 	curallocval = allocval;
  
  	for (li = argvars[1].vval.v_list->lv_first; li != NULL;
  							     li = li->li_next)
  	{
! 	    strval = get_tv_string_buf_chk(&li->li_tv, buf);
  	    if (strval == NULL)
+ 		goto free_lstval;
+ 	    if (strval == buf)
  	    {
! 		/* Need to make a copy, next get_tv_string_buf_chk() will
! 		 * overwrite the string. */
! 		strval = vim_strsave(buf);
! 		if (strval == NULL)
! 		    goto free_lstval;
! 		*curallocval++ = strval;
  	    }
  	    *curval++ = strval;
  	}
***************
*** 16852,16857 ****
--- 16864,16872 ----
  
  	write_reg_contents_lst(regname, lstval, -1,
  						append, yank_type, block_len);
+ free_lstval:
+ 	while (curallocval > allocval)
+ 	    vim_free(*--curallocval);
  	vim_free(lstval);
      }
      else
***************
*** 20453,20458 ****
--- 20468,20476 ----
      return res != NULL ? res : (char_u *)"";
  }
  
+ /*
+  * Careful: This uses a single, static buffer.  YOU CAN ONLY USE IT ONCE!
+  */
      char_u *
  get_tv_string_chk(varp)
      typval_T	*varp;
*** ../vim-7.4.248/src/testdir/test_eval.in	2014-04-02 22:17:00.003482236 +0200
--- src/testdir/test_eval.in	2014-04-05 21:14:38.367172522 +0200
***************
*** 90,95 ****
--- 90,97 ----
  call SetReg('b', ['abcB3'], 'l')
  call SetReg('c', ['abcC3'], 'b')
  call SetReg('d', ['abcD3'])
+ call SetReg('e', [1, 2, 'abc', 3])
+ call SetReg('f', [1, 2, 3])
  
  $put ='{{{1 Appending lists with setreg()'
  call SetReg('A', ['abcA3c'], 'c')
***************
*** 128,135 ****
  call ErrExe('call setreg([], 2)')
  call ErrExe('call setreg(1, {})')
  call ErrExe('call setreg(1, 2, [])')
! call ErrExe('call setreg("/", [1, 2])')
! call ErrExe('call setreg("=", [1, 2])')
  call ErrExe('call setreg(1, ["", "", [], ""])')
  endfun
  :"
--- 130,137 ----
  call ErrExe('call setreg([], 2)')
  call ErrExe('call setreg(1, {})')
  call ErrExe('call setreg(1, 2, [])')
! call ErrExe('call setreg("/", ["1", "2"])')
! call ErrExe('call setreg("=", ["1", "2"])')
  call ErrExe('call setreg(1, ["", "", [], ""])')
  endfun
  :"
*** ../vim-7.4.248/src/testdir/test_eval.ok	2014-04-02 22:17:00.003482236 +0200
--- src/testdir/test_eval.ok	2014-04-05 21:25:29.207173944 +0200
***************
*** 162,167 ****
--- 162,182 ----
  ==
  abcD3
  ==
+ {{{2 setreg('e', [1, 2, 'abc', 3])
+ e: type V; value: 1