Merge pull request #5232 from bfredl/dictchar_u

eval: remove char_u in  get_dict_(string|number) key parameters
This commit is contained in:
Björn Linse 2016-08-25 19:16:03 +02:00 committed by GitHub
commit 41a64586c7
3 changed files with 60 additions and 65 deletions

View File

@ -3530,21 +3530,15 @@ int ins_compl_add_tv(typval_T *tv, int dir)
char_u *(cptext[CPT_COUNT]); char_u *(cptext[CPT_COUNT]);
if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) { if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) {
word = get_dict_string(tv->vval.v_dict, (char_u *)"word", FALSE); word = get_dict_string(tv->vval.v_dict, "word", false);
cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict, cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict, "abbr", false);
(char_u *)"abbr", FALSE); cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict, "menu", false);
cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict, cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict, "kind", false);
(char_u *)"menu", FALSE); cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict, "info", false);
cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict,
(char_u *)"kind", FALSE); icase = get_dict_number(tv->vval.v_dict, "icase");
cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict, adup = get_dict_number(tv->vval.v_dict, "dup");
(char_u *)"info", FALSE); aempty = get_dict_number(tv->vval.v_dict, "empty");
if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL)
icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase");
if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL)
adup = get_dict_number(tv->vval.v_dict, (char_u *)"dup");
if (get_dict_string(tv->vval.v_dict, (char_u *)"empty", FALSE) != NULL)
aempty = get_dict_number(tv->vval.v_dict, (char_u *)"empty");
} else { } else {
word = get_tv_string_chk(tv); word = get_tv_string_chk(tv);
memset(cptext, 0, sizeof(cptext)); memset(cptext, 0, sizeof(cptext));

View File

@ -6482,19 +6482,20 @@ static ufunc_T *find_ufunc(uint8_t *name)
return rv; return rv;
} }
/* /// Get a string item from a dictionary.
* Get a string item from a dictionary. ///
* When "save" is TRUE allocate memory for it. /// @param save whether memory should be allocated for the return value
* Returns NULL if the entry doesn't exist. ///
*/ /// @return the entry or NULL if the entry doesn't exist.
char_u *get_dict_string(dict_T *d, char_u *key, int save) char_u *get_dict_string(dict_T *d, char *key, bool save)
{ {
dictitem_T *di; dictitem_T *di;
char_u *s; char_u *s;
di = dict_find(d, key, -1); di = dict_find(d, (char_u *)key, -1);
if (di == NULL) if (di == NULL) {
return NULL; return NULL;
}
s = get_tv_string(&di->di_tv); s = get_tv_string(&di->di_tv);
if (save) { if (save) {
s = vim_strsave(s); s = vim_strsave(s);
@ -6502,15 +6503,15 @@ char_u *get_dict_string(dict_T *d, char_u *key, int save)
return s; return s;
} }
/* /// Get a number item from a dictionary.
* Get a number item from a dictionary. ///
* Returns 0 if the entry doesn't exist. /// @return the entry or 0 if the entry doesn't exist.
*/ long get_dict_number(dict_T *d, char *key)
long get_dict_number(dict_T *d, char_u *key)
{ {
dictitem_T *di = dict_find(d, key, -1); dictitem_T *di = dict_find(d, (char_u *)key, -1);
if (di == NULL) if (di == NULL) {
return 0; return 0;
}
return get_tv_number(&di->di_tv); return get_tv_number(&di->di_tv);
} }
@ -11943,16 +11944,16 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type == VAR_DICT) { if (argvars[1].v_type == VAR_DICT) {
job_opts = argvars[1].vval.v_dict; job_opts = argvars[1].vval.v_dict;
detach = get_dict_number(job_opts, (uint8_t *)"detach") != 0; detach = get_dict_number(job_opts, "detach") != 0;
rpc = get_dict_number(job_opts, (uint8_t *)"rpc") != 0; rpc = get_dict_number(job_opts, "rpc") != 0;
pty = get_dict_number(job_opts, (uint8_t *)"pty") != 0; pty = get_dict_number(job_opts, "pty") != 0;
if (pty && rpc) { if (pty && rpc) {
EMSG2(_(e_invarg2), "job cannot have both 'pty' and 'rpc' options set"); EMSG2(_(e_invarg2), "job cannot have both 'pty' and 'rpc' options set");
shell_free_argv(argv); shell_free_argv(argv);
return; return;
} }
char *new_cwd = (char *)get_dict_string(job_opts, (char_u *)"cwd", false); char *new_cwd = (char *)get_dict_string(job_opts, "cwd", false);
if (new_cwd && strlen(new_cwd) > 0) { if (new_cwd && strlen(new_cwd) > 0) {
cwd = new_cwd; cwd = new_cwd;
// The new cwd must be a directory. // The new cwd must be a directory.
@ -11974,15 +11975,15 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv)
Process *proc = (Process *)&data->proc; Process *proc = (Process *)&data->proc;
if (pty) { if (pty) {
uint16_t width = get_dict_number(job_opts, (uint8_t *)"width"); uint16_t width = get_dict_number(job_opts, "width");
if (width > 0) { if (width > 0) {
data->proc.pty.width = width; data->proc.pty.width = width;
} }
uint16_t height = get_dict_number(job_opts, (uint8_t *)"height"); uint16_t height = get_dict_number(job_opts, "height");
if (height > 0) { if (height > 0) {
data->proc.pty.height = height; data->proc.pty.height = height;
} }
char *term = (char *)get_dict_string(job_opts, (uint8_t *)"TERM", true); char *term = (char *)get_dict_string(job_opts, "TERM", true);
if (term) { if (term) {
data->proc.pty.term_name = term; data->proc.pty.term_name = term;
} }
@ -12677,7 +12678,7 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv)
if (dict_find(argvars[4].vval.v_dict, if (dict_find(argvars[4].vval.v_dict,
(char_u *)"conceal", -1) != NULL) { (char_u *)"conceal", -1) != NULL) {
conceal_char = get_dict_string(argvars[4].vval.v_dict, conceal_char = get_dict_string(argvars[4].vval.v_dict,
(char_u *)"conceal", false); "conceal", false);
} }
} }
} }
@ -12733,7 +12734,7 @@ static void f_matchaddpos(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_
if (dict_find(argvars[4].vval.v_dict, if (dict_find(argvars[4].vval.v_dict,
(char_u *)"conceal", -1) != NULL) { (char_u *)"conceal", -1) != NULL) {
conceal_char = get_dict_string(argvars[4].vval.v_dict, conceal_char = get_dict_string(argvars[4].vval.v_dict,
(char_u *)"conceal", false); "conceal", false);
} }
} }
} }
@ -14697,7 +14698,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv)
} }
if ((d = argvars[0].vval.v_dict) != NULL) { if ((d = argvars[0].vval.v_dict) != NULL) {
csearch = get_dict_string(d, (char_u *)"char", FALSE); csearch = get_dict_string(d, "char", false);
if (csearch != NULL) { if (csearch != NULL) {
if (enc_utf8) { if (enc_utf8) {
int pcc[MAX_MCO]; int pcc[MAX_MCO];
@ -14971,16 +14972,16 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv)
} }
} }
char_u *group = get_dict_string(d, (char_u *)"group", false); char_u *group = get_dict_string(d, "group", false);
int priority = get_dict_number(d, (char_u *)"priority"); int priority = get_dict_number(d, "priority");
int id = get_dict_number(d, (char_u *)"id"); int id = get_dict_number(d, "id");
char_u *conceal = dict_find(d, (char_u *)"conceal", -1) != NULL char_u *conceal = dict_find(d, (char_u *)"conceal", -1) != NULL
? get_dict_string(d, (char_u *)"conceal", ? get_dict_string(d, "conceal",
false) false)
: NULL; : NULL;
if (i == 0) { if (i == 0) {
match_add(curwin, group, match_add(curwin, group,
get_dict_string(d, (char_u *)"pattern", false), get_dict_string(d, "pattern", false),
priority, id, NULL, conceal); priority, id, NULL, conceal);
} else { } else {
match_add(curwin, group, NULL, priority, id, s, conceal); match_add(curwin, group, NULL, priority, id, s, conceal);
@ -16687,7 +16688,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type == VAR_DICT) { if (argvars[1].v_type == VAR_DICT) {
job_opts = argvars[1].vval.v_dict; job_opts = argvars[1].vval.v_dict;
char *new_cwd = (char *)get_dict_string(job_opts, (char_u *)"cwd", false); char *new_cwd = (char *)get_dict_string(job_opts, "cwd", false);
if (new_cwd && strlen(new_cwd) > 0) { if (new_cwd && strlen(new_cwd) > 0) {
cwd = new_cwd; cwd = new_cwd;
// The new cwd must be a directory. // The new cwd must be a directory.
@ -16785,7 +16786,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv)
return; return;
} }
if (dict_find(dict, (char_u *)"repeat", -1) != NULL) { if (dict_find(dict, (char_u *)"repeat", -1) != NULL) {
repeat = get_dict_number(dict, (char_u *)"repeat"); repeat = get_dict_number(dict, "repeat");
if (repeat == 0) { if (repeat == 0) {
repeat = 1; repeat = 1;
} }
@ -17311,29 +17312,29 @@ static void f_winrestview(typval_T *argvars, typval_T *rettv)
EMSG(_(e_invarg)); EMSG(_(e_invarg));
else { else {
if (dict_find(dict, (char_u *)"lnum", -1) != NULL) { if (dict_find(dict, (char_u *)"lnum", -1) != NULL) {
curwin->w_cursor.lnum = get_dict_number(dict, (char_u *)"lnum"); curwin->w_cursor.lnum = get_dict_number(dict, "lnum");
} }
if (dict_find(dict, (char_u *)"col", -1) != NULL) { if (dict_find(dict, (char_u *)"col", -1) != NULL) {
curwin->w_cursor.col = get_dict_number(dict, (char_u *)"col"); curwin->w_cursor.col = get_dict_number(dict, "col");
} }
if (dict_find(dict, (char_u *)"coladd", -1) != NULL) { if (dict_find(dict, (char_u *)"coladd", -1) != NULL) {
curwin->w_cursor.coladd = get_dict_number(dict, (char_u *)"coladd"); curwin->w_cursor.coladd = get_dict_number(dict, "coladd");
} }
if (dict_find(dict, (char_u *)"curswant", -1) != NULL) { if (dict_find(dict, (char_u *)"curswant", -1) != NULL) {
curwin->w_curswant = get_dict_number(dict, (char_u *)"curswant"); curwin->w_curswant = get_dict_number(dict, "curswant");
curwin->w_set_curswant = FALSE; curwin->w_set_curswant = false;
} }
if (dict_find(dict, (char_u *)"topline", -1) != NULL) { if (dict_find(dict, (char_u *)"topline", -1) != NULL) {
set_topline(curwin, get_dict_number(dict, (char_u *)"topline")); set_topline(curwin, get_dict_number(dict, "topline"));
} }
if (dict_find(dict, (char_u *)"topfill", -1) != NULL) { if (dict_find(dict, (char_u *)"topfill", -1) != NULL) {
curwin->w_topfill = get_dict_number(dict, (char_u *)"topfill"); curwin->w_topfill = get_dict_number(dict, "topfill");
} }
if (dict_find(dict, (char_u *)"leftcol", -1) != NULL) { if (dict_find(dict, (char_u *)"leftcol", -1) != NULL) {
curwin->w_leftcol = get_dict_number(dict, (char_u *)"leftcol"); curwin->w_leftcol = get_dict_number(dict, "leftcol");
} }
if (dict_find(dict, (char_u *)"skipcol", -1) != NULL) { if (dict_find(dict, (char_u *)"skipcol", -1) != NULL) {
curwin->w_skipcol = get_dict_number(dict, (char_u *)"skipcol"); curwin->w_skipcol = get_dict_number(dict, "skipcol");
} }
check_cursor(); check_cursor();

View File

@ -3505,15 +3505,15 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
if (d == NULL) if (d == NULL)
continue; continue;
char_u *filename = get_dict_string(d, (char_u *)"filename", true); char_u *filename = get_dict_string(d, "filename", true);
int bufnum = (int)get_dict_number(d, (char_u *)"bufnr"); int bufnum = (int)get_dict_number(d, "bufnr");
long lnum = get_dict_number(d, (char_u *)"lnum"); long lnum = get_dict_number(d, "lnum");
int col = (int)get_dict_number(d, (char_u *)"col"); int col = (int)get_dict_number(d, "col");
char_u vcol = (char_u)get_dict_number(d, (char_u *)"vcol"); char_u vcol = (char_u)get_dict_number(d, "vcol");
int nr = (int)get_dict_number(d, (char_u *)"nr"); int nr = (int)get_dict_number(d, "nr");
char_u *type = get_dict_string(d, (char_u *)"type", true); char_u *type = get_dict_string(d, "type", true);
char_u *pattern = get_dict_string(d, (char_u *)"pattern", true); char_u *pattern = get_dict_string(d, "pattern", true);
char_u *text = get_dict_string(d, (char_u *)"text", true); char_u *text = get_dict_string(d, "text", true);
if (text == NULL) { if (text == NULL) {
text = vim_strsave((char_u *)""); text = vim_strsave((char_u *)"");
} }