Mercurial > vim
comparison src/eval.c @ 5810:0b9a66ea49f4 v7.4.249
updated for version 7.4.249
Problem: Using setreg() with a list of numbers does not work.
Solution: Use a separate buffer for numbers. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 05 Apr 2014 21:28:56 +0200 |
parents | e5f1f2ea0b4a |
children | afb542ea210c |
comparison
equal
deleted
inserted
replaced
5809:ddc6a8829b86 | 5810:0b9a66ea49f4 |
---|---|
16825 } | 16825 } |
16826 | 16826 |
16827 if (argvars[1].v_type == VAR_LIST) | 16827 if (argvars[1].v_type == VAR_LIST) |
16828 { | 16828 { |
16829 char_u **lstval; | 16829 char_u **lstval; |
16830 char_u **allocval; | |
16831 char_u buf[NUMBUFLEN]; | |
16830 char_u **curval; | 16832 char_u **curval; |
16833 char_u **curallocval; | |
16831 int len = argvars[1].vval.v_list->lv_len; | 16834 int len = argvars[1].vval.v_list->lv_len; |
16832 listitem_T *li; | 16835 listitem_T *li; |
16833 | 16836 |
16834 lstval = (char_u **)alloc(sizeof(char_u *) * (len + 1)); | 16837 /* First half: use for pointers to result lines; second half: use for |
16838 * pointers to allocated copies. */ | |
16839 lstval = (char_u **)alloc(sizeof(char_u *) * ((len + 1) * 2)); | |
16835 if (lstval == NULL) | 16840 if (lstval == NULL) |
16836 return; | 16841 return; |
16837 curval = lstval; | 16842 curval = lstval; |
16843 allocval = lstval + len + 2; | |
16844 curallocval = allocval; | |
16838 | 16845 |
16839 for (li = argvars[1].vval.v_list->lv_first; li != NULL; | 16846 for (li = argvars[1].vval.v_list->lv_first; li != NULL; |
16840 li = li->li_next) | 16847 li = li->li_next) |
16841 { | 16848 { |
16842 /* TODO: this may use a static buffer several times. */ | 16849 strval = get_tv_string_buf_chk(&li->li_tv, buf); |
16843 strval = get_tv_string_chk(&li->li_tv); | |
16844 if (strval == NULL) | 16850 if (strval == NULL) |
16851 goto free_lstval; | |
16852 if (strval == buf) | |
16845 { | 16853 { |
16846 vim_free(lstval); | 16854 /* Need to make a copy, next get_tv_string_buf_chk() will |
16847 return; | 16855 * overwrite the string. */ |
16856 strval = vim_strsave(buf); | |
16857 if (strval == NULL) | |
16858 goto free_lstval; | |
16859 *curallocval++ = strval; | |
16848 } | 16860 } |
16849 *curval++ = strval; | 16861 *curval++ = strval; |
16850 } | 16862 } |
16851 *curval++ = NULL; | 16863 *curval++ = NULL; |
16852 | 16864 |
16853 write_reg_contents_lst(regname, lstval, -1, | 16865 write_reg_contents_lst(regname, lstval, -1, |
16854 append, yank_type, block_len); | 16866 append, yank_type, block_len); |
16867 free_lstval: | |
16868 while (curallocval > allocval) | |
16869 vim_free(*--curallocval); | |
16855 vim_free(lstval); | 16870 vim_free(lstval); |
16856 } | 16871 } |
16857 else | 16872 else |
16858 { | 16873 { |
16859 strval = get_tv_string_chk(&argvars[1]); | 16874 strval = get_tv_string_chk(&argvars[1]); |
20451 char_u *res = get_tv_string_buf_chk(varp, buf); | 20466 char_u *res = get_tv_string_buf_chk(varp, buf); |
20452 | 20467 |
20453 return res != NULL ? res : (char_u *)""; | 20468 return res != NULL ? res : (char_u *)""; |
20454 } | 20469 } |
20455 | 20470 |
20471 /* | |
20472 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! | |
20473 */ | |
20456 char_u * | 20474 char_u * |
20457 get_tv_string_chk(varp) | 20475 get_tv_string_chk(varp) |
20458 typval_T *varp; | 20476 typval_T *varp; |
20459 { | 20477 { |
20460 static char_u mybuf[NUMBUFLEN]; | 20478 static char_u mybuf[NUMBUFLEN]; |