eval: Split and move dict_add_nr_str to typval.c

Function was split into tv_dict_add_nr() and tv_dict_add_str().
This commit is contained in:
ZyX
2016-08-20 23:56:49 +03:00
parent 210342d795
commit 2dcfc439b2
11 changed files with 201 additions and 154 deletions

View File

@@ -4034,16 +4034,20 @@ static void ins_compl_insert(int in_compl_func)
// Set completed item. // Set completed item.
// { word, abbr, menu, kind, info } // { word, abbr, menu, kind, info }
dict_T *dict = tv_dict_alloc(); dict_T *dict = tv_dict_alloc();
dict_add_nr_str(dict, "word", 0L, tv_dict_add_str(dict, S_LEN("word"),
EMPTY_IF_NULL(compl_shown_match->cp_str)); (const char *)EMPTY_IF_NULL(compl_shown_match->cp_str));
dict_add_nr_str(dict, "abbr", 0L, tv_dict_add_str(
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_ABBR])); dict, S_LEN("abbr"),
dict_add_nr_str(dict, "menu", 0L, (const char *)EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_ABBR]));
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_MENU])); tv_dict_add_str(
dict_add_nr_str(dict, "kind", 0L, dict, S_LEN("menu"),
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_KIND])); (const char *)EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_MENU]));
dict_add_nr_str(dict, "info", 0L, tv_dict_add_str(
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO])); dict, S_LEN("kind"),
(const char *)EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_KIND]));
tv_dict_add_str(
dict, S_LEN("info"),
(const char *)EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO]));
set_vim_var_dict(VV_COMPLETED_ITEM, dict); set_vim_var_dict(VV_COMPLETED_ITEM, dict);
if (!in_compl_func) { if (!in_compl_func) {
compl_curr_match = compl_shown_match; compl_curr_match = compl_shown_match;

View File

@@ -5544,31 +5544,6 @@ static bool set_ref_in_funccal(funccall_T *fc, int copyID)
return abort; return abort;
} }
/*
* Add a number or string entry to dictionary "d".
* When "str" is NULL use number "nr", otherwise use "str".
* Returns FAIL when key already exists.
*/
int dict_add_nr_str(dict_T *d, char *key, long nr, char_u *str)
{
dictitem_T *item;
item = tv_dict_item_alloc(key);
item->di_tv.v_lock = 0;
if (str == NULL) {
item->di_tv.v_type = VAR_NUMBER;
item->di_tv.vval.v_number = nr;
} else {
item->di_tv.v_type = VAR_STRING;
item->di_tv.vval.v_string = vim_strsave(str);
}
if (tv_dict_add(d, item) == FAIL) {
tv_dict_item_free(item);
return FAIL;
}
return OK;
}
/* /*
* 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}.
@@ -9066,9 +9041,10 @@ static void get_buffer_signs(buf_T *buf, list_T *l)
for (signlist_T *sign = buf->b_signlist; sign; sign = sign->next) { for (signlist_T *sign = buf->b_signlist; sign; sign = sign->next) {
dict_T *const d = tv_dict_alloc(); dict_T *const d = tv_dict_alloc();
dict_add_nr_str(d, "id", sign->id, NULL); tv_dict_add_nr(d, S_LEN("id"), sign->id);
dict_add_nr_str(d, "lnum", sign->lnum, NULL); tv_dict_add_nr(d, S_LEN("lnum"), sign->lnum);
dict_add_nr_str(d, "name", 0L, sign_typenr2name(sign->typenr)); tv_dict_add_str(d, S_LEN("name"),
(const char *)sign_typenr2name(sign->typenr));
tv_list_append_dict(l, d); tv_list_append_dict(l, d);
} }
@@ -9079,17 +9055,16 @@ static dict_T *get_buffer_info(buf_T *buf)
{ {
dict_T *const dict = tv_dict_alloc(); dict_T *const dict = tv_dict_alloc();
dict_add_nr_str(dict, "bufnr", buf->b_fnum, NULL); tv_dict_add_nr(dict, S_LEN("bufnr"), buf->b_fnum);
dict_add_nr_str(dict, "name", 0L, tv_dict_add_str(dict, S_LEN("name"),
buf->b_ffname != NULL ? buf->b_ffname : (char_u *)""); buf->b_ffname != NULL ? (const char *)buf->b_ffname : "");
dict_add_nr_str(dict, "lnum", buflist_findlnum(buf), NULL); tv_dict_add_nr(dict, S_LEN("lnum"), buflist_findlnum(buf));
dict_add_nr_str(dict, "loaded", buf->b_ml.ml_mfp != NULL, NULL); tv_dict_add_nr(dict, S_LEN("loaded"), buf->b_ml.ml_mfp != NULL);
dict_add_nr_str(dict, "listed", buf->b_p_bl, NULL); tv_dict_add_nr(dict, S_LEN("listed"), buf->b_p_bl);
dict_add_nr_str(dict, "changed", bufIsChanged(buf), NULL); tv_dict_add_nr(dict, S_LEN("changed"), bufIsChanged(buf));
dict_add_nr_str(dict, "changedtick", buf->b_changedtick, NULL); tv_dict_add_nr(dict, S_LEN("changedtick"), buf->b_changedtick);
dict_add_nr_str(dict, "hidden", tv_dict_add_nr(dict, S_LEN("hidden"),
buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0, buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0);
NULL);
// Get a reference to buffer variables // Get a reference to buffer variables
tv_dict_add_dict(dict, S_LEN("variables"), buf->b_vars); tv_dict_add_dict(dict, S_LEN("variables"), buf->b_vars);
@@ -9411,9 +9386,9 @@ static void f_getcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
dict_T *dict = rettv->vval.v_dict; dict_T *dict = rettv->vval.v_dict;
dict_add_nr_str(dict, "char", 0L, last_csearch()); tv_dict_add_str(dict, S_LEN("char"), last_csearch());
dict_add_nr_str(dict, "forward", last_csearch_forward(), NULL); tv_dict_add_nr(dict, S_LEN("forward"), last_csearch_forward());
dict_add_nr_str(dict, "until", last_csearch_until(), NULL); tv_dict_add_nr(dict, S_LEN("until"), last_csearch_until());
} }
/* /*
@@ -9881,17 +9856,18 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
tv_dict_add_list(dict, buf, (size_t)len, l); tv_dict_add_list(dict, buf, (size_t)len, l);
} }
} else { } else {
dict_add_nr_str(dict, "pattern", 0L, cur->pattern); tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cur->pattern);
} }
dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id)); tv_dict_add_str(dict, S_LEN("group"),
dict_add_nr_str(dict, "priority", (long)cur->priority, NULL); (const char *)syn_id2name(cur->hlg_id));
dict_add_nr_str(dict, "id", (long)cur->id, NULL); tv_dict_add_nr(dict, S_LEN("priority"), (varnumber_T)cur->priority);
tv_dict_add_nr(dict, S_LEN("id"), (varnumber_T)cur->id);
if (cur->conceal_char) { if (cur->conceal_char) {
char_u buf[MB_MAXBYTES + 1]; char buf[MB_MAXBYTES + 1];
buf[(*mb_char2bytes)((int)cur->conceal_char, buf)] = NUL; buf[(*mb_char2bytes)((int)cur->conceal_char, (char_u *)buf)] = NUL;
dict_add_nr_str(dict, "conceal", 0L, (char_u *)&buf); tv_dict_add_str(dict, S_LEN("conceal"), buf);
} }
tv_list_append_dict(rettv->vval.v_list, dict); tv_list_append_dict(rettv->vval.v_list, dict);
@@ -10041,7 +10017,7 @@ static dict_T *get_tabpage_info(tabpage_T *tp, int tp_idx)
{ {
dict_T *const dict = tv_dict_alloc(); dict_T *const dict = tv_dict_alloc();
dict_add_nr_str(dict, "tabnr", tp_idx, NULL); tv_dict_add_nr(dict, S_LEN("tabnr"), tp_idx);
list_T *const l = tv_list_alloc(); list_T *const l = tv_list_alloc();
FOR_ALL_WINDOWS_IN_TAB(wp, tp) { FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
@@ -10139,17 +10115,16 @@ static dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
{ {
dict_T *const dict = tv_dict_alloc(); dict_T *const dict = tv_dict_alloc();
dict_add_nr_str(dict, "tabnr", tpnr, NULL); tv_dict_add_nr(dict, S_LEN("tabnr"), tpnr);
dict_add_nr_str(dict, "winnr", winnr, NULL); tv_dict_add_nr(dict, S_LEN("winnr"), winnr);
dict_add_nr_str(dict, "winid", wp->handle, NULL); tv_dict_add_nr(dict, S_LEN("winid"), wp->handle);
dict_add_nr_str(dict, "height", wp->w_height, NULL); tv_dict_add_nr(dict, S_LEN("height"), wp->w_height);
dict_add_nr_str(dict, "width", wp->w_width, NULL); tv_dict_add_nr(dict, S_LEN("width"), wp->w_width);
dict_add_nr_str(dict, "bufnr", wp->w_buffer->b_fnum, NULL); tv_dict_add_nr(dict, S_LEN("bufnr"), wp->w_buffer->b_fnum);
dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL); tv_dict_add_nr(dict, S_LEN("quickfix"), bt_quickfix(wp->w_buffer));
dict_add_nr_str(dict, "loclist", tv_dict_add_nr(dict, S_LEN("loclist"),
(bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL));
NULL);
// Add a reference to window variables // Add a reference to window variables
tv_dict_add_dict(dict, S_LEN("variables"), wp->w_vars); tv_dict_add_dict(dict, S_LEN("variables"), wp->w_vars);
@@ -12074,15 +12049,15 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
char *const mapmode = map_mode_to_chars(mp->m_mode); char *const mapmode = map_mode_to_chars(mp->m_mode);
dict_T *dict = rettv->vval.v_dict; dict_T *dict = rettv->vval.v_dict;
dict_add_nr_str(dict, "lhs", 0L, lhs); tv_dict_add_str(dict, S_LEN("lhs"), (const char *)lhs);
dict_add_nr_str(dict, "rhs", 0L, mp->m_orig_str); tv_dict_add_str(dict, S_LEN("rhs"), (const char *)mp->m_orig_str);
dict_add_nr_str(dict, "noremap", mp->m_noremap ? 1L : 0L, NULL); tv_dict_add_nr(dict, S_LEN("noremap"), mp->m_noremap ? 1 : 0);
dict_add_nr_str(dict, "expr", mp->m_expr ? 1L : 0L, NULL); tv_dict_add_nr(dict, S_LEN("expr"), mp->m_expr ? 1 : 0);
dict_add_nr_str(dict, "silent", mp->m_silent ? 1L : 0L, NULL); tv_dict_add_nr(dict, S_LEN("silent"), mp->m_silent ? 1 : 0);
dict_add_nr_str(dict, "sid", (long)mp->m_script_ID, NULL); tv_dict_add_nr(dict, S_LEN("sid"), (varnumber_T)mp->m_script_ID);
dict_add_nr_str(dict, "buffer", (long)buffer_local, NULL); tv_dict_add_nr(dict, S_LEN("buffer"), (varnumber_T)buffer_local);
dict_add_nr_str(dict, "nowait", mp->m_nowait ? 1L : 0L, NULL); tv_dict_add_nr(dict, S_LEN("nowait"), mp->m_nowait ? 1 : 0);
dict_add_nr_str(dict, "mode", 0L, (char_u *)mapmode); tv_dict_add_str(dict, S_LEN("mode"), mapmode);
xfree(lhs); xfree(lhs);
xfree(mapmode); xfree(mapmode);
@@ -16984,13 +16959,13 @@ static void f_undotree(typval_T *argvars, typval_T *rettv, FunPtr fptr)
dict_T *dict = rettv->vval.v_dict; dict_T *dict = rettv->vval.v_dict;
list_T *list; list_T *list;
dict_add_nr_str(dict, "synced", (long)curbuf->b_u_synced, NULL); tv_dict_add_nr(dict, S_LEN("synced"), (varnumber_T)curbuf->b_u_synced);
dict_add_nr_str(dict, "seq_last", curbuf->b_u_seq_last, NULL); tv_dict_add_nr(dict, S_LEN("seq_last"), (varnumber_T)curbuf->b_u_seq_last);
dict_add_nr_str(dict, "save_last", tv_dict_add_nr(dict, S_LEN("save_last"),
(long)curbuf->b_u_save_nr_last, NULL); (varnumber_T)curbuf->b_u_save_nr_last);
dict_add_nr_str(dict, "seq_cur", curbuf->b_u_seq_cur, NULL); tv_dict_add_nr(dict, S_LEN("seq_cur"), (varnumber_T)curbuf->b_u_seq_cur);
dict_add_nr_str(dict, "time_cur", (long)curbuf->b_u_time_cur, NULL); tv_dict_add_nr(dict, S_LEN("time_cur"), (varnumber_T)curbuf->b_u_time_cur);
dict_add_nr_str(dict, "save_cur", (long)curbuf->b_u_save_nr_cur, NULL); tv_dict_add_nr(dict, S_LEN("save_cur"), (varnumber_T)curbuf->b_u_save_nr_cur);
list = tv_list_alloc(); list = tv_list_alloc();
u_eval_tree(curbuf->b_u_oldhead, list); u_eval_tree(curbuf->b_u_oldhead, list);
@@ -17223,16 +17198,16 @@ static void f_winsaveview(typval_T *argvars, typval_T *rettv, FunPtr fptr)
tv_dict_alloc_ret(rettv); tv_dict_alloc_ret(rettv);
dict = rettv->vval.v_dict; dict = rettv->vval.v_dict;
dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL); tv_dict_add_nr(dict, S_LEN("lnum"), (varnumber_T)curwin->w_cursor.lnum);
dict_add_nr_str(dict, "col", (long)curwin->w_cursor.col, NULL); tv_dict_add_nr(dict, S_LEN("col"), (varnumber_T)curwin->w_cursor.col);
dict_add_nr_str(dict, "coladd", (long)curwin->w_cursor.coladd, NULL); tv_dict_add_nr(dict, S_LEN("coladd"), (varnumber_T)curwin->w_cursor.coladd);
update_curswant(); update_curswant();
dict_add_nr_str(dict, "curswant", (long)curwin->w_curswant, NULL); tv_dict_add_nr(dict, S_LEN("curswant"), (varnumber_T)curwin->w_curswant);
dict_add_nr_str(dict, "topline", (long)curwin->w_topline, NULL); tv_dict_add_nr(dict, S_LEN("topline"), (varnumber_T)curwin->w_topline);
dict_add_nr_str(dict, "topfill", (long)curwin->w_topfill, NULL); tv_dict_add_nr(dict, S_LEN("topfill"), (varnumber_T)curwin->w_topfill);
dict_add_nr_str(dict, "leftcol", (long)curwin->w_leftcol, NULL); tv_dict_add_nr(dict, S_LEN("leftcol"), (varnumber_T)curwin->w_leftcol);
dict_add_nr_str(dict, "skipcol", (long)curwin->w_skipcol, NULL); tv_dict_add_nr(dict, S_LEN("skipcol"), (varnumber_T)curwin->w_skipcol);
} }
/// Writes list of strings to file /// Writes list of strings to file

View File

@@ -1180,7 +1180,7 @@ int tv_dict_add_list(dict_T *const d, const char *const key,
const size_t key_len, list_T *const list) const size_t key_len, list_T *const list)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
dictitem_T *item = tv_dict_item_alloc_len(key, key_len); dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
item->di_tv.v_lock = VAR_UNLOCKED; item->di_tv.v_lock = VAR_UNLOCKED;
item->di_tv.v_type = VAR_LIST; item->di_tv.v_type = VAR_LIST;
@@ -1218,6 +1218,54 @@ int tv_dict_add_dict(dict_T *const d, const char *const key,
return OK; return OK;
} }
/// Add a number entry to dictionary
///
/// @param[out] d Dictionary to add entry to.
/// @param[in] key Key to add.
/// @param[in] key_len Key length.
/// @param[in] nr Number to add.
///
/// @return OK in case of success, FAIL when key already exists.
int tv_dict_add_nr(dict_T *const d, const char *const key,
const size_t key_len, const varnumber_T nr)
{
dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
item->di_tv.v_lock = VAR_UNLOCKED;
item->di_tv.v_type = VAR_NUMBER;
item->di_tv.vval.v_number = nr;
if (tv_dict_add(d, item) == FAIL) {
tv_dict_item_free(item);
return FAIL;
}
return OK;
}
/// Add a string entry to dictionary
///
/// @param[out] d Dictionary to add entry to.
/// @param[in] key Key to add.
/// @param[in] key_len Key length.
/// @param[in] val String to add.
///
/// @return OK in case of success, FAIL when key already exists.
int tv_dict_add_str(dict_T *const d,
const char *const key, const size_t key_len,
const char *const val)
FUNC_ATTR_NONNULL_ALL
{
dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
item->di_tv.v_lock = VAR_UNLOCKED;
item->di_tv.v_type = VAR_STRING;
item->di_tv.vval.v_string = (char_u *)xstrdup(val);
if (tv_dict_add(d, item) == FAIL) {
tv_dict_item_free(item);
return FAIL;
}
return OK;
}
//{{{2 Operations on the whole dict //{{{2 Operations on the whole dict
/// Clear all the keys of a Dictionary. "d" remains a valid empty Dictionary. /// Clear all the keys of a Dictionary. "d" remains a valid empty Dictionary.

View File

@@ -4,6 +4,7 @@
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include "nvim/hashtab.h" #include "nvim/hashtab.h"
#include "nvim/garray.h" #include "nvim/garray.h"

View File

@@ -1549,8 +1549,8 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope)
assert(false); assert(false);
} }
dict_add_nr_str(dict, "scope", 0L, (char_u *)buf); tv_dict_add_str(dict, S_LEN("scope"), buf);
dict_add_nr_str(dict, "cwd", 0L, (char_u *)new_dir); tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
tv_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,

View File

@@ -14,6 +14,7 @@
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/assert.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/eval/typval.h" #include "nvim/eval/typval.h"
@@ -2567,17 +2568,17 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg)
// the register type // the register type
char buf[NUMBUFLEN+2]; char buf[NUMBUFLEN+2];
format_reg_type(reg->y_type, reg->y_width, buf, ARRAY_SIZE(buf)); format_reg_type(reg->y_type, reg->y_width, buf, ARRAY_SIZE(buf));
dict_add_nr_str(dict, "regtype", 0, (char_u *)buf); tv_dict_add_str(dict, S_LEN("regtype"), buf);
// name of requested register or the empty string for an unnamed operation. // name of requested register or the empty string for an unnamed operation.
buf[0] = (char)oap->regname; buf[0] = (char)oap->regname;
buf[1] = NUL; buf[1] = NUL;
dict_add_nr_str(dict, "regname", 0, (char_u *)buf); tv_dict_add_str(dict, S_LEN("regname"), buf);
// kind of operation (yank/delete/change) // kind of operation (yank/delete/change)
buf[0] = (char)get_op_char(oap->op_type); buf[0] = (char)get_op_char(oap->op_type);
buf[1] = NUL; buf[1] = NUL;
dict_add_nr_str(dict, "operator", 0, (char_u *)buf); tv_dict_add_str(dict, S_LEN("operator"), buf);
tv_dict_set_keys_readonly(dict); tv_dict_set_keys_readonly(dict);
textlock++; textlock++;
@@ -5484,17 +5485,19 @@ void cursor_pos_info(dict_T *dict)
if (dict != NULL) { if (dict != NULL) {
// Don't shorten this message, the user asked for it. // Don't shorten this message, the user asked for it.
dict_add_nr_str(dict, "words", word_count, NULL); tv_dict_add_nr(dict, S_LEN("words"), (varnumber_T)word_count);
dict_add_nr_str(dict, "chars", char_count, NULL); tv_dict_add_nr(dict, S_LEN("chars"), (varnumber_T)char_count);
dict_add_nr_str(dict, "bytes", byte_count + bom_count, NULL); tv_dict_add_nr(dict, S_LEN("bytes"), (varnumber_T)(byte_count + bom_count));
dict_add_nr_str(dict, l_VIsual_active ? "visual_bytes" : "cursor_bytes", STATIC_ASSERT(sizeof("visual") == sizeof("cursor"),
byte_count_cursor, NULL); "key_len argument in tv_dict_add_nr is wrong");
dict_add_nr_str(dict, l_VIsual_active ? "visual_chars" : "cursor_chars", tv_dict_add_nr(dict, l_VIsual_active ? "visual_bytes" : "cursor_bytes",
char_count_cursor, NULL); sizeof("visual_bytes") - 1, (varnumber_T)byte_count_cursor);
dict_add_nr_str(dict, l_VIsual_active ? "visual_words" : "cursor_words", tv_dict_add_nr(dict, l_VIsual_active ? "visual_chars" : "cursor_chars",
word_count_cursor, NULL); sizeof("visual_chars") - 1, (varnumber_T)char_count_cursor);
} tv_dict_add_nr(dict, l_VIsual_active ? "visual_words" : "cursor_words",
sizeof("visual_words") - 1, (varnumber_T)word_count_cursor);
}
} }
/// Check if the default register (used in an unnamed paste) should be a /// Check if the default register (used in an unnamed paste) should be a

View File

@@ -6971,9 +6971,10 @@ dict_T *get_winbuf_options(const int bufopt)
if (varp != NULL) { if (varp != NULL) {
if (opt->flags & P_STRING) { if (opt->flags & P_STRING) {
dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp); tv_dict_add_str(d, opt->fullname, strlen(opt->fullname),
*(const char **)varp);
} else { } else {
dict_add_nr_str(d, opt->fullname, *varp, NULL); tv_dict_add_nr(d, opt->fullname, strlen(opt->fullname), *varp);
} }
} }
} }

View File

@@ -3972,7 +3972,6 @@ static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start)
int get_errorlist(win_T *wp, int qf_idx, list_T *list) int get_errorlist(win_T *wp, int qf_idx, list_T *list)
{ {
qf_info_T *qi = &ql_info; qf_info_T *qi = &ql_info;
dict_T *dict;
char_u buf[2]; char_u buf[2];
qfline_T *qfp; qfline_T *qfp;
int i; int i;
@@ -4000,23 +3999,34 @@ int get_errorlist(win_T *wp, int qf_idx, list_T *list)
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
bufnum = 0; bufnum = 0;
dict = tv_dict_alloc(); dict_T *const dict = tv_dict_alloc();
tv_list_append_dict(list, dict); tv_list_append_dict(list, dict);
buf[0] = qfp->qf_type; buf[0] = qfp->qf_type;
buf[1] = NUL; buf[1] = NUL;
if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL if (tv_dict_add_nr(dict, S_LEN("bufnr"), (varnumber_T)bufnum) == FAIL
|| dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL || (tv_dict_add_nr(dict, S_LEN("lnum"), (varnumber_T)qfp->qf_lnum)
|| dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL == FAIL)
|| dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL || (tv_dict_add_nr(dict, S_LEN("col"), (varnumber_T)qfp->qf_col)
|| dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL == FAIL)
|| dict_add_nr_str(dict, "pattern", 0L, || (tv_dict_add_nr(dict, S_LEN("vcol"), (varnumber_T)qfp->qf_viscol)
qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL == FAIL)
|| dict_add_nr_str(dict, "text", 0L, || (tv_dict_add_nr(dict, S_LEN("nr"), (varnumber_T)qfp->qf_nr) == FAIL)
qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL || tv_dict_add_str(dict, S_LEN("pattern"),
|| dict_add_nr_str(dict, "type", 0L, buf) == FAIL (qfp->qf_pattern == NULL
|| dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL) ? ""
return FAIL; : (const char *)qfp->qf_pattern)) == FAIL
|| tv_dict_add_str(dict, S_LEN("text"),
(qfp->qf_text == NULL
? ""
: (const char *)qfp->qf_text)) == FAIL
|| tv_dict_add_str(dict, S_LEN("type"), (const char *)buf) == FAIL
|| (tv_dict_add_nr(dict, S_LEN("valid"), (varnumber_T)qfp->qf_valid)
== FAIL)) {
// tv_dict_add* fail only if key already exist, but this is a newly
// allocated dictionary which is thus guaranteed to have no existing keys.
assert(false);
}
qfp = qfp->qf_next; qfp = qfp->qf_next;
if (qfp == NULL) { if (qfp == NULL) {
@@ -4085,15 +4095,15 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
if (t == NULL) { if (t == NULL) {
t = (char_u *)""; t = (char_u *)"";
} }
status = dict_add_nr_str(retdict, "title", 0L, t); status = tv_dict_add_str(retdict, S_LEN("title"), (const char *)t);
} }
if ((status == OK) && (flags & QF_GETLIST_NR)) { if ((status == OK) && (flags & QF_GETLIST_NR)) {
status = dict_add_nr_str(retdict, "nr", qf_idx + 1, NULL); status = tv_dict_add_nr(retdict, S_LEN("nr"), qf_idx + 1);
} }
if ((status == OK) && (flags & QF_GETLIST_WINID)) { if ((status == OK) && (flags & QF_GETLIST_WINID)) {
win_T *win = qf_find_win(qi); win_T *win = qf_find_win(qi);
if (win != NULL) { if (win != NULL) {
status = dict_add_nr_str(retdict, "winid", win->handle, NULL); status = tv_dict_add_nr(retdict, S_LEN("winid"), win->handle);
} }
} }

View File

@@ -356,9 +356,10 @@ int pat_has_uppercase(char_u *pat)
return FALSE; return FALSE;
} }
char_u *last_csearch(void) const char *last_csearch(void)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return lastc_bytes; return (const char *)lastc_bytes;
} }
int last_csearch_forward(void) int last_csearch_forward(void)

View File

@@ -776,11 +776,12 @@ do_tag (
dict = tv_dict_alloc(); dict = tv_dict_alloc();
tv_list_append_dict(list, dict); tv_list_append_dict(list, dict);
dict_add_nr_str(dict, "text", 0L, tag_name); tv_dict_add_str(dict, S_LEN("text"), (const char *)tag_name);
dict_add_nr_str(dict, "filename", 0L, fname); tv_dict_add_str(dict, S_LEN("filename"), (const char *)fname);
dict_add_nr_str(dict, "lnum", lnum, NULL); tv_dict_add_nr(dict, S_LEN("lnum"), lnum);
if (lnum == 0) if (lnum == 0) {
dict_add_nr_str(dict, "pattern", 0L, cmd); tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cmd);
}
} }
vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag);
@@ -2203,7 +2204,7 @@ parse_tag_line (
* Return TRUE if it is a static tag and adjust *tagname to the real tag. * Return TRUE if it is a static tag and adjust *tagname to the real tag.
* Return FALSE if it is not a static tag. * Return FALSE if it is not a static tag.
*/ */
static int test_for_static(tagptrs_T *tagp) static bool test_for_static(tagptrs_T *tagp)
{ {
char_u *p; char_u *p;
@@ -2790,7 +2791,8 @@ add_tag_field (
STRLCPY(buf, start, len + 1); STRLCPY(buf, start, len + 1);
} }
buf[len] = NUL; buf[len] = NUL;
retval = dict_add_nr_str(dict, field_name, 0L, buf); retval = tv_dict_add_str(dict, field_name, STRLEN(field_name),
(const char *)buf);
xfree(buf); xfree(buf);
return retval; return retval;
} }
@@ -2806,7 +2808,7 @@ int get_tags(list_T *list, char_u *pat)
char_u *full_fname; char_u *full_fname;
dict_T *dict; dict_T *dict;
tagptrs_T tp; tagptrs_T tp;
long is_static; bool is_static;
ret = find_tags(pat, &num_matches, &matches, ret = find_tags(pat, &num_matches, &matches,
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL); TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL);
@@ -2829,14 +2831,13 @@ int get_tags(list_T *list, char_u *pat)
full_fname = tag_full_fname(&tp); full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname, || add_tag_field(dict, "filename", full_fname, NULL) == FAIL
NULL) == FAIL || add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
|| add_tag_field(dict, "cmd", tp.command,
tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind, || add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind ? tp.tagkind_end : NULL) == FAIL tp.tagkind ? tp.tagkind_end : NULL) == FAIL
|| dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) || tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) {
ret = FAIL; ret = FAIL;
}
xfree(full_fname); xfree(full_fname);

