api: Rename dict_set_value to dict_set_var

Reasonings:
1. It is not used for anything, but scope dictionaries currenly. So there is no 
   need to generalize and split it into dict_set_var (which will contain some 
   scope-dictionary-specific checks) and dict_set_value (which will work for any 
   dictionary).
2. Check for key size is no longer valid for non-scope dictionaries: you *can* 
   use empty keys there. In scope dictionaries also, but you actually are not 
   supposed to store there anything, but variables.

Note that actually one may still do

    let b:[''] = 1

and “bypass” check for variable name. It won’t change what `echo b:` will show, 
but it may affect code which iterates over scope dictionary keys and sets them 
to something (if there is such code).
This commit is contained in:
ZyX 2017-02-23 01:27:45 +03:00
parent 6550caee50
commit 8faa4af396
7 changed files with 31 additions and 31 deletions

View File

@ -456,7 +456,7 @@ void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err)
return; return;
} }
dict_set_value(buf->b_vars, name, value, false, false, err); dict_set_var(buf->b_vars, name, value, false, false, err);
} }
/// Removes a buffer-scoped (b:) variable /// Removes a buffer-scoped (b:) variable
@ -472,7 +472,7 @@ void nvim_buf_del_var(Buffer buffer, String name, Error *err)
return; return;
} }
dict_set_value(buf->b_vars, name, NIL, true, false, err); dict_set_var(buf->b_vars, name, NIL, true, false, err);
} }
/// Sets a buffer-scoped (b:) variable /// Sets a buffer-scoped (b:) variable
@ -495,7 +495,7 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(buf->b_vars, name, value, false, true, err); return dict_set_var(buf->b_vars, name, value, false, true, err);
} }
/// Removes a buffer-scoped (b:) variable /// Removes a buffer-scoped (b:) variable
@ -514,7 +514,7 @@ Object buffer_del_var(Buffer buffer, String name, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(buf->b_vars, name, NIL, true, true, err); return dict_set_var(buf->b_vars, name, NIL, true, true, err);
} }

View File

@ -98,7 +98,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
return vim_to_object(&di->di_tv); return vim_to_object(&di->di_tv);
} }
/// Set a value in a dict. Objects are recursively expanded into their /// Set a value in a scope dict. Objects are recursively expanded into their
/// vimscript equivalents. /// vimscript equivalents.
/// ///
/// @param dict The vimscript dict /// @param dict The vimscript dict
@ -109,8 +109,8 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
/// @param retval If true the old value will be converted and returned. /// @param retval If true the old value will be converted and returned.
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
/// @return The old value if `retval` is true and the key was present, else NIL /// @return The old value if `retval` is true and the key was present, else NIL
Object dict_set_value(dict_T *dict, String key, Object value, bool del, Object dict_set_var(dict_T *dict, String key, Object value, bool del,
bool retval, Error *err) bool retval, Error *err)
{ {
Object rv = OBJECT_INIT; Object rv = OBJECT_INIT;
@ -120,7 +120,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
} }
if (key.size == 0) { if (key.size == 0) {
api_set_error(err, Validation, _("Empty dictionary keys aren't allowed")); api_set_error(err, Validation, _("Empty variable names aren't allowed"));
return rv; return rv;
} }
@ -129,7 +129,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
return rv; return rv;
} }
dictitem_T *di = dict_find(dict, (uint8_t *)key.data, (int)key.size); dictitem_T *di = dict_find(dict, (char_u *)key.data, (int)key.size);
if (del) { if (del) {
// Delete the key // Delete the key

View File

@ -71,7 +71,7 @@ void nvim_tabpage_set_var(Tabpage tabpage,
return; return;
} }
dict_set_value(tab->tp_vars, name, value, false, false, err); dict_set_var(tab->tp_vars, name, value, false, false, err);
} }
/// Removes a tab-scoped (t:) variable /// Removes a tab-scoped (t:) variable
@ -87,7 +87,7 @@ void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
return; return;
} }
dict_set_value(tab->tp_vars, name, NIL, true, false, err); dict_set_var(tab->tp_vars, name, NIL, true, false, err);
} }
/// Sets a tab-scoped (t:) variable /// Sets a tab-scoped (t:) variable
@ -110,7 +110,7 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(tab->tp_vars, name, value, false, true, err); return dict_set_var(tab->tp_vars, name, value, false, true, err);
} }
/// Removes a tab-scoped (t:) variable /// Removes a tab-scoped (t:) variable
@ -129,7 +129,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(tab->tp_vars, name, NIL, true, true, err); return dict_set_var(tab->tp_vars, name, NIL, true, true, err);
} }
/// Gets the current window in a tabpage /// Gets the current window in a tabpage

