Return list from rettv_list_alloc.

This commit is contained in:
Scott Prager
2014-09-05 16:38:36 -04:00
parent 566ce93135
commit 78979427d1

View File

@@ -4686,12 +4686,13 @@ list_T *list_alloc(void) FUNC_ATTR_NONNULL_RET
/* /*
* Allocate an empty list for a return value. * Allocate an empty list for a return value.
*/ */
static void rettv_list_alloc(typval_T *rettv) static list_T *rettv_list_alloc(typval_T *rettv)
{ {
list_T *l = list_alloc(); list_T *l = list_alloc();
rettv->vval.v_list = l; rettv->vval.v_list = l;
rettv->v_type = VAR_LIST; rettv->v_type = VAR_LIST;
++l->lv_refcount; ++l->lv_refcount;
return l;
} }
/* /*
@@ -9408,16 +9409,15 @@ static void f_getpid(typval_T *argvars, typval_T *rettv)
static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos) static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos)
{ {
pos_T *fp; pos_T *fp;
list_T *l;
int fnum = -1; int fnum = -1;
rettv_list_alloc(rettv);
l = rettv->vval.v_list;
if (getcurpos) { if (getcurpos) {
fp = &curwin->w_cursor; fp = &curwin->w_cursor;
} else { } else {
fp = var2fpos(&argvars[0], true, &fnum); fp = var2fpos(&argvars[0], true, &fnum);
} }
list_T *l = rettv_list_alloc(rettv);
list_append_number(l, (fnum != -1) ? (varnumber_T)fnum : (varnumber_T)0); list_append_number(l, (fnum != -1) ? (varnumber_T)fnum : (varnumber_T)0);
list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum : (varnumber_T)0); list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum : (varnumber_T)0);
list_append_number(l, list_append_number(l,
@@ -12010,8 +12010,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv)
EMSG(_(e_invrange)); EMSG(_(e_invrange));
else { else {
vim_list_remove(l, item, item2); vim_list_remove(l, item, item2);
rettv_list_alloc(rettv); l = rettv_list_alloc(rettv);
l = rettv->vval.v_list;
l->lv_first = item; l->lv_first = item;
l->lv_last = item2; l->lv_last = item2;
item->li_prev = NULL; item->li_prev = NULL;
@@ -14656,8 +14655,7 @@ static void f_taglist(typval_T *argvars, typval_T *rettv)
if (*tag_pattern == NUL) if (*tag_pattern == NUL)
return; return;
rettv_list_alloc(rettv); (void)get_tags(rettv_list_alloc(rettv), tag_pattern);
(void)get_tags(rettv->vval.v_list, tag_pattern);
} }
/* /*