comparison src/list.c @ 22545:47596deedfb5 v8.2.1821

patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work Commit: https://github.com/vim/vim/commit/1a73923705744ab8297dd856d194e20297563456 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 10 15:37:58 2020 +0200 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work Problem: Vim9: concatenating to a NULL list doesn't work. Solution: Handle a NULL list like an empty list. (closes https://github.com/vim/vim/issues/7064)
author Bram Moolenaar <Bram@vim.org>
date Sat, 10 Oct 2020 15:45:03 +0200
parents 4ce3906e5997
children f140b9036aa5
comparison
equal deleted inserted replaced
22544:beaa663bf63c 22545:47596deedfb5
822 && list_flatten(l, maxdepth) == OK) 822 && list_flatten(l, maxdepth) == OK)
823 copy_tv(&argvars[0], rettv); 823 copy_tv(&argvars[0], rettv);
824 } 824 }
825 825
826 /* 826 /*
827 * Extend "l1" with "l2". 827 * Extend "l1" with "l2". "l1" must not be NULL.
828 * If "bef" is NULL append at the end, otherwise insert before this item. 828 * If "bef" is NULL append at the end, otherwise insert before this item.
829 * Returns FAIL when out of memory. 829 * Returns FAIL when out of memory.
830 */ 830 */
831 int 831 int
832 list_extend(list_T *l1, list_T *l2, listitem_T *bef) 832 list_extend(list_T *l1, list_T *l2, listitem_T *bef)
833 { 833 {
834 listitem_T *item; 834 listitem_T *item;
835 int todo = l2->lv_len; 835 int todo;
836 836
837 // NULL list is equivalent to an empty list: nothing to do.
838 if (l2 == NULL || l2->lv_len == 0)
839 return OK;
840
841 todo = l2->lv_len;
837 CHECK_LIST_MATERIALIZE(l1); 842 CHECK_LIST_MATERIALIZE(l1);
838 CHECK_LIST_MATERIALIZE(l2); 843 CHECK_LIST_MATERIALIZE(l2);
839 844
840 // We also quit the loop when we have inserted the original item count of 845 // We also quit the loop when we have inserted the original item count of
841 // the list, avoid a hang when we extend a list with itself. 846 // the list, avoid a hang when we extend a list with itself.
852 int 857 int
853 list_concat(list_T *l1, list_T *l2, typval_T *tv) 858 list_concat(list_T *l1, list_T *l2, typval_T *tv)
854 { 859 {
855 list_T *l; 860 list_T *l;
856 861
857 if (l1 == NULL || l2 == NULL)
858 return FAIL;
859
860 // make a copy of the first list. 862 // make a copy of the first list.
861 l = list_copy(l1, FALSE, 0); 863 if (l1 == NULL)
864 l = list_alloc();
865 else
866 l = list_copy(l1, FALSE, 0);
862 if (l == NULL) 867 if (l == NULL)
863 return FAIL; 868 return FAIL;
864 tv->v_type = VAR_LIST; 869 tv->v_type = VAR_LIST;
865 tv->vval.v_list = l; 870 tv->vval.v_list = l;
871 if (l1 == NULL)
872 ++l->lv_refcount;
866 873
867 // append all items from the second list 874 // append all items from the second list
868 return list_extend(l, l2, NULL); 875 return list_extend(l, l2, NULL);
869 } 876 }
870 877