View File

@ -368,7 +368,7 @@ Object nvim_get_var(String name, Error *err)
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
void nvim_set_var(String name, Object value, Error *err) void nvim_set_var(String name, Object value, Error *err)
{ {
dict_set_value(&globvardict, name, value, false, false, err); dict_set_var(&globvardict, name, value, false, false, err);
} }
/// Removes a global (g:) variable /// Removes a global (g:) variable
@ -377,7 +377,7 @@ void nvim_set_var(String name, Object value, Error *err)
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
void nvim_del_var(String name, Error *err) void nvim_del_var(String name, Error *err)
{ {
dict_set_value(&globvardict, name, NIL, true, false, err); dict_set_var(&globvardict, name, NIL, true, false, err);
} }
/// Sets a global variable /// Sets a global variable
@ -393,7 +393,7 @@ void nvim_del_var(String name, Error *err)
/// or if previous value was `v:null`. /// or if previous value was `v:null`.
Object vim_set_var(String name, Object value, Error *err) Object vim_set_var(String name, Object value, Error *err)
{ {
return dict_set_value(&globvardict, name, value, false, true, err); return dict_set_var(&globvardict, name, value, false, true, err);
} }
/// Removes a global variable /// Removes a global variable
@ -405,7 +405,7 @@ Object vim_set_var(String name, Object value, Error *err)
/// @return Old value /// @return Old value
Object vim_del_var(String name, Error *err) Object vim_del_var(String name, Error *err)
{ {
return dict_set_value(&globvardict, name, NIL, true, true, err); return dict_set_var(&globvardict, name, NIL, true, true, err);
} }
/// Gets a v: variable /// Gets a v: variable

View File

@ -210,7 +210,7 @@ void nvim_win_set_var(Window window, String name, Object value, Error *err)
return; return;
} }
dict_set_value(win->w_vars, name, value, false, false, err); dict_set_var(win->w_vars, name, value, false, false, err);
} }
/// Removes a window-scoped (w:) variable /// Removes a window-scoped (w:) variable
@ -226,7 +226,7 @@ void nvim_win_del_var(Window window, String name, Error *err)
return; return;
} }
dict_set_value(win->w_vars, name, NIL, true, false, err); dict_set_var(win->w_vars, name, NIL, true, false, err);
} }
/// Sets a window-scoped (w:) variable /// Sets a window-scoped (w:) variable
@ -249,7 +249,7 @@ Object window_set_var(Window window, String name, Object value, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(win->w_vars, name, value, false, true, err); return dict_set_var(win->w_vars, name, value, false, true, err);
} }
/// Removes a window-scoped (w:) variable /// Removes a window-scoped (w:) variable
@ -268,7 +268,7 @@ Object window_del_var(Window window, String name, Error *err)
return (Object) OBJECT_INIT; return (Object) OBJECT_INIT;
} }
return dict_set_value(win->w_vars, name, NIL, true, true, err); return dict_set_var(win->w_vars, name, NIL, true, true, err);
} }
/// Gets a window option value /// Gets a window option value

View File

@ -17731,10 +17731,10 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
(void)setfname(curbuf, (uint8_t *)buf, NULL, true); (void)setfname(curbuf, (uint8_t *)buf, NULL, true);
// Save the job id and pid in b:terminal_job_{id,pid} // Save the job id and pid in b:terminal_job_{id,pid}
Error err; Error err;
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_id"), dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_id"),
INTEGER_OBJ(rettv->vval.v_number), false, false, &err); INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_pid"), dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
INTEGER_OBJ(pid), false, false, &err); INTEGER_OBJ(pid), false, false, &err);
Terminal *term = terminal_open(topts); Terminal *term = terminal_open(topts);
data->term = term; data->term = term;

View File

@ -623,12 +623,12 @@ static void buf_set_term_title(buf_T *buf, char *title)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
Error err; Error err;
dict_set_value(buf->b_vars, dict_set_var(buf->b_vars,
cstr_as_string("term_title"), STATIC_CSTR_AS_STRING("term_title"),
STRING_OBJ(cstr_as_string(title)), STRING_OBJ(cstr_as_string(title)),
false, false,
false, false,
&err); &err);
} }
static int term_settermprop(VTermProp prop, VTermValue *val, void *data) static int term_settermprop(VTermProp prop, VTermValue *val, void *data)