Call to rettv_list_alloc cannot fail.

Clean up the use of rettv_list_alloc and remove error checks.
This commit is contained in:
oni-link
2014-04-24 23:02:00 +02:00
committed by Thiago de Arruda
parent dc9b680deb
commit bee4f4f724

View File

@@ -464,7 +464,7 @@ static int get_option_tv(char_u **arg, typval_T *rettv, int evaluate);
static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate); static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate);
static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate); static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate);
static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate); static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate);
static int rettv_list_alloc(typval_T *rettv); static void rettv_list_alloc(typval_T *rettv);
static long list_len(list_T *l); static long list_len(list_T *l);
static int list_equal(list_T *l1, list_T *l2, int ic, int recursive); static int list_equal(list_T *l1, list_T *l2, int ic, int recursive);
static int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive); static int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive);
@@ -5136,19 +5136,13 @@ list_T *list_alloc(void)
/* /*
* Allocate an empty list for a return value. * Allocate an empty list for a return value.
* Returns OK or FAIL.
*/ */
static int rettv_list_alloc(typval_T *rettv) static void rettv_list_alloc(typval_T *rettv)
{ {
list_T *l = list_alloc(); list_T *l = list_alloc();
if (l == NULL)
return FAIL;
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 OK;
} }
/* /*
@@ -7628,10 +7622,12 @@ static void f_argv(typval_T *argvars, typval_T *rettv)
else else
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
} else if (rettv_list_alloc(rettv) == OK) } else {
for (idx = 0; idx < ARGCOUNT; ++idx) rettv_list_alloc(rettv);
list_append_string(rettv->vval.v_list, for (idx = 0; idx < ARGCOUNT; ++idx) {
alist_name(&ARGLIST[idx]), -1); list_append_string(rettv->vval.v_list, alist_name(&ARGLIST[idx]), -1);
}
}
} }
/* /*
@@ -8630,10 +8626,12 @@ static void f_expand(typval_T *argvars, typval_T *rettv)
result = eval_vars(s, s, &len, NULL, &errormsg, NULL); result = eval_vars(s, s, &len, NULL, &errormsg, NULL);
--emsg_off; --emsg_off;
if (rettv->v_type == VAR_LIST) { if (rettv->v_type == VAR_LIST) {
if (rettv_list_alloc(rettv) != FAIL && result != NULL) rettv_list_alloc(rettv);
if (result != NULL) {
list_append_string(rettv->vval.v_list, result, -1); list_append_string(rettv->vval.v_list, result, -1);
else } else {
vim_free(result); vim_free(result);
}
} else } else
rettv->vval.v_string = result; rettv->vval.v_string = result;
} else { } else {
@@ -8650,12 +8648,12 @@ static void f_expand(typval_T *argvars, typval_T *rettv)
if (rettv->v_type == VAR_STRING) if (rettv->v_type == VAR_STRING)
rettv->vval.v_string = ExpandOne(&xpc, s, NULL, rettv->vval.v_string = ExpandOne(&xpc, s, NULL,
options, WILD_ALL); options, WILD_ALL);
else if (rettv_list_alloc(rettv) != FAIL) { else {
int i; rettv_list_alloc(rettv);
ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP); ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP);
for (i = 0; i < xpc.xp_numfiles; i++) for (int i = 0; i < xpc.xp_numfiles; i++) {
list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
}
ExpandCleanup(&xpc); ExpandCleanup(&xpc);
} }
} else } else
@@ -8888,8 +8886,9 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)
} }
} }
if (count < 0 && rettv_list_alloc(rettv) == FAIL) if (count < 0) {
error = TRUE; rettv_list_alloc(rettv);
}
if (*fname != NUL && !error) { if (*fname != NUL && !error) {
do { do {
@@ -9400,8 +9399,9 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (retlist && rettv_list_alloc(rettv) == FAIL) if (retlist) {
return; rettv_list_alloc(rettv);
}
if (buf == NULL || buf->b_ml.ml_mfp == NULL || start < 0) if (buf == NULL || buf->b_ml.ml_mfp == NULL || start < 0)
return; return;
@@ -9824,14 +9824,11 @@ static void f_getline(typval_T *argvars, typval_T *rettv)
*/ */
static void f_getmatches(typval_T *argvars, typval_T *rettv) static void f_getmatches(typval_T *argvars, typval_T *rettv)
{ {
dict_T *dict;
matchitem_T *cur = curwin->w_match_head; matchitem_T *cur = curwin->w_match_head;
if (rettv_list_alloc(rettv) == OK) { rettv_list_alloc(rettv);
while (cur != NULL) { while (cur != NULL) {
dict = dict_alloc(); dict_T *dict = dict_alloc();
if (dict == NULL)
return;
dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id)); dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id));
dict_add_nr_str(dict, "pattern", 0L, cur->pattern); dict_add_nr_str(dict, "pattern", 0L, cur->pattern);
dict_add_nr_str(dict, "priority", (long)cur->priority, NULL); dict_add_nr_str(dict, "priority", (long)cur->priority, NULL);
@@ -9840,7 +9837,6 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv)
cur = cur->next; cur = cur->next;
} }
} }
}
/* /*
* "getpid()" function * "getpid()" function
@@ -9859,23 +9855,17 @@ static void f_getpos(typval_T *argvars, typval_T *rettv)
list_T *l; list_T *l;
int fnum = -1; int fnum = -1;
if (rettv_list_alloc(rettv) == OK) { rettv_list_alloc(rettv);
l = rettv->vval.v_list; l = rettv->vval.v_list;
fp = var2fpos(&argvars[0], TRUE, &fnum); fp = var2fpos(&argvars[0], TRUE, &fnum);
if (fnum != -1) list_append_number(l, (fnum != -1) ? (varnumber_T)fnum : (varnumber_T)0);
list_append_number(l, (varnumber_T)fnum); list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum : (varnumber_T)0);
else list_append_number(l,
list_append_number(l, (varnumber_T)0); (fp != NULL)
list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum
: (varnumber_T)0);
list_append_number(l, (fp != NULL)
? (varnumber_T)(fp->col == MAXCOL ? MAXCOL : fp->col + 1) ? (varnumber_T)(fp->col == MAXCOL ? MAXCOL : fp->col + 1)
: (varnumber_T)0); : (varnumber_T)0);
list_append_number(l, list_append_number(l,
(fp != NULL) ? (varnumber_T)fp->coladd : (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0);
(varnumber_T)0);
} else
rettv->vval.v_number = FALSE;
} }
/* /*
@@ -9883,18 +9873,15 @@ static void f_getpos(typval_T *argvars, typval_T *rettv)
*/ */
static void f_getqflist(typval_T *argvars, typval_T *rettv) static void f_getqflist(typval_T *argvars, typval_T *rettv)
{ {
win_T *wp; rettv_list_alloc(rettv);
win_T *wp = NULL;
if (rettv_list_alloc(rettv) == OK) {
wp = NULL;
if (argvars[0].v_type != VAR_UNKNOWN) { /* getloclist() */ if (argvars[0].v_type != VAR_UNKNOWN) { /* getloclist() */
wp = find_win_by_nr(&argvars[0], NULL); wp = find_win_by_nr(&argvars[0], NULL);
if (wp == NULL) if (wp == NULL) {
return; return;
} }
(void)get_errorlist(wp, rettv->vval.v_list);
} }
(void)get_errorlist(wp, rettv->vval.v_list);
} }
/* /*
@@ -10134,14 +10121,12 @@ static void f_glob(typval_T *argvars, typval_T *rettv)
if (rettv->v_type == VAR_STRING) if (rettv->v_type == VAR_STRING)
rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]), rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
NULL, options, WILD_ALL); NULL, options, WILD_ALL);
else if (rettv_list_alloc(rettv) != FAIL) { else {
int i; rettv_list_alloc(rettv);
ExpandOne(&xpc, get_tv_string(&argvars[0]), NULL, options, WILD_ALL_KEEP);
ExpandOne(&xpc, get_tv_string(&argvars[0]), for (int i = 0; i < xpc.xp_numfiles; i++) {
NULL, options, WILD_ALL_KEEP);
for (i = 0; i < xpc.xp_numfiles; i++)
list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
}
ExpandCleanup(&xpc); ExpandCleanup(&xpc);
} }
} else } else
@@ -10932,8 +10917,7 @@ static void dict_list(typval_T *argvars, typval_T *rettv, int what)
if ((d = argvars[0].vval.v_dict) == NULL) if ((d = argvars[0].vval.v_dict) == NULL)
return; return;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
todo = (int)d->dv_hashtab.ht_used; todo = (int)d->dv_hashtab.ht_used;
for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) { for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) {
@@ -11457,8 +11441,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
if (type == 3) { if (type == 3) {
/* return empty list when there are no matches */ /* return empty list when there are no matches */
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
goto theend;
} else if (type == 2) { } else if (type == 2) {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
@@ -11632,14 +11615,14 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv)
*/ */
static void f_matcharg(typval_T *argvars, typval_T *rettv) static void f_matcharg(typval_T *argvars, typval_T *rettv)
{ {
if (rettv_list_alloc(rettv) == OK) { rettv_list_alloc(rettv);
int id = get_tv_number(&argvars[0]); int id = get_tv_number(&argvars[0]);
matchitem_T *m; matchitem_T *m;
if (id >= 1 && id <= 3) { if (id >= 1 && id <= 3) {
if ((m = (matchitem_T *)get_match(curwin, id)) != NULL) { if ((m = (matchitem_T *)get_match(curwin, id)) != NULL) {
list_append_string(rettv->vval.v_list, list_append_string(rettv->vval.v_list, syn_id2name(m->hlg_id), -1);
syn_id2name(m->hlg_id), -1);
list_append_string(rettv->vval.v_list, m->pattern, -1); list_append_string(rettv->vval.v_list, m->pattern, -1);
} else { } else {
list_append_string(rettv->vval.v_list, NULL, -1); list_append_string(rettv->vval.v_list, NULL, -1);
@@ -11647,7 +11630,6 @@ static void f_matcharg(typval_T *argvars, typval_T *rettv)
} }
} }
} }
}
/* /*
* "matchdelete()" function * "matchdelete()" function
@@ -12042,7 +12024,7 @@ static void f_range(typval_T *argvars, typval_T *rettv)
else if (stride > 0 ? end + 1 < start : end - 1 > start) else if (stride > 0 ? end + 1 < start : end - 1 > start)
EMSG(_("E727: Start past end")); EMSG(_("E727: Start past end"));
else { else {
if (rettv_list_alloc(rettv) == OK) rettv_list_alloc(rettv);
for (i = start; stride > 0 ? i <= end : i >= end; i += stride) { for (i = start; stride > 0 ? i <= end : i >= end; i += stride) {
list_append_number(rettv->vval.v_list, (varnumber_T)i); list_append_number(rettv->vval.v_list, (varnumber_T)i);
} }
@@ -12076,8 +12058,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
maxline = get_tv_number(&argvars[2]); maxline = get_tv_number(&argvars[2]);
} }
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
/* Always open the file in binary mode, library functions have a mind of /* Always open the file in binary mode, library functions have a mind of
* their own about CR-LF conversion. */ * their own about CR-LF conversion. */
@@ -12282,16 +12263,12 @@ static void f_reltime(typval_T *argvars, typval_T *rettv)
return; return;
profile_sub(&res, &start); profile_sub(&res, &start);
} }
rettv_list_alloc(rettv);
if (rettv_list_alloc(rettv) == OK) { long n1 = res.tv_sec;
long n1, n2; long n2 = res.tv_usec;
n1 = res.tv_sec;
n2 = res.tv_usec;
list_append_number(rettv->vval.v_list, (varnumber_T)n1); list_append_number(rettv->vval.v_list, (varnumber_T)n1);
list_append_number(rettv->vval.v_list, (varnumber_T)n2); list_append_number(rettv->vval.v_list, (varnumber_T)n2);
} }
}
/* /*
* "reltimestr()" function * "reltimestr()" function
@@ -12414,7 +12391,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv)
EMSG(_(e_invrange)); EMSG(_(e_invrange));
else { else {
list_remove(l, item, item2); list_remove(l, item, item2);
if (rettv_list_alloc(rettv) == OK) { rettv_list_alloc(rettv);
l = rettv->vval.v_list; l = rettv->vval.v_list;
l->lv_first = item; l->lv_first = item;
l->lv_last = item2; l->lv_last = item2;
@@ -12427,7 +12404,6 @@ static void f_remove(typval_T *argvars, typval_T *rettv)
} }
} }
} }
}
/* /*
* "rename({from}, {to})" function * "rename({from}, {to})" function
@@ -12457,11 +12433,15 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
n = get_tv_number(&argvars[1]); n = get_tv_number(&argvars[1]);
if (argvars[0].v_type == VAR_LIST) { if (argvars[0].v_type == VAR_LIST) {
if (rettv_list_alloc(rettv) == OK && argvars[0].vval.v_list != NULL) rettv_list_alloc(rettv);
while (n-- > 0) if (argvars[0].vval.v_list != NULL) {
if (list_extend(rettv->vval.v_list, while (n-- > 0) {
argvars[0].vval.v_list, NULL) == FAIL) if (list_extend(rettv->vval.v_list, argvars[0].vval.v_list, NULL)
== FAIL) {
break; break;
}
}
}
} else { } else {
p = get_tv_string(&argvars[0]); p = get_tv_string(&argvars[0]);
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@@ -13044,8 +13024,7 @@ static void f_searchpairpos(typval_T *argvars, typval_T *rettv)
int lnum = 0; int lnum = 0;
int col = 0; int col = 0;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
if (searchpair_cmn(argvars, &match_pos) > 0) { if (searchpair_cmn(argvars, &match_pos) > 0) {
lnum = match_pos.lnum; lnum = match_pos.lnum;
@@ -13215,8 +13194,7 @@ static void f_searchpos(typval_T *argvars, typval_T *rettv)
int n; int n;
int flags = 0; int flags = 0;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
n = search_cmn(argvars, &match_pos, &flags); n = search_cmn(argvars, &match_pos, &flags);
if (n > 0) { if (n > 0) {
@@ -13974,8 +13952,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv)
hlf_T attr = HLF_COUNT; hlf_T attr = HLF_COUNT;
int len = 0; int len = 0;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
if (argvars[0].v_type == VAR_UNKNOWN) { if (argvars[0].v_type == VAR_UNKNOWN) {
/* Find the start and length of the badly spelled word. */ /* Find the start and length of the badly spelled word. */
@@ -14021,8 +13998,7 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv)
listitem_T *li; listitem_T *li;
int need_capital = FALSE; int need_capital = FALSE;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) { if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {
str = get_tv_string(&argvars[0]); str = get_tv_string(&argvars[0]);
@@ -14085,8 +14061,8 @@ static void f_split(typval_T *argvars, typval_T *rettv)
if (pat == NULL || *pat == NUL) if (pat == NULL || *pat == NUL)
pat = (char_u *)"[\\x01- ]\\+"; pat = (char_u *)"[\\x01- ]\\+";
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
if (typeerr) if (typeerr)
return; return;
@@ -14605,10 +14581,9 @@ static void f_synconcealed(typval_T *argvars, typval_T *rettv)
memset(str, NUL, sizeof(str)); memset(str, NUL, sizeof(str));
if (rettv_list_alloc(rettv) != FAIL) { rettv_list_alloc(rettv);
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count && col >= 0
&& col >= 0 && col <= (long)STRLEN(ml_get(lnum)) && col <= (long)STRLEN(ml_get(lnum)) && curwin->w_p_cole > 0) {
&& curwin->w_p_cole > 0) {
(void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE);
syntax_flags = get_syntax_info(&matchid); syntax_flags = get_syntax_info(&matchid);
@@ -14626,13 +14601,11 @@ static void f_synconcealed(typval_T *argvars, typval_T *rettv)
} }
} }
list_append_number(rettv->vval.v_list, list_append_number(rettv->vval.v_list, (syntax_flags & HL_CONCEAL) != 0);
(syntax_flags & HL_CONCEAL) != 0);
/* -1 to auto-determine strlen */ /* -1 to auto-determine strlen */
list_append_string(rettv->vval.v_list, str, -1); list_append_string(rettv->vval.v_list, str, -1);
list_append_number(rettv->vval.v_list, matchid); list_append_number(rettv->vval.v_list, matchid);
} }
}
/* /*
* "synstack(lnum, col)" function * "synstack(lnum, col)" function
@@ -14648,9 +14621,11 @@ static void f_synstack(typval_T *argvars, typval_T *rettv)
lnum = get_tv_lnum(argvars); /* -1 on type error */ lnum = get_tv_lnum(argvars); /* -1 on type error */
col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */ col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count if (lnum >= 1
&& col >= 0 && col <= (long)STRLEN(ml_get(lnum)) && lnum <= curbuf->b_ml.ml_line_count
&& rettv_list_alloc(rettv) != FAIL) { && col >= 0
&& col <= (long)STRLEN(ml_get(lnum))) {
rettv_list_alloc(rettv);
(void)syn_get_id(curwin, lnum, (colnr_T)col, FALSE, NULL, TRUE); (void)syn_get_id(curwin, lnum, (colnr_T)col, FALSE, NULL, TRUE);
int id; int id;
@@ -14760,9 +14735,11 @@ static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv)
if (tp != NULL) if (tp != NULL)
wp = (tp == curtab) ? firstwin : tp->tp_firstwin; wp = (tp == curtab) ? firstwin : tp->tp_firstwin;
} }
if (wp != NULL && rettv_list_alloc(rettv) != FAIL) { if (wp != NULL) {
for (; wp != NULL; wp = wp->w_next) { rettv_list_alloc(rettv);
while (wp != NULL) {
list_append_number(rettv->vval.v_list, wp->w_buffer->b_fnum); list_append_number(rettv->vval.v_list, wp->w_buffer->b_fnum);
wp = wp->w_next;
} }
} }
} }
@@ -14858,11 +14835,8 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
char_u *fname; char_u *fname;
tagname_T tn; tagname_T tn;
if (rettv_list_alloc(rettv) == FAIL) rettv_list_alloc(rettv);
return;
fname = alloc(MAXPATHL); fname = alloc(MAXPATHL);
if (fname == NULL)
return;
int first = TRUE; int first = TRUE;
while (get_tagfname(&tn, first, fname) == OK) { while (get_tagfname(&tn, first, fname) == OK) {
@@ -14887,7 +14861,7 @@ static void f_taglist(typval_T *argvars, typval_T *rettv)
if (*tag_pattern == NUL) if (*tag_pattern == NUL)
return; return;
if (rettv_list_alloc(rettv) == OK) rettv_list_alloc(rettv);
(void)get_tags(rettv->vval.v_list, tag_pattern); (void)get_tags(rettv->vval.v_list, tag_pattern);
} }