diff options
author | Scott Prager <splinterofchaos@gmail.com> | 2014-09-05 13:15:48 -0400 |
---|---|---|
committer | Scott Prager <splinterofchaos@gmail.com> | 2014-12-11 20:30:00 -0500 |
commit | 3d93e47d9af5722c0e1be1d073090347d6ae28e3 (patch) | |
tree | 41f7092e37def49a8aec40405fd4a197c22bdc11 /src | |
parent | 171445ef3441a4dbc9958871760e42460ba7404c (diff) | |
download | rneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.tar.gz rneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.tar.bz2 rneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 23 | ||||
-rw-r--r-- | src/nvim/testdir/test_eval.in | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_eval.ok | bin | 10307 -> 10578 bytes | |||
-rw-r--r-- | src/nvim/version.c | 2 |
4 files changed, 24 insertions, 7 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2e2871abc5..86ac112212 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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]; diff --git a/src/nvim/testdir/test_eval.in b/src/nvim/testdir/test_eval.in index 176e62b9cc..95a59ee42a 100644 --- a/src/nvim/testdir/test_eval.in +++ b/src/nvim/testdir/test_eval.in @@ -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 :" diff --git a/src/nvim/testdir/test_eval.ok b/src/nvim/testdir/test_eval.ok Binary files differindex 7fe5f1bd1b..061e0cfd2f 100644 --- a/src/nvim/testdir/test_eval.ok +++ b/src/nvim/testdir/test_eval.ok diff --git a/src/nvim/version.c b/src/nvim/version.c index 722a725df2..6f37982f4d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -416,7 +416,7 @@ static int included_patches[] = { //252 NA 251, //250 NA - //249, + 249, 248, 247, //246, |