mirror of
https://github.com/neovim/neovim.git
synced 2025-11-28 21:20:45 +00:00
eval: Move dict_set_keys_readonly to typval.c
This commit is contained in:
@@ -5605,19 +5605,6 @@ int dict_add_dict(dict_T *d, char *key, dict_T *dict)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set all existing keys in "dict" as read-only.
|
|
||||||
///
|
|
||||||
/// This does not protect against adding new keys to the Dictionary.
|
|
||||||
///
|
|
||||||
/// @param dict The dict whose keys should be frozen
|
|
||||||
void dict_set_keys_readonly(dict_T *const dict)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
|
||||||
{
|
|
||||||
TV_DICT_ITER(dict, di, {
|
|
||||||
di->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a variable for a Dictionary and fill it from "*arg".
|
* Allocate a variable for a Dictionary and fill it from "*arg".
|
||||||
* Return OK or FAIL. Returns NOTDONE for {expr}.
|
* Return OK or FAIL. Returns NOTDONE for {expr}.
|
||||||
@@ -18083,7 +18070,7 @@ void set_vim_var_dict(const VimVarIndex idx, dict_T *const val)
|
|||||||
if (val != NULL) {
|
if (val != NULL) {
|
||||||
val->dv_refcount++;
|
val->dv_refcount++;
|
||||||
// Set readonly
|
// Set readonly
|
||||||
dict_set_keys_readonly(val);
|
tv_dict_set_keys_readonly(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1135,8 +1135,8 @@ const char *tv_dict_get_string_buf(dict_T *const d, const char *const key,
|
|||||||
/// @param[in] d Dictionary to get callback from.
|
/// @param[in] d Dictionary to get callback from.
|
||||||
/// @param[in] key Dictionary key.
|
/// @param[in] key Dictionary key.
|
||||||
/// @param[in] key_len Key length, may be -1 to use strlen().
|
/// @param[in] key_len Key length, may be -1 to use strlen().
|
||||||
/// @param[out] result The address where a pointer to the wanted callback
|
/// @param[out] result The address where a pointer to the wanted callback
|
||||||
/// will be left.
|
/// will be left.
|
||||||
///
|
///
|
||||||
/// @return true/false on success/failure.
|
/// @return true/false on success/failure.
|
||||||
bool tv_dict_get_callback(dict_T *const d,
|
bool tv_dict_get_callback(dict_T *const d,
|
||||||
@@ -1348,6 +1348,19 @@ dict_T *tv_dict_copy(const vimconv_T *const conv,
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set all existing keys in "dict" as read-only.
|
||||||
|
///
|
||||||
|
/// This does not protect against adding new keys to the Dictionary.
|
||||||
|
///
|
||||||
|
/// @param dict The dict whose keys should be frozen.
|
||||||
|
void tv_dict_set_keys_readonly(dict_T *const dict)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
TV_DICT_ITER(dict, di, {
|
||||||
|
di->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//{{{1 Generic typval operations
|
//{{{1 Generic typval operations
|
||||||
//{{{2 Init/alloc/clear
|
//{{{2 Init/alloc/clear
|
||||||
//{{{3 Alloc
|
//{{{3 Alloc
|
||||||
|
|||||||
@@ -1551,7 +1551,7 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope)
|
|||||||
|
|
||||||
dict_add_nr_str(dict, "scope", 0L, (char_u *)buf);
|
dict_add_nr_str(dict, "scope", 0L, (char_u *)buf);
|
||||||
dict_add_nr_str(dict, "cwd", 0L, (char_u *)new_dir);
|
dict_add_nr_str(dict, "cwd", 0L, (char_u *)new_dir);
|
||||||
dict_set_keys_readonly(dict);
|
tv_dict_set_keys_readonly(dict);
|
||||||
|
|
||||||
apply_autocmds(EVENT_DIRCHANGED, (char_u *)buf, (char_u *)new_dir, false,
|
apply_autocmds(EVENT_DIRCHANGED, (char_u *)buf, (char_u *)new_dir, false,
|
||||||
NULL);
|
NULL);
|
||||||
|
|||||||
@@ -2578,7 +2578,7 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg)
|
|||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
dict_add_nr_str(dict, "operator", 0, (char_u *)buf);
|
dict_add_nr_str(dict, "operator", 0, (char_u *)buf);
|
||||||
|
|
||||||
dict_set_keys_readonly(dict);
|
tv_dict_set_keys_readonly(dict);
|
||||||
textlock++;
|
textlock++;
|
||||||
apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, false, curbuf);
|
||||||
textlock--;
|
textlock--;
|
||||||
|
|||||||
Reference in New Issue
Block a user