vim-patch:7.4.249

Problem:    Using setreg() with a list of numbers does not work.
Solution:   Use a separate buffer for numbers. (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-249
This commit is contained in:
Scott Prager 2014-09-05 13:15:48 -04:00
parent 171445ef34
commit 3d93e47d9a
4 changed files with 24 additions and 7 deletions

View File

@ -13373,22 +13373,36 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type == VAR_LIST) {
int len = argvars[1].vval.v_list->lv_len;
char_u **lstval = xmalloc(sizeof(char_u *) * (len + 1));
// First half: use for pointers to result lines; second half: use for
// pointers to allocated copies.
char_u **lstval = xmalloc(sizeof(char_u *) * ((len + 1) * 2));
char_u **curval = lstval;
char_u **allocval = lstval + len + 2;
char_u **curallocval = allocval;
char_u buf[NUMBUFLEN];
for (listitem_T *li = argvars[1].vval.v_list->lv_first;
li != NULL;
li = li->li_next) {
char_u *strval = get_tv_string_chk(&li->li_tv);
char_u *strval = get_tv_string_buf_chk(&li->li_tv, buf);
if (strval == NULL) {
free(lstval);
return;
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);
*curallocval++ = strval;
}
*curval++ = strval;
}
*curval++ = NULL;
write_reg_contents_lst(regname, lstval, -1, append, yank_type, block_len);
free_lstval:
while (curallocval > allocval)
free(*--curallocval);
free(lstval);
} else {
char_u *strval = get_tv_string_chk(&argvars[1]);
@ -16334,6 +16348,7 @@ static char_u *get_tv_string_buf(typval_T *varp, char_u *buf)
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(typval_T *varp)
{
static char_u mybuf[NUMBUFLEN];

View File

@ -90,6 +90,8 @@ call SetReg('a', ['abcA3'], 'c')
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,8 +130,8 @@ call ErrExe('call setreg(1, 2, 3, 4)')
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", "2"])')
call ErrExe('call setreg("=", ["1", "2"])')
call ErrExe('call setreg(1, ["", "", [], ""])')
endfun
:"

Binary file not shown.

View File

@ -416,7 +416,7 @@ static int included_patches[] = {
//252 NA
251,
//250 NA
//249,
249,
248,
247,
//246,