View File

@@ -2943,19 +2943,22 @@ void u_eval_tree(u_header_T *first_uhp, list_T *list)
while (uhp != NULL) { while (uhp != NULL) {
dict = tv_dict_alloc(); dict = tv_dict_alloc();
dict_add_nr_str(dict, "seq", uhp->uh_seq, NULL); tv_dict_add_nr(dict, S_LEN("seq"), (varnumber_T)uhp->uh_seq);
dict_add_nr_str(dict, "time", (long)uhp->uh_time, NULL); tv_dict_add_nr(dict, S_LEN("time"), (varnumber_T)uhp->uh_time);
if (uhp == curbuf->b_u_newhead) if (uhp == curbuf->b_u_newhead) {
dict_add_nr_str(dict, "newhead", 1, NULL); tv_dict_add_nr(dict, S_LEN("newhead"), 1);
if (uhp == curbuf->b_u_curhead) }
dict_add_nr_str(dict, "curhead", 1, NULL); if (uhp == curbuf->b_u_curhead) {
if (uhp->uh_save_nr > 0) tv_dict_add_nr(dict, S_LEN("curhead"), 1);
dict_add_nr_str(dict, "save", uhp->uh_save_nr, NULL); }
if (uhp->uh_save_nr > 0) {
tv_dict_add_nr(dict, S_LEN("save"), (varnumber_T)uhp->uh_save_nr);
}
if (uhp->uh_alt_next.ptr != NULL) { if (uhp->uh_alt_next.ptr != NULL) {
list_T *alt_list = tv_list_alloc(); list_T *alt_list = tv_list_alloc();
/* Recursive call to add alternate undo tree. */ // Recursive call to add alternate undo tree.
u_eval_tree(uhp->uh_alt_next.ptr, alt_list); u_eval_tree(uhp->uh_alt_next.ptr, alt_list);
tv_dict_add_list(dict, S_LEN("alt"), alt_list); tv_dict_add_list(dict, S_LEN("alt"), alt_list);
} }