To: vim_dev@googlegroups.com Subject: Patch 7.4.249 Fcc: outbox From: Bram Moolenaar 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: 12abc3 (['1', '2', 'abc', '3']), expr: 12abc3 (['1', '2', 'abc', '3']) + == + 1 + 2 + abc + 3 + == + {{{2 setreg('f', [1, 2, 3]) + f: type V; value: 123 (['1', '2', '3']), expr: 123 (['1', '2', '3']) + == + 1 + 2 + 3 + == {{{1 Appending lists with setreg() {{{2 setreg('A', ['abcA3c'], 'c') A: type v; value: abcA3abcA3c (['abcA3', 'abcA3c']), expr: abcA3abcA3c (['abcA3', 'abcA3c']) *************** *** 314,322 **** Vim(call):E731: using Dictionary as a String Executing call setreg(1, 2, []) Vim(call):E730: using List as a String ! Executing call setreg("/", [1, 2]) Vim(call):E883: search pattern and expression register may not contain two or more lines ! Executing call setreg("=", [1, 2]) Vim(call):E883: search pattern and expression register may not contain two or more lines Executing call setreg(1, ["", "", [], ""]) Vim(call):E730: using List as a String --- 329,337 ---- Vim(call):E731: using Dictionary as a String Executing call setreg(1, 2, []) Vim(call):E730: using List as a String ! Executing call setreg("/", ["1", "2"]) Vim(call):E883: search pattern and expression register may not contain two or more lines ! Executing call setreg("=", ["1", "2"]) Vim(call):E883: search pattern and expression register may not contain two or more lines Executing call setreg(1, ["", "", [], ""]) Vim(call):E730: using List as a String *** ../vim-7.4.248/src/version.c 2014-04-05 19:44:36.903160723 +0200 --- src/version.c 2014-04-05 21:17:34.483172907 +0200 *************** *** 736,737 **** --- 736,739 ---- { /* Add new patch number below this line */ + /**/ + 249, /**/ -- Due knot trussed yore spell chequer two fined awl miss steaks. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///