comparison src/list.c @ 11418:162bcd0debd7 v8.0.0593

patch 8.0.0593: duplication of code for adding a list or dict return value commit https://github.com/vim/vim/commit/45cf6e910c6d162775ca9d470fac4b6db844001f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 30 20:25:19 2017 +0200 patch 8.0.0593: duplication of code for adding a list or dict return value Problem: Duplication of code for adding a list or dict return value. Solution: Add rettv_dict_set() and rettv_list_set(). (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sun, 30 Apr 2017 20:30:04 +0200
parents 055b1633aed7
children aec3df2af27c
comparison
equal deleted inserted replaced
11417:47bfa931b0e7 11418:162bcd0debd7
95 list_T *l = list_alloc(); 95 list_T *l = list_alloc();
96 96
97 if (l == NULL) 97 if (l == NULL)
98 return FAIL; 98 return FAIL;
99 99
100 rettv->v_lock = 0;
101 rettv_list_set(rettv, l);
102 return OK;
103 }
104
105 /*
106 * Set a list as the return value
107 */
108 void
109 rettv_list_set(typval_T *rettv, list_T *l)
110 {
111 rettv->v_type = VAR_LIST;
100 rettv->vval.v_list = l; 112 rettv->vval.v_list = l;
101 rettv->v_type = VAR_LIST; 113 if (l != NULL)
102 rettv->v_lock = 0; 114 ++l->lv_refcount;
103 ++l->lv_refcount;
104 return OK;
105 } 115 }
106 116
107 /* 117 /*
108 * Unreference a list: decrement the reference count and free it when it 118 * Unreference a list: decrement the reference count and free it when it
109 * becomes zero. 119 * becomes zero.
873 return FAIL; 883 return FAIL;
874 } 884 }
875 885
876 *arg = skipwhite(*arg + 1); 886 *arg = skipwhite(*arg + 1);
877 if (evaluate) 887 if (evaluate)
878 { 888 rettv_list_set(rettv, l);
879 rettv->v_type = VAR_LIST;
880 rettv->vval.v_list = l;
881 ++l->lv_refcount;
882 }
883 889
884 return OK; 890 return OK;
885 } 891 }
886 892
887 /* 893 /*