From 1ae73e2d1c328a6181f4ebaebfc273e1d1c8d59d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 18 Jan 2022 12:22:54 +0000 Subject: vim-patch:8.2.0175: crash when removing list element in map() Problem: Crash when removing list element in map(). Solution: Lock the list. (closes vim/vim#2652) https://github.com/vim/vim/commit/db661fb95dc41b7a9438cf3cd4e77f8410bc81c0 --- src/nvim/eval.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6dbdc09c3b..d25903c12a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6468,6 +6468,10 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) if (argvars[0].v_type == VAR_DICT) { vimvars[VV_KEY].vv_type = VAR_STRING; + const VarLockStatus prev_lock = d->dv_lock; + if (map && d->dv_lock == VAR_UNLOCKED) { + d->dv_lock = VAR_LOCKED; + } ht = &d->dv_hashtab; hash_lock(ht); todo = (int)ht->ht_used; @@ -6498,6 +6502,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) } } hash_unlock(ht); + d->dv_lock = prev_lock; } else if (argvars[0].v_type == VAR_BLOB) { vimvars[VV_KEY].vv_type = VAR_NUMBER; @@ -6530,6 +6535,10 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) assert(argvars[0].v_type == VAR_LIST); vimvars[VV_KEY].vv_type = VAR_NUMBER; + const VarLockStatus prev_lock = tv_list_locked(l); + if (map && tv_list_locked(l) == VAR_UNLOCKED) { + tv_list_set_lock(l, VAR_LOCKED); + } for (listitem_T *li = tv_list_first(l); li != NULL;) { if (map && var_check_lock(TV_LIST_ITEM_TV(li)->v_lock, arg_errmsg, @@ -6548,6 +6557,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) } idx++; } + tv_list_set_lock(l, prev_lock); } restore_vimvar(VV_KEY, &save_key); -- cgit From fb8cd340dcd102773f0651c75436271fcab721d4 Mon Sep 17 00:00:00 2001 From: bb010g Date: Wed, 26 Jan 2022 20:35:12 -0800 Subject: fix(eval): v:lua support for `-` in module names --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d25903c12a..40fa05da4f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8956,7 +8956,7 @@ static bool tv_is_luafunc(typval_T *tv) const char *skip_luafunc_name(const char *p) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - while (ASCII_ISALNUM(*p) || *p == '_' || *p == '.' || *p == '\'') { + while (ASCII_ISALNUM(*p) || *p == '_' || *p == '-' || *p == '.' || *p == '\'') { p++; } return p; -- cgit From 796224028bb8f67d91913f953edfe0693f444de9 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 29 Jan 2022 16:34:00 +0000 Subject: vim-patch:8.2.3629: command completion in cmdline window uses global commands Problem: Command completion in cmdline window uses global user commands, not local commands for the window where it was opened from. Solution: Use local commands. (closes vim/vim#9168) https://github.com/vim/vim/commit/a1198124370a366ff02811a43845a631b5c6e7f0 --- src/nvim/eval.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 40fa05da4f..b87dad0d1f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3218,9 +3218,8 @@ char_u *get_user_var_name(expand_T *xp, int idx) // b: variables // In cmdwin, the alternative buffer should be used. - hashtab_T *ht = (cmdwin_type != 0 && get_cmdline_type() == NUL) - ? &prevwin->w_buffer->b_vars->dv_hashtab - : &curbuf->b_vars->dv_hashtab; + hashtab_T *ht + = is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab; if (bdone < ht->ht_used) { if (bdone++ == 0) { hi = ht->ht_array; @@ -3235,9 +3234,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) // w: variables // In cmdwin, the alternative window should be used. - ht = (cmdwin_type != 0 && get_cmdline_type() == NUL) - ? &prevwin->w_vars->dv_hashtab - : &curwin->w_vars->dv_hashtab; + ht = is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab : &curwin->w_vars->dv_hashtab; if (wdone < ht->ht_used) { if (wdone++ == 0) { hi = ht->ht_array; -- cgit From 62c8715ee9be95f9e0f5164dc9b39a04f4d60e8a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 31 Jan 2022 08:12:44 +0800 Subject: vim-patch:8.1.2412: crash when evaluating expression with error (#17109) --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 40fa05da4f..3325628a8e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4402,7 +4402,7 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool eva rettv->v_type = VAR_UNKNOWN; int ret = get_lambda_tv(arg, rettv, evaluate); - if (ret == NOTDONE) { + if (ret != OK) { return FAIL; } else if (**arg != '(') { if (verbose) { -- cgit From f195345c936eaecf423ab79473003e1ab337a17d Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 31 Jan 2022 23:06:46 +0900 Subject: [RFC] fix: has('python') error (#17252) * fix: has('python') error * fix: functional tests --- src/nvim/eval.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cf3322df1b..b8e9f41551 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -11004,10 +11004,7 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments, boo bool eval_has_provider(const char *feat) { if (!strequal(feat, "clipboard") - && !strequal(feat, "python") && !strequal(feat, "python3") - && !strequal(feat, "python_compiled") - && !strequal(feat, "python_dynamic") && !strequal(feat, "python3_compiled") && !strequal(feat, "python3_dynamic") && !strequal(feat, "perl") -- cgit From f326c9a77da3aef052ce6af0f851344f2479c844 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 6 Jan 2022 13:48:37 +0000 Subject: vim-patch:8.2.4018: ml_get error when win_execute redraws with Visual selection Problem: ml_get error when win_execute redraws with Visual selection. Solution: Disable Visual area temporarily. (closes vim/vim#9479) https://github.com/vim/vim/commit/18f4740f043b353abe47b7a00131317052457686 {switch_to/restore}_win_for_buf is N/A (marked as such in v8.0.0860; currently only used in Vim's if_py). Add a modeline to test_execute_func.vim. --- src/nvim/eval.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b8e9f41551..5d9326eb24 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6963,10 +6963,9 @@ win_T *find_tabwin(typval_T *wvp, typval_T *tvp) /// @param off 1 for gettabwinvar() void getwinvar(typval_T *argvars, typval_T *rettv, int off) { - win_T *win, *oldcurwin; + win_T *win; dictitem_T *v; tabpage_T *tp = NULL; - tabpage_T *oldtabpage = NULL; bool done = false; if (off == 1) { @@ -6986,8 +6985,8 @@ void getwinvar(typval_T *argvars, typval_T *rettv, int off) // otherwise the window is not valid. Only do this when needed, // autocommands get blocked. bool need_switch_win = tp != curtab || win != curwin; - if (!need_switch_win - || switch_win(&oldcurwin, &oldtabpage, win, tp, true) == OK) { + switchwin_T switchwin; + if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) { if (*varname == '&') { if (varname[1] == NUL) { // get all window-local options in a dict @@ -7015,7 +7014,7 @@ void getwinvar(typval_T *argvars, typval_T *rettv, int off) if (need_switch_win) { // restore previous notion of curwin - restore_win(oldcurwin, oldtabpage, true); + restore_win(&switchwin, true); } } emsg_off--; @@ -7517,11 +7516,9 @@ void setwinvar(typval_T *argvars, typval_T *rettv, int off) typval_T *varp = &argvars[off + 2]; if (win != NULL && varname != NULL && varp != NULL) { - win_T *save_curwin; - tabpage_T *save_curtab; bool need_switch_win = tp != curtab || win != curwin; - if (!need_switch_win - || switch_win(&save_curwin, &save_curtab, win, tp, true) == OK) { + switchwin_T switchwin; + if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) { if (*varname == '&') { long numval; bool error = false; @@ -7543,7 +7540,7 @@ void setwinvar(typval_T *argvars, typval_T *rettv, int off) } } if (need_switch_win) { - restore_win(save_curwin, save_curtab, true); + restore_win(&switchwin, true); } } } -- cgit From 7002a3433bed7600ec02d64927ae0e77d077f34e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 1 Jan 2022 07:27:46 +0000 Subject: vim-patch:8.2.2658: :for cannot loop over a string Problem: :for cannot loop over a string. Solution: Accept a string argument and iterate over its characters. https://github.com/vim/vim/commit/74e54fcb447e5db32f9c2df34c0554bbecdccca2 v8.2.2659 is already ported. N/A patches for version.c: vim-patch:8.2.2736: Vim9: for loop over string is a bit slow Problem: Vim9: for loop over string is a bit slow. Solution: Avoid using strlen(). https://github.com/vim/vim/commit/175a41c13f3e27e30c662f2f418c5a347dbc645d --- src/nvim/eval.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5d9326eb24..aecb23f251 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -112,9 +112,11 @@ typedef struct { int fi_semicolon; // TRUE if ending in '; var]' int fi_varcount; // nr of variables in the list listwatch_T fi_lw; // keep an eye on the item used. - list_T *fi_list; // list being used + list_T *fi_list; // list being used int fi_bi; // index of blob blob_T *fi_blob; // blob being used + char_u *fi_string; // copy of string being used + int fi_byte_idx; // byte index in fi_string } forinfo_T; // values for vv_flags: @@ -2641,6 +2643,13 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) fi->fi_blob = btv.vval.v_blob; } tv_clear(&tv); + } else if (tv.v_type == VAR_STRING) { + fi->fi_byte_idx = 0; + fi->fi_string = tv.vval.v_string; + tv.vval.v_string = NULL; + if (fi->fi_string == NULL) { + fi->fi_string = vim_strsave((char_u *)""); + } } else { emsg(_(e_listblobreq)); tv_clear(&tv); @@ -2679,6 +2688,19 @@ bool next_for_item(void *fi_void, char_u *arg) fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; } + if (fi->fi_string != NULL) { + const int len = utfc_ptr2len(fi->fi_string + fi->fi_byte_idx); + if (len == 0) { + return false; + } + typval_T tv; + tv.v_type = VAR_STRING; + tv.v_lock = VAR_FIXED; + tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len); + fi->fi_byte_idx += len; + return ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; + } + listitem_T *item = fi->fi_lw.lw_item; if (item == NULL) { return false; @@ -2698,12 +2720,16 @@ void free_for_info(void *fi_void) { forinfo_T *fi = (forinfo_T *)fi_void; - if (fi != NULL && fi->fi_list != NULL) { + if (fi == NULL) { + return; + } + if (fi->fi_list != NULL) { tv_list_watch_remove(fi->fi_list, &fi->fi_lw); tv_list_unref(fi->fi_list); - } - if (fi != NULL && fi->fi_blob != NULL) { + } else if (fi->fi_blob != NULL) { tv_blob_unref(fi->fi_blob); + } else { + xfree(fi->fi_string); } xfree(fi); } -- cgit From 83a48d7a44c69a8b159bdcf90029005f2f4a8de5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 1 Jan 2022 07:51:13 +0000 Subject: vim-patch:8.2.2661: leaking memory when looping over a string Problem: Leaking memory when looping over a string. Solution: Free the memory. https://github.com/vim/vim/commit/bb5d87c8504588be9c9d2fecc5b6455a2b2f6201 --- src/nvim/eval.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index aecb23f251..b4baeb5240 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2698,7 +2698,10 @@ bool next_for_item(void *fi_void, char_u *arg) tv.v_lock = VAR_FIXED; tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len); fi->fi_byte_idx += len; - return ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; + const int result + = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; + xfree(tv.vval.v_string); + return result; } listitem_T *item = fi->fi_lw.lw_item; -- cgit From 8adbba7ac38d7a0b4e1f602f6522b9403c11fc7e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 1 Jan 2022 08:07:13 +0000 Subject: feat(eval): port emsg from v8.2.3284 https://github.com/vim/vim/commit/80d7395dcfe96158428da6bb3d28a6eee1244e28 --- src/nvim/eval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b4baeb5240..93d34cf86f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -69,6 +69,7 @@ static char *e_nowhitespace static char *e_invalwindow = N_("E957: Invalid window number"); static char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s"); static char *e_write2 = N_("E80: Error while writing: %s"); +static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob required"); // TODO(ZyX-I): move to eval/executor static char *e_letwrong = N_("E734: Wrong variable type for %s="); @@ -2651,7 +2652,7 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) fi->fi_string = vim_strsave((char_u *)""); } } else { - emsg(_(e_listblobreq)); + emsg(_(e_string_list_or_blob_required)); tv_clear(&tv); } } -- cgit From 6ab71683d14a408e79f7cbda3a07ab65f76c6b35 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Feb 2022 04:46:16 +0800 Subject: vim-patch:8.2.2324: not easy to get mark en cursor posotion by character count Problem: Not easy to get mark en cursor posotion by character count. Solution: Add functions that use character index. (Yegappan Lakshmanan, closes vim/vim#7648) https://github.com/vim/vim/commit/6f02b00bb0958f70bc15534e115b4c6dadff0e06 --- src/nvim/eval.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 90 insertions(+), 15 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5d9326eb24..8421d8978a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8151,6 +8151,52 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) return ret; } +/// Convert the specified byte index of line 'lnum' in buffer 'buf' to a +/// character index. Works only for loaded buffers. Returns -1 on failure. +/// The index of the first character is one. +int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) +{ + if (buf == NULL || buf->b_ml.ml_mfp == NULL) { + return -1; + } + + if (lnum > buf->b_ml.ml_line_count) { + lnum = buf->b_ml.ml_line_count; + } + + char_u *str = ml_get_buf(buf, lnum, false); + + if (*str == NUL) { + return 1; + } + + return mb_charlen_len(str, byteidx + 1); +} + +/// Convert the specified character index of line 'lnum' in buffer 'buf' to a +/// byte index. Works only for loaded buffers. Returns -1 on failure. The index +/// of the first byte and the first character is one. +int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) +{ + if (buf == NULL || buf->b_ml.ml_mfp == NULL) { + return -1; + } + + if (lnum > buf->b_ml.ml_line_count) { + lnum = buf->b_ml.ml_line_count; + } + + char_u *str = ml_get_buf(buf, lnum, false); + + // Convert the character offset to a byte offset + char_u *t = str; + while (*t != NUL && --charidx > 0) { + t += utfc_ptr2len(t); + } + + return t - str + 1; +} + /// Translate a VimL object into a position /// /// Accepts VAR_LIST and VAR_STRING objects. Does not give an error for invalid @@ -8159,9 +8205,11 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) /// @param[in] tv Object to translate. /// @param[in] dollar_lnum True when "$" is last line. /// @param[out] ret_fnum Set to fnum for marks. +/// @param[in] charcol True to return character column. /// /// @return Pointer to position or NULL in case of error (e.g. invalid type). -pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret_fnum) +pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret_fnum, + const bool charcol) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { static pos_T pos; @@ -8191,7 +8239,11 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret if (error) { return NULL; } - len = (long)STRLEN(ml_get(pos.lnum)); + if (charcol) { + len = mb_charlen(ml_get(pos.lnum)); + } else { + len = STRLEN(ml_get(pos.lnum)); + } // We accept "$" for the column number: last column. li = tv_list_find(l, 1L); @@ -8222,19 +8274,31 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret return NULL; } if (name[0] == '.') { // Cursor. - return &curwin->w_cursor; + pos = curwin->w_cursor; + if (charcol) { + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col) - 1; + } + return &pos; } if (name[0] == 'v' && name[1] == NUL) { // Visual start. if (VIsual_active) { - return &VIsual; + pos = VIsual; + } else { + pos = curwin->w_cursor; + } + if (charcol) { + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col) - 1; } - return &curwin->w_cursor; + return &pos; } if (name[0] == '\'') { // Mark. pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) { return NULL; } + if (charcol) { + pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col) - 1; + } return pp; } @@ -8260,22 +8324,24 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret pos.col = 0; } else { pos.lnum = curwin->w_cursor.lnum; - pos.col = (colnr_T)STRLEN(get_cursor_line_ptr()); + if (charcol) { + pos.col = (colnr_T)mb_charlen(get_cursor_line_ptr()); + } else { + pos.col = (colnr_T)STRLEN(get_cursor_line_ptr()); + } } return &pos; } return NULL; } -/* - * Convert list in "arg" into a position and optional file number. - * When "fnump" is NULL there is no file number, only 3 items. - * Note that the column is passed on as-is, the caller may want to decrement - * it to use 1 for the first column. - * Return FAIL when conversion is not possible, doesn't check the position for - * validity. - */ -int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp) +/// Convert list in "arg" into a position and optional file number. +/// When "fnump" is NULL there is no file number, only 3 items. +/// Note that the column is passed on as-is, the caller may want to decrement +/// it to use 1 for the first column. +/// Return FAIL when conversion is not possible, doesn't check the position for +/// validity. +int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool charcol) { list_T *l; long i = 0; @@ -8311,6 +8377,15 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp) if (n < 0) { return FAIL; } + // If character position is specified, then convert to byte position + if (charcol) { + // Get the text for the specified line in a loaded buffer + buf_T *buf = buflist_findnr(fnump == NULL ? curbuf->b_fnum : *fnump); + if (buf == NULL || buf->b_ml.ml_mfp == NULL) { + return FAIL; + } + n = buf_charidx_to_byteidx(buf, posp->lnum, n); + } posp->col = n; n = tv_list_find_nr(l, i, NULL); // off -- cgit From d457168e3b6078ae018a2b1fe59ff54f82d3ba14 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Feb 2022 06:48:10 +0800 Subject: vim-patch:8.2.0208: fnamemodify() does not apply ":~" when followed by ":." Problem: Fnamemodify() does not apply ":~" when followed by ":.". Solution: Don't let a failing ":." cause the ":~" to be skipped. (Yasuhiro Matsumoto, closes vim/vim#5577) https://github.com/vim/vim/commit/d816cd94d87afb73c505bf1e5cd5e07522482113 --- src/nvim/eval.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index dccad5a2d0..70909b46cb 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10624,12 +10624,13 @@ int modify_fname(char_u *src, bool tilde_file, size_t *usedlen, char_u **fnamep, char_u *s, *p, *pbuf; char_u dirname[MAXPATHL]; int c; - int has_fullname = 0; + bool has_fullname = false; + bool has_homerelative = false; repeat: // ":p" - full path/file_name if (src[*usedlen] == ':' && src[*usedlen + 1] == 'p') { - has_fullname = 1; + has_fullname = true; valid |= VALID_PATH; *usedlen += 2; @@ -10698,7 +10699,7 @@ repeat: } pbuf = NULL; // Need full path first (use expand_env() to remove a "~/") - if (!has_fullname) { + if (!has_fullname && !has_homerelative) { if (c == '.' && **fnamep == '~') { p = pbuf = expand_env_save(*fnamep); } else { @@ -10708,14 +10709,26 @@ repeat: p = *fnamep; } - has_fullname = 0; + has_fullname = false; if (p != NULL) { if (c == '.') { os_dirname(dirname, MAXPATHL); - s = path_shorten_fname(p, dirname); - if (s != NULL) { - *fnamep = s; + if (has_homerelative) { + s = vim_strsave(dirname); + home_replace(NULL, s, dirname, MAXPATHL, true); + xfree(s); + } + size_t namelen = STRLEN(dirname); + + // Do not call shorten_fname() here since it removes the prefix + // even though the path does not have a prefix. + if (fnamencmp(p, dirname, namelen) == 0) { + p += namelen; + while (*p && vim_ispathsep(*p)) { + ++p; + } + *fnamep = p; if (pbuf != NULL) { xfree(*bufp); // free any allocated file name *bufp = pbuf; @@ -10730,6 +10743,7 @@ repeat: *fnamep = s; xfree(*bufp); *bufp = s; + has_homerelative = true; } } xfree(pbuf); -- cgit From f47ba10636b498430fc8d2d490e5bdf6b4e01033 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Feb 2022 06:48:10 +0800 Subject: vim-patch:8.2.0215: wrong file name shortening Problem: Wrong file name shortening. (Ingo Karkat) Solution: Better check for path separator. (Yasuhiro Matsumoto, closes vim/vim#5583, closes vim/vim#5584) https://github.com/vim/vim/commit/a78e9c61a0ded9c5302bc77e889aa1b3d3467f61 --- src/nvim/eval.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 70909b46cb..0fe928beb7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10725,14 +10725,17 @@ repeat: // even though the path does not have a prefix. if (fnamencmp(p, dirname, namelen) == 0) { p += namelen; - while (*p && vim_ispathsep(*p)) { - ++p; - } - *fnamep = p; - if (pbuf != NULL) { - xfree(*bufp); // free any allocated file name - *bufp = pbuf; - pbuf = NULL; + if (vim_ispathsep(*p)) { + while (*p && vim_ispathsep(*p)) { + p++; + } + *fnamep = p; + if (pbuf != NULL) { + // free any allocated file name + xfree(*bufp); + *bufp = pbuf; + pbuf = NULL; + } } } } else { -- cgit From 53e4434c722d94f9c49dee2fd787d05d36a46bf3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Feb 2022 06:48:10 +0800 Subject: vim-patch:8.2.0942: expanding to local dir after homedir keeps "~/" Problem: Expanding to local dir after homedir keeps "~/". Solution: Adjust modify_fname(). (Christian Brabandt, closes vim/vim#6205, closes vim/vim#5979) https://github.com/vim/vim/commit/0e390f40e944036fb558a63b91238cfda128d95f --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0fe928beb7..926c385892 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10700,7 +10700,7 @@ repeat: pbuf = NULL; // Need full path first (use expand_env() to remove a "~/") if (!has_fullname && !has_homerelative) { - if (c == '.' && **fnamep == '~') { + if ((c == '.' || c == '~') && **fnamep == '~') { p = pbuf = expand_env_save(*fnamep); } else { p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE); -- cgit From aff0ddd784bed586e359fc4b16e86ab214cf6039 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 9 Feb 2022 18:55:01 +0100 Subject: vim-patch:8.2.4337: part of condition is always true (#17352) Problem: Part of condition is always true. Solution: Remove that part of the condition. (closes vim/vim#9729) https://github.com/vim/vim/commit/78a8404f8b6ad0152614d5fdc3ec277444c1eee5 --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 926c385892..c197754685 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10700,7 +10700,7 @@ repeat: pbuf = NULL; // Need full path first (use expand_env() to remove a "~/") if (!has_fullname && !has_homerelative) { - if ((c == '.' || c == '~') && **fnamep == '~') { + if (**fnamep == '~') { p = pbuf = expand_env_save(*fnamep); } else { p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE); -- cgit From cdb2c100118ab788772a6a0a1d60f555370fd201 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 1 Feb 2022 12:44:14 +0000 Subject: vim-patch:8.2.0915: search() cannot skip over matches like searchpair() can Problem: Search() cannot skip over matches like searchpair() can. Solution: Add an optional "skip" argument. (Christian Brabandt, closes vim/vim#861) https://github.com/vim/vim/commit/adc17a5f9d207fd1623fd923457a46efc9214777 Enable skip arg usage in autoload/freebasic.vim evalarg_T doesn't really matter because it's deleted in v8.2.0918 (and reincarnated for Vim9 script in v8.2.1047), but I found out too late :P Anyway: - Port evalarg_T into eval.h and use const char * and Callback fields - Use EVALARG_INIT to initialize - Return bool over OK/FAIL from evalarg functions - Remove check from evalarg_clean as callback_free ignores None callbacks anyway - Move eva_buf field into evalarg_get as a local (not sure what reason it has being in the struct) N/A patches for version.c: vim-patch:8.2.4355: unnecessary call to check_colorcolumn() Problem: Unnecessary call to check_colorcolumn(). Solution: Remove the call. (Sean Dewar, closes vim/vim#9748) https://github.com/vim/vim/commit/0f7ff851cb721bb3c07261adbf82b591229f530d --- src/nvim/eval.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c197754685..2d8d1694d1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3381,6 +3381,67 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, return ret; } +/// Process a function argument that can be a string expression or a function +/// reference. +/// "tv" must remain valid until calling evalarg_clean()! +/// @return false when the argument is invalid. +bool evalarg_get(typval_T *const tv, evalarg_T *const eva) + FUNC_ATTR_NONNULL_ALL +{ + if (tv->v_type == VAR_STRING || tv->v_type == VAR_NUMBER || tv->v_type == VAR_BOOL + || tv->v_type == VAR_SPECIAL) { + char numbuf[NUMBUFLEN]; + eva->eva_string = tv_get_string_buf(tv, numbuf); + return true; + } + + return callback_from_typval(&eva->eva_callback, tv); +} + +/// @return whether "eva" has a valid expression or callback. +bool evalarg_valid(const evalarg_T *const eva) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_CONST +{ + return eva->eva_string != NULL || eva->eva_callback.type != kCallbackNone; +} + +/// Invoke the expression or callback "eva" and return the result in "tv". +/// @return false if something failed +bool evalarg_call(evalarg_T *const eva, typval_T *const tv) + FUNC_ATTR_NONNULL_ALL +{ + if (eva->eva_string != NULL) { + return eval0((char_u *)eva->eva_string, tv, NULL, true); + } + + typval_T argv[1]; + argv[0].v_type = VAR_UNKNOWN; + return callback_call(&eva->eva_callback, 0, argv, tv); +} + +/// Like evalarg_call(), but just return true or false. +/// Sets "error" to true if evaluation failed. +bool evalarg_call_bool(evalarg_T *const eva, bool *const error) + FUNC_ATTR_NONNULL_ALL +{ + typval_T tv; + if (!evalarg_call(eva, &tv)) { + *error = true; + return false; + } + + const bool r = tv_get_number(&tv); + tv_clear(&tv); + *error = false; + return r; +} + +void evalarg_clean(evalarg_T *const eva) + FUNC_ATTR_NONNULL_ALL +{ + callback_free(&eva->eva_callback); +} + // TODO(ZyX-I): move to eval/expressions /* -- cgit From 0511a31ca28e76b12c05622719fc6797d59fb19a Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 1 Feb 2022 15:07:33 +0000 Subject: vim-patch:8.2.0918: duplicate code for evaluating expression argument Problem: Duplicate code for evaluating expression argument. Solution: Merge the code and make the use more flexible. https://github.com/vim/vim/commit/a9c010494767e43a51c443cac35ebc80d0831d0b --- src/nvim/eval.c | 70 ++++++++------------------------------------------------- 1 file changed, 9 insertions(+), 61 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2d8d1694d1..4b83bda804 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -766,6 +766,15 @@ static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) return ret; } +/// @return whether a typval is a valid expression to pass to eval_expr_typval() +/// or eval_expr_to_bool(). An empty string returns false; +bool eval_expr_valid_arg(const typval_T *const tv) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_CONST +{ + return tv->v_type != VAR_UNKNOWN + && (tv->v_type != VAR_STRING || (tv->vval.v_string != NULL && *tv->vval.v_string != NUL)); +} + int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *rettv) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { @@ -3381,67 +3390,6 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, return ret; } -/// Process a function argument that can be a string expression or a function -/// reference. -/// "tv" must remain valid until calling evalarg_clean()! -/// @return false when the argument is invalid. -bool evalarg_get(typval_T *const tv, evalarg_T *const eva) - FUNC_ATTR_NONNULL_ALL -{ - if (tv->v_type == VAR_STRING || tv->v_type == VAR_NUMBER || tv->v_type == VAR_BOOL - || tv->v_type == VAR_SPECIAL) { - char numbuf[NUMBUFLEN]; - eva->eva_string = tv_get_string_buf(tv, numbuf); - return true; - } - - return callback_from_typval(&eva->eva_callback, tv); -} - -/// @return whether "eva" has a valid expression or callback. -bool evalarg_valid(const evalarg_T *const eva) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_CONST -{ - return eva->eva_string != NULL || eva->eva_callback.type != kCallbackNone; -} - -/// Invoke the expression or callback "eva" and return the result in "tv". -/// @return false if something failed -bool evalarg_call(evalarg_T *const eva, typval_T *const tv) - FUNC_ATTR_NONNULL_ALL -{ - if (eva->eva_string != NULL) { - return eval0((char_u *)eva->eva_string, tv, NULL, true); - } - - typval_T argv[1]; - argv[0].v_type = VAR_UNKNOWN; - return callback_call(&eva->eva_callback, 0, argv, tv); -} - -/// Like evalarg_call(), but just return true or false. -/// Sets "error" to true if evaluation failed. -bool evalarg_call_bool(evalarg_T *const eva, bool *const error) - FUNC_ATTR_NONNULL_ALL -{ - typval_T tv; - if (!evalarg_call(eva, &tv)) { - *error = true; - return false; - } - - const bool r = tv_get_number(&tv); - tv_clear(&tv); - *error = false; - return r; -} - -void evalarg_clean(evalarg_T *const eva) - FUNC_ATTR_NONNULL_ALL -{ - callback_free(&eva->eva_callback); -} - // TODO(ZyX-I): move to eval/expressions /* -- cgit From ed169d89979caf8e67dbdf74491367d2e0cfad58 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Feb 2022 21:25:44 +0800 Subject: vim-patch:8.2.2342: "char" functions may return wrong column in Insert mode Problem: "char" functions return the wront column in Insert mode when the cursor is beyond the end of the line. Solution: Compute the column correctly. (Yegappan Lakshmanan, closes vim/vim#7669) https://github.com/vim/vim/commit/9145846b6aa411e3ab5c0d145b37808654352877 --- src/nvim/eval.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4b83bda804..07f0799bc4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8192,7 +8192,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) /// Convert the specified byte index of line 'lnum' in buffer 'buf' to a /// character index. Works only for loaded buffers. Returns -1 on failure. -/// The index of the first character is one. +/// The index of the first byte and the first character is zero. int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) { if (buf == NULL || buf->b_ml.ml_mfp == NULL) { @@ -8206,15 +8206,29 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) char_u *str = ml_get_buf(buf, lnum, false); if (*str == NUL) { - return 1; + return 0; + } + + // count the number of characters + char_u *t = str; + int count; + for (count = 0; *t != NUL && t <= str + byteidx; count++) { + t += utfc_ptr2len(t); + } + + // In insert mode, when the cursor is at the end of a non-empty line, + // byteidx points to the NUL character immediately past the end of the + // string. In this case, add one to the character count. + if (*t == NUL && byteidx != 0 && t == str + byteidx) { + count++; } - return mb_charlen_len(str, byteidx + 1); + return count - 1; } /// Convert the specified character index of line 'lnum' in buffer 'buf' to a -/// byte index. Works only for loaded buffers. Returns -1 on failure. The index -/// of the first byte and the first character is one. +/// byte index. Works only for loaded buffers. Returns -1 on failure. +/// The index of the first byte and the first character is zero. int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) { if (buf == NULL || buf->b_ml.ml_mfp == NULL) { @@ -8233,7 +8247,7 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) t += utfc_ptr2len(t); } - return t - str + 1; + return t - str; } /// Translate a VimL object into a position @@ -8315,7 +8329,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret if (name[0] == '.') { // Cursor. pos = curwin->w_cursor; if (charcol) { - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col) - 1; + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); } return &pos; } @@ -8326,7 +8340,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret pos = curwin->w_cursor; } if (charcol) { - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col) - 1; + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); } return &pos; } @@ -8336,7 +8350,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret return NULL; } if (charcol) { - pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col) - 1; + pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col); } return pp; } @@ -8423,7 +8437,7 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c if (buf == NULL || buf->b_ml.ml_mfp == NULL) { return FAIL; } - n = buf_charidx_to_byteidx(buf, posp->lnum, n); + n = buf_charidx_to_byteidx(buf, posp->lnum, n) + 1; } posp->col = n; -- cgit From 991e472881bf29805982b402c1a010cde051ded3 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 28 May 2021 15:45:34 -0400 Subject: feat(lua): add api and lua autocmds --- src/nvim/eval.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 07f0799bc4..0322898827 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6,6 +6,7 @@ */ #include +#include #include "auto/config.h" @@ -3258,7 +3259,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) // b: variables // In cmdwin, the alternative buffer should be used. hashtab_T *ht - = is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab; + = is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab; if (bdone < ht->ht_used) { if (bdone++ == 0) { hi = ht->ht_array; @@ -7746,6 +7747,7 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) callback->type = kCallbackFuncref; } } else if (nlua_is_table_from_lua(arg)) { + // TODO(tjdvries): UnifiedCallback char_u *name = nlua_register_table_as_callable(arg); if (name != NULL) { @@ -7775,6 +7777,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co { partial_T *partial; char_u *name; + Array args = ARRAY_DICT_INIT; switch (callback->type) { case kCallbackFuncref: name = callback->data.funcref; @@ -7786,6 +7789,13 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co name = partial_name(partial); break; + case kCallbackLua: + ILOG(" We tryin to call dat dang lua ref "); + nlua_call_ref(callback->data.luaref, "aucmd", args, false, NULL); + + return false; + break; + case kCallbackNone: return false; break; -- cgit From 7b6ee3ef0a2d64657c8ca25f440e010c6dc75408 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 17 Feb 2022 12:53:17 +0600 Subject: fix: anonymous sid not working --- src/nvim/eval.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0322898827..d95b9560c2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9369,10 +9369,31 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, cons } else if (*name == 'l' && funccal != NULL) { // local variable *d = &funccal->l_vars; } else if (*name == 's' // script variable - && (current_sctx.sc_sid > 0 || current_sctx.sc_sid == SID_STR) + && (current_sctx.sc_sid > 0 || current_sctx.sc_sid == SID_STR + || current_sctx.sc_sid == SID_LUA) && current_sctx.sc_sid <= ga_scripts.ga_len) { // For anonymous scripts without a script item, create one now so script vars can be used - if (current_sctx.sc_sid == SID_STR) { + if (current_sctx.sc_sid == SID_LUA) { + // try to resolve lua filename & line no so it can be shown in lastset messages. + nlua_set_sctx(¤t_sctx); + if (current_sctx.sc_sid != SID_LUA) { + // Great we have valid location. Now here this out we'll create a new + // script context with the name and lineno of this one. why ? + // for behavioral consistency. With this different anonymous exec from + // same file can't access each others script local stuff. We need to do + // this all other cases except this will act like that otherwise. + const LastSet last_set = (LastSet){ + .script_ctx = current_sctx, + .channel_id = LUA_INTERNAL_CALL, + }; + bool should_free; + // should_free is ignored as script_sctx will be resolved to a fnmae + // & new_script_item will consume it. + char_u *sc_name = get_scriptname(last_set, &should_free); + new_script_item(sc_name, ¤t_sctx.sc_sid); + } + } + if (current_sctx.sc_sid == SID_STR || current_sctx.sc_sid == SID_LUA) { new_script_item(NULL, ¤t_sctx.sc_sid); } *d = &SCRIPT_SV(current_sctx.sc_sid)->sv_dict; -- cgit From 4d2744ffe30c785ff19624831e36d01e3f6a6089 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sun, 27 Feb 2022 12:29:33 +0100 Subject: refactor: fix clang-tidy bugprone-signed-char-misuse warnings Prefer to declare variables with correct type instead of explicit casts wherever possible. --- src/nvim/eval.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d95b9560c2..c5c03455b7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4858,7 +4858,6 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval long numval; char_u *stringval; int opt_type; - int c; bool working = (**arg == '+'); // has("+option") int ret = OK; int opt_flags; @@ -4877,7 +4876,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval return OK; } - c = *option_end; + char c = *option_end; *option_end = NUL; opt_type = get_option_value(*arg, &numval, rettv == NULL ? NULL : &stringval, opt_flags); -- cgit From ff032f2710974dcf5930187f1925534da93db199 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sun, 6 Mar 2022 12:40:31 +0100 Subject: refactor: remove redundant casts --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c5c03455b7..aa7b9e80a4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9441,7 +9441,7 @@ void new_script_vars(scid_T id) hashtab_T *ht; scriptvar_T *sv; - ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)); + ga_grow(&ga_scripts, id - ga_scripts.ga_len); { /* Re-allocating ga_data means that an ht_array pointing to * ht_smallarray becomes invalid. We can recognize this: ht_mask is -- cgit From bce1fd221814c705e8ad8172f8839305e0633127 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 8 Mar 2022 12:56:45 +0100 Subject: chore(aucmd): remove left-over debug log (#17649) --- src/nvim/eval.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c5c03455b7..81432fefd3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7789,7 +7789,6 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co break; case kCallbackLua: - ILOG(" We tryin to call dat dang lua ref "); nlua_call_ref(callback->data.luaref, "aucmd", args, false, NULL); return false; -- cgit From 4f007a7f651ccd052f299000b49b9a389f713725 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 8 Mar 2022 11:27:11 -0500 Subject: fix: do not pass aucmd to the callback (#17650) --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 81432fefd3..2ec748a217 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7789,7 +7789,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co break; case kCallbackLua: - nlua_call_ref(callback->data.luaref, "aucmd", args, false, NULL); + nlua_call_ref(callback->data.luaref, NULL, args, false, NULL); return false; break; -- cgit From 7e3bdc75e44b9139d8afaea4381b53ae78b15746 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Wed, 9 Mar 2022 21:19:37 +0100 Subject: refactor(uncrustify): format all c files --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8cdb03c341..83223cdd5c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2710,7 +2710,7 @@ bool next_for_item(void *fi_void, char_u *arg) tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len); fi->fi_byte_idx += len; const int result - = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; + = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; xfree(tv.vval.v_string); return result; } -- cgit From 6c26ab71ceb9f4f12c55492ba7ab33a5e61af079 Mon Sep 17 00:00:00 2001 From: VVKot Date: Sun, 19 Dec 2021 07:46:28 +0000 Subject: vim-patch:8.1.0892: failure when closing a window when location list is in use Problem: Failure when closing a window when location list is in use. Solution: Handle the situation gracefully. Make sure memory for 'switchbuf' is not freed at the wrong time. (Yegappan Lakshmanan, closes vim/vim#3928) https://github.com/vim/vim/commit/eeb1b9c7ed33c152e041a286d79bf3ed00d80e40 --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 83223cdd5c..18b9039d60 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6436,7 +6436,7 @@ win_T *find_win_by_nr_or_id(typval_T *vp) int nr = (int)tv_get_number_chk(vp, NULL); if (nr >= LOWEST_WIN_ID) { - return win_id2wp(vp); + return win_id2wp(tv_get_number(vp)); } return find_win_by_nr(vp, NULL); -- cgit From 880d3537d06ef067021c73bc361fa47ab8347992 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 21 Feb 2022 10:55:36 +0000 Subject: vim-patch:8.2.4428: crash when switching tabpage while in the cmdline window Problem: Crash when switching tabpage while in the cmdline window. Solution: Disallow switching tabpage when in the cmdline window. https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1 Ensure cmdline window doesn't stop us from closing tabs with EXITFREE. mem_free_all -> win_free_all -> tabpage_close -> ... -> goto_tabpage_tp -> CHECK_CMDWIN can cause an infinite loop if Nvim is exited without using standard methods such as :qa! and friends (e.g: killed via a signal). This issue had caused the ASAN CI's functionaltests to timeout. Cherry-pick Test_cmdwin_tabpage from v8.2.4463. https://github.com/vim/vim/commit/38b85cb4d7216705058708bacbc25ab90cd61595 This bug was already fixed in Nvim. Note that g inside cmdwin is already tested for in tabnewentered_spec.lua anyway. E492 is thrown after E11 when using ":norm" in assert_fails for some reason (except after v8.2.1919, which isn't ported yet). As v8.2.1183 isn't ported yet, so we cannot assert E11 directly. Modify the test to check for E11 and E492 seperately; when v8.2.1183 is ported, the assertion for E492 will fail and the changes can be reverted to match upstream. Remove redundant CHECK_CMDWIN from goto_tabpage; it's handled with text_locked() and text_locked_msg() above: vim-patch:8.2.4434: duplicate check for cmdline window Problem: Duplicate check for cmdline window. Solution: Remove the second check. (Sean Dewar, closes vim/vim#9816) https://github.com/vim/vim/commit/16b51d26fe2cc3afb09afd439069220dea74581d --- src/nvim/eval.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 18b9039d60..b2ce15fd87 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3257,9 +3257,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) } // b: variables - // In cmdwin, the alternative buffer should be used. - hashtab_T *ht - = is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab; + const hashtab_T *ht = &prevwin_curwin()->w_buffer->b_vars->dv_hashtab; if (bdone < ht->ht_used) { if (bdone++ == 0) { hi = ht->ht_array; @@ -3273,8 +3271,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) } // w: variables - // In cmdwin, the alternative window should be used. - ht = is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab : &curwin->w_vars->dv_hashtab; + ht = &prevwin_curwin()->w_vars->dv_hashtab; if (wdone < ht->ht_used) { if (wdone++ == 0) { hi = ht->ht_array; -- cgit From 378db4f32ab004eb5e37a7bac4f3ca132cf1ac98 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sun, 13 Mar 2022 16:21:44 +0100 Subject: refactor(eval): convert function comments to doxygen format --- src/nvim/eval.c | 848 +++++++++++++++++++++++++------------------------------- 1 file changed, 378 insertions(+), 470 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 18b9039d60..464e408efa 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -331,7 +331,7 @@ void restore_v_event(dict_T *v_event, save_v_event_T *sve) } } -// Return "n1" divided by "n2", taking care of dividing by zero. +/// @return "n1" divided by "n2", taking care of dividing by zero. varnumber_T num_divide(varnumber_T n1, varnumber_T n2) FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT { @@ -352,7 +352,7 @@ varnumber_T num_divide(varnumber_T n1, varnumber_T n2) return result; } -// Return "n1" modulus "n2", taking care of dividing by zero. +/// @return "n1" modulus "n2", taking care of dividing by zero. varnumber_T num_modulus(varnumber_T n1, varnumber_T n2) FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT { @@ -360,9 +360,7 @@ varnumber_T num_modulus(varnumber_T n1, varnumber_T n2) return (n2 == 0) ? 0 : (n1 % n2); } -/* - * Initialize the global and v: variables. - */ +/// Initialize the global and v: variables. void eval_init(void) { vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; @@ -502,10 +500,8 @@ void eval_clear(void) #endif -/* - * Set an internal variable to a string value. Creates the variable if it does - * not already exist. - */ +/// Set an internal variable to a string value. Creates the variable if it does +/// not already exist. void set_internal_string_var(const char *name, char_u *value) FUNC_ATTR_NONNULL_ARG(1) { @@ -523,9 +519,10 @@ static char_u *redir_endp = NULL; static char_u *redir_varname = NULL; /// Start recording command output to a variable -/// Returns OK if successfully completed the setup. FAIL otherwise. /// /// @param append append to an existing variable +/// +/// @return OK if successfully completed the setup. FAIL otherwise. int var_redir_start(char_u *name, int append) { int save_emsg; @@ -586,15 +583,13 @@ int var_redir_start(char_u *name, int append) return OK; } -/* - * Append "value[value_len]" to the variable set by var_redir_start(). - * The actual appending is postponed until redirection ends, because the value - * appended may in fact be the string we write to, changing it may cause freed - * memory to be used: - * :redir => foo - * :let foo - * :redir END - */ +/// Append "value[value_len]" to the variable set by var_redir_start(). +/// The actual appending is postponed until redirection ends, because the value +/// appended may in fact be the string we write to, changing it may cause freed +/// memory to be used: +/// :redir => foo +/// :let foo +/// :redir END void var_redir_str(char_u *value, int value_len) { int len; @@ -614,10 +609,8 @@ void var_redir_str(char_u *value, int value_len) redir_ga.ga_len += len; } -/* - * Stop redirecting command output to a variable. - * Frees the allocated memory. - */ +/// Stop redirecting command output to a variable. +/// Frees the allocated memory. void var_redir_stop(void) { typval_T tv; @@ -744,7 +737,7 @@ int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) return retval; } -// Call eval1() and give an error message if not done at a lower level. +/// Call eval1() and give an error message if not done at a lower level. static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) FUNC_ATTR_NONNULL_ARG(1, 2) { @@ -767,8 +760,8 @@ static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) return ret; } -/// @return whether a typval is a valid expression to pass to eval_expr_typval() -/// or eval_expr_to_bool(). An empty string returns false; +/// @return whether a typval is a valid expression to pass to eval_expr_typval() +/// or eval_expr_to_bool(). An empty string returns false; bool eval_expr_valid_arg(const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_CONST { @@ -867,10 +860,9 @@ char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip return retval; } -/* - * Skip over an expression at "*pp". - * Return FAIL for an error, OK otherwise. - */ +/// Skip over an expression at "*pp". +/// +/// @return FAIL for an error, OK otherwise. int skip_expr(char_u **pp) { typval_T rettv; @@ -917,10 +909,10 @@ char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) return (char_u *)retval; } -/* - * Call eval_to_string() without using current local variables and using - * textlock. When "use_sandbox" is TRUE use the sandbox. - */ +/// Call eval_to_string() without using current local variables and using +/// textlock. +/// +/// @param use_sandbox when TRUE, use the sandbox. char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) { char_u *retval; @@ -940,11 +932,10 @@ char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) return retval; } -/* - * Top level evaluation function, returning a number. - * Evaluates "expr" silently. - * Returns -1 for an error. - */ +/// Top level evaluation function, returning a number. +/// Evaluates "expr" silently. +/// +/// @return -1 for an error. varnumber_T eval_to_number(char_u *expr) { typval_T rettv; @@ -964,9 +955,10 @@ varnumber_T eval_to_number(char_u *expr) return retval; } -// Top level evaluation function. -// Returns an allocated typval_T with the result. -// Returns NULL when there is an error. +/// Top level evaluation function. +/// +/// @return an allocated typval_T with the result or +/// NULL when there is an error. typval_T *eval_expr(char_u *arg) { typval_T *tv = xmalloc(sizeof(*tv)); @@ -976,11 +968,9 @@ typval_T *eval_expr(char_u *arg) return tv; } -/* - * Prepare v: variable "idx" to be used. - * Save the current typeval in "save_tv". - * When not used yet add the variable to the v: hashtable. - */ +/// Prepare v: variable "idx" to be used. +/// Save the current typeval in "save_tv". +/// When not used yet add the variable to the v: hashtable. void prepare_vimvar(int idx, typval_T *save_tv) { *save_tv = vimvars[idx].vv_tv; @@ -989,10 +979,8 @@ void prepare_vimvar(int idx, typval_T *save_tv) } } -/* - * Restore v: variable "idx" to typeval "save_tv". - * When no longer defined, remove the variable from the v: hashtable. - */ +/// Restore v: variable "idx" to typeval "save_tv". +/// When no longer defined, remove the variable from the v: hashtable. void restore_vimvar(int idx, typval_T *save_tv) { hashitem_T *hi; @@ -1019,11 +1007,10 @@ void find_win_for_curbuf(void) } } -/* - * Evaluate an expression to a list with suggestions. - * For the "expr:" part of 'spellsuggest'. - * Returns NULL when there is an error. - */ +/// Evaluate an expression to a list with suggestions. +/// For the "expr:" part of 'spellsuggest'. +/// +/// @return NULL when there is an error. list_T *eval_spell_expr(char_u *badword, char_u *expr) { typval_T save_val; @@ -1087,7 +1074,7 @@ int get_spellword(list_T *const list, const char **ret_word) // Uses argv[0] to argv[argc-1] for the function arguments. argv[argc] // should have type VAR_UNKNOWN. // -// Return OK or FAIL. +// @return OK or FAIL. int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *rettv) FUNC_ATTR_NONNULL_ALL { @@ -1225,10 +1212,8 @@ void prof_child_exit(proftime_T *tm) } -/* - * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding - * it in "*cp". Doesn't give error messages. - */ +/// Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding +/// it in "*cp". Doesn't give error messages. int eval_foldexpr(char_u *arg, int *cp) { typval_T tv; @@ -1269,26 +1254,27 @@ int eval_foldexpr(char_u *arg, int *cp) return (int)retval; } -// ":cons[t] var = expr1" define constant -// ":cons[t] [name1, name2, ...] = expr1" define constants unpacking list -// ":cons[t] [name, ..., ; lastname] = expr" define constants unpacking list +/// ":cons[t] var = expr1" define constant +/// ":cons[t] [name1, name2, ...] = expr1" define constants unpacking list +/// ":cons[t] [name, ..., ; lastname] = expr" define constants unpacking list void ex_const(exarg_T *eap) { ex_let_const(eap, true); } -// Get a list of lines from a HERE document. The here document is a list of -// lines surrounded by a marker. -// cmd << {marker} -// {line1} -// {line2} -// .... -// {marker} -// -// The {marker} is a string. If the optional 'trim' word is supplied before the -// marker, then the leading indentation before the lines (matching the -// indentation in the 'cmd' line) is stripped. -// Returns a List with {lines} or NULL. +/// Get a list of lines from a HERE document. The here document is a list of +/// lines surrounded by a marker. +/// cmd << {marker} +/// {line1} +/// {line2} +/// .... +/// {marker} +/// +/// The {marker} is a string. If the optional 'trim' word is supplied before the +/// marker, then the leading indentation before the lines (matching the +/// indentation in the 'cmd' line) is stripped. +/// +/// @return a List with {lines} or NULL. static list_T *heredoc_get(exarg_T *eap, char_u *cmd) { char_u *marker; @@ -1386,18 +1372,18 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) return l; } -// ":let" list all variable values -// ":let var1 var2" list variable values -// ":let var = expr" assignment command. -// ":let var += expr" assignment command. -// ":let var -= expr" assignment command. -// ":let var *= expr" assignment command. -// ":let var /= expr" assignment command. -// ":let var %= expr" assignment command. -// ":let var .= expr" assignment command. -// ":let var ..= expr" assignment command. -// ":let [var1, var2] = expr" unpack list. -// ":let [name, ..., ; lastname] = expr" unpack list. +/// ":let" list all variable values +/// ":let var1 var2" list variable values +/// ":let var = expr" assignment command. +/// ":let var += expr" assignment command. +/// ":let var -= expr" assignment command. +/// ":let var *= expr" assignment command. +/// ":let var /= expr" assignment command. +/// ":let var %= expr" assignment command. +/// ":let var .= expr" assignment command. +/// ":let var ..= expr" assignment command. +/// ":let [var1, var2] = expr" unpack list. +/// ":let [name, ..., ; lastname] = expr" unpack list. void ex_let(exarg_T *eap) { ex_let_const(eap, false); @@ -1578,13 +1564,12 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, return OK; } -/* - * Skip over assignable variable "var" or list of variables "[var, var]". - * Used for ":let varvar = expr" and ":for varvar in expr". - * For "[var, var]" increment "*var_count" for each variable. - * for "[var, var; var]" set "semicolon". - * Return NULL for an error. - */ +/// Skip over assignable variable "var" or list of variables "[var, var]". +/// Used for ":let varvar = expr" and ":for varvar in expr". +/// For "[var, var]" increment "*var_count" for each variable. +/// for "[var, var; var]" set "semicolon". +/// +/// @return NULL for an error. static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semicolon) { const char_u *p; @@ -1622,10 +1607,8 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semic } } -/* - * Skip one (assignable) variable name, including @r, $VAR, &option, d.key, - * l[idx]. - */ +/// Skip one (assignable) variable name, including @r, $VAR, &option, d.key, +/// l[idx]. static const char_u *skip_var_one(const char_u *arg) { if (*arg == '@' && arg[1] != NUL) { @@ -1635,10 +1618,9 @@ static const char_u *skip_var_one(const char_u *arg) NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); } -/* - * List variables for hashtab "ht" with prefix "prefix". - * If "empty" is TRUE also list NULL strings as empty strings. - */ +/// List variables for hashtab "ht" with prefix "prefix". +/// +/// @param empty if TRUE also list NULL strings as empty strings. void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, int *first) { hashitem_T *hi; @@ -1667,47 +1649,37 @@ void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, int *firs } } -/* - * List global variables. - */ +/// List global variables. static void list_glob_vars(int *first) { list_hashtable_vars(&globvarht, "", true, first); } -/* - * List buffer variables. - */ +/// List buffer variables. static void list_buf_vars(int *first) { list_hashtable_vars(&curbuf->b_vars->dv_hashtab, "b:", true, first); } -/* - * List window variables. - */ +/// List window variables. static void list_win_vars(int *first) { list_hashtable_vars(&curwin->w_vars->dv_hashtab, "w:", true, first); } -/* - * List tab page variables. - */ +/// List tab page variables. static void list_tab_vars(int *first) { list_hashtable_vars(&curtab->tp_vars->dv_hashtab, "t:", true, first); } -/* - * List Vim variables. - */ +/// List Vim variables. static void list_vim_vars(int *first) { list_hashtable_vars(&vimvarht, "v:", false, first); } -// List script-local variables, if there is a script. +/// List script-local variables, if there is a script. static void list_script_vars(int *first) { if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) { @@ -1715,9 +1687,7 @@ static void list_script_vars(int *first) } } -/* - * List variables in "arg". - */ +/// List variables in "arg". static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) { int error = FALSE; @@ -2380,9 +2350,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co // TODO(ZyX-I): move to eval/executor -/* - * Clear lval "lp" that was filled by get_lval(). - */ +/// Clear lval "lp" that was filled by get_lval(). void clear_lval(lval_T *lp) { xfree(lp->ll_exp_name); @@ -2391,12 +2359,11 @@ void clear_lval(lval_T *lp) // TODO(ZyX-I): move to eval/executor -/* - * Set a variable that was parsed by get_lval() to "rettv". - * "endp" points to just after the parsed name. - * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", - * "%" for "%=", "." for ".=" or "=" for "=". - */ +/// Set a variable that was parsed by get_lval() to "rettv". +/// +/// @param endp points to just after the parsed name. +/// @param op NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", +/// "%" for "%=", "." for ".=" or "=" for "=". static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, const bool is_const, const char *op) { @@ -2599,12 +2566,12 @@ notify: // TODO(ZyX-I): move to eval/ex_cmds -/* - * Evaluate the expression used in a ":for var in expr" command. - * "arg" points to "var". - * Set "*errp" to TRUE for an error, FALSE otherwise; - * Return a pointer that holds the info. Null when there is an error. - */ +/// Evaluate the expression used in a ":for var in expr" command. +/// "arg" points to "var". +/// +/// @param[out] *errp set to TRUE for an error, FALSE otherwise; +/// +/// @return a pointer that holds the info. Null when there is an error. void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) { forinfo_T *fi = xcalloc(1, sizeof(forinfo_T)); @@ -2676,12 +2643,11 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) // TODO(ZyX-I): move to eval/ex_cmds -/* - * Use the first item in a ":for" list. Advance to the next. - * Assign the values to the variable (list). "arg" points to the first one. - * Return TRUE when a valid item was found, FALSE when at end of list or - * something wrong. - */ +/// Use the first item in a ":for" list. Advance to the next. +/// Assign the values to the variable (list). "arg" points to the first one. +/// +/// @return true when a valid item was found, false when at end of list or +/// something wrong. bool next_for_item(void *fi_void, char_u *arg) { forinfo_T *fi = (forinfo_T *)fi_void; @@ -2727,9 +2693,7 @@ bool next_for_item(void *fi_void, char_u *arg) // TODO(ZyX-I): move to eval/ex_cmds -/* - * Free the structure used to store info used by ":for". - */ +/// Free the structure used to store info used by ":for". void free_for_info(void *fi_void) { forinfo_T *fi = (forinfo_T *)fi_void; @@ -3178,9 +3142,7 @@ static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, exarg_T *e return ret; } -/* - * Delete all "menutrans_" variables. - */ +/// Delete all "menutrans_" variables. void del_menutrans_vars(void) { hash_lock(&globvarht); @@ -3202,9 +3164,7 @@ void del_menutrans_vars(void) static char_u *varnamebuf = NULL; static size_t varnamebuflen = 0; -/* - * Function to concatenate a prefix and a variable name. - */ +/// Function to concatenate a prefix and a variable name. char_u *cat_prefix_varname(int prefix, const char_u *name) FUNC_ATTR_NONNULL_ALL { @@ -3222,10 +3182,8 @@ char_u *cat_prefix_varname(int prefix, const char_u *name) return varnamebuf; } -/* - * Function given to ExpandGeneric() to obtain the list of user defined - * (global/buffer/window/built-in) variable names. - */ +/// Function given to ExpandGeneric() to obtain the list of user defined +/// (global/buffer/window/built-in) variable names. char_u *get_user_var_name(expand_T *xp, int idx) { static size_t gdone; @@ -3313,8 +3271,9 @@ char_u *get_user_var_name(expand_T *xp, int idx) // TODO(ZyX-I): move to eval/expressions -/// Return TRUE if "pat" matches "text". /// Does not use 'cpo' and always uses 'magic'. +/// +/// @return TRUE if "pat" matches "text". static int pattern_match(char_u *pat, char_u *text, bool ic) { int matches = 0; @@ -3335,10 +3294,10 @@ static int pattern_match(char_u *pat, char_u *text, bool ic) /// Handle a name followed by "(". Both for just "name(arg)" and for /// "expr->name(arg)". -// +/// /// @param arg Points to "(", will be advanced /// @param basetv "expr" for "expr->name(arg)" -// +/// /// @return OK or FAIL. static int eval_func(char_u **const arg, char_u *const name, const int name_len, typval_T *const rettv, const bool evaluate, typval_T *const basetv) @@ -3399,13 +3358,12 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, * VAR_UNKNOWN. The function still returns FAIL for a syntax error. */ -/* - * Handle zero level expression. - * This calls eval1() and handles error message and nextcmd. - * Put the result in "rettv" when returning OK and "evaluate" is TRUE. - * Note: "rettv.v_lock" is not set. - * Return OK or FAIL. - */ +/// Handle zero level expression. +/// This calls eval1() and handles error message and nextcmd. +/// Put the result in "rettv" when returning OK and "evaluate" is TRUE. +/// Note: "rettv.v_lock" is not set. +/// +/// @return OK or FAIL. int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) { int ret; @@ -3438,17 +3396,15 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) // TODO(ZyX-I): move to eval/expressions -/* - * Handle top level expression: - * expr2 ? expr1 : expr1 - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Note: "rettv.v_lock" is not set. - * - * Return OK or FAIL. - */ +/// Handle top level expression: +/// expr2 ? expr1 : expr1 +/// +/// "arg" must point to the first non-white of the expression. +/// "arg" is advanced to the next non-white after the recognized expression. +/// +/// Note: "rettv.v_lock" is not set. +/// +/// @return OK or FAIL. int eval1(char_u **arg, typval_T *rettv, int evaluate) { int result; @@ -3514,15 +3470,13 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) // TODO(ZyX-I): move to eval/expressions -/* - * Handle first level expression: - * expr2 || expr2 || expr2 logical OR - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Return OK or FAIL. - */ +/// Handle first level expression: +/// expr2 || expr2 || expr2 logical OR +/// +/// "arg" must point to the first non-white of the expression. +/// "arg" is advanced to the next non-white after the recognized expression. +/// +/// @return OK or FAIL. static int eval2(char_u **arg, typval_T *rettv, int evaluate) { typval_T var2; @@ -3585,15 +3539,13 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) // TODO(ZyX-I): move to eval/expressions -/* - * Handle second level expression: - * expr3 && expr3 && expr3 logical AND - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Return OK or FAIL. - */ +/// Handle second level expression: +/// expr3 && expr3 && expr3 logical AND +/// +/// @param arg must point to the first non-white of the expression. +/// `arg` is advanced to the next non-white after the recognized expression. +/// +/// @return OK or FAIL. static int eval3(char_u **arg, typval_T *rettv, int evaluate) { typval_T var2; @@ -3656,24 +3608,22 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) // TODO(ZyX-I): move to eval/expressions -/* - * Handle third level expression: - * var1 == var2 - * var1 =~ var2 - * var1 != var2 - * var1 !~ var2 - * var1 > var2 - * var1 >= var2 - * var1 < var2 - * var1 <= var2 - * var1 is var2 - * var1 isnot var2 - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Return OK or FAIL. - */ +/// Handle third level expression: +/// var1 == var2 +/// var1 =~ var2 +/// var1 != var2 +/// var1 !~ var2 +/// var1 > var2 +/// var1 >= var2 +/// var1 < var2 +/// var1 <= var2 +/// var1 is var2 +/// var1 isnot var2 +/// +/// "arg" must point to the first non-white of the expression. +/// "arg" is advanced to the next non-white after the recognized expression. +/// +/// @return OK or FAIL. static int eval4(char_u **arg, typval_T *rettv, int evaluate) { typval_T var2; @@ -3767,18 +3717,16 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) // TODO(ZyX-I): move to eval/expressions -/* - * Handle fourth level expression: - * + number addition - * - number subtraction - * . string concatenation - * .. string concatenation - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Return OK or FAIL. - */ +/// Handle fourth level expression: +/// + number addition +/// - number subtraction +/// . string concatenation +/// .. string concatenation +/// +/// @param arg must point to the first non-white of the expression. +/// `arg` is advanced to the next non-white after the recognized expression. +/// +/// @return OK or FAIL. static int eval5(char_u **arg, typval_T *rettv, int evaluate) { typval_T var2; @@ -4324,7 +4272,8 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) /// Apply the leading "!" and "-" before an eval7 expression to "rettv". /// Adjusts "end_leaderp" until it is at "start_leader". -/// @return OK on success, FAIL on failure. +/// +/// @return OK on success, FAIL on failure. static int eval7_leader(typval_T *const rettv, const char_u *const start_leader, const char_u **const end_leaderp) FUNC_ATTR_NONNULL_ALL @@ -4378,7 +4327,7 @@ static int eval7_leader(typval_T *const rettv, const char_u *const start_leader, /// @param lua_funcname If `rettv` refers to a v:lua function, this must point /// to the name of the Lua function to call (after the /// "v:lua." prefix). -/// @return OK on success, FAIL on failure. +/// @return OK on success, FAIL on failure. static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool evaluate, dict_T *const selfdict, typval_T *const basetv, const char_u *const lua_funcname) @@ -4426,9 +4375,13 @@ static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool } /// Evaluate "->method()". +/// /// @param verbose if true, give error messages. -/// @note "*arg" points to the '-'. -/// @return FAIL or OK. @note "*arg" is advanced to after the ')'. +/// @param *arg points to the '-'. +/// +/// @return FAIL or OK. +/// +/// @note "*arg" is advanced to after the ')'. static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool evaluate, const bool verbose) FUNC_ATTR_NONNULL_ALL @@ -4465,8 +4418,10 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool eva } /// Evaluate "->method()" or "->v:lua.method()". -/// @note "*arg" points to the '-'. -/// @return FAIL or OK. "*arg" is advanced to after the ')'. +/// +/// @param *arg points to the '-'. +/// +/// @return FAIL or OK. "*arg" is advanced to after the ')'. static int eval_method(char_u **const arg, typval_T *const rettv, const bool evaluate, const bool verbose) FUNC_ATTR_NONNULL_ALL @@ -4539,9 +4494,10 @@ static int eval_method(char_u **const arg, typval_T *const rettv, const bool eva /// Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". /// "*arg" points to the '[' or '.'. -/// Returns FAIL or OK. "*arg" is advanced to after the ']'. /// /// @param verbose give error messages +/// +/// @returns FAIL or OK. "*arg" is advanced to after the ']'. static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) { bool empty1 = false; @@ -4846,12 +4802,12 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) /// Get an option value /// -/// @param[in,out] arg Points to the '&' or '+' before the option name. Is +/// @param[in,out] arg Points to the '&' or '+' before the option name. Is /// advanced to the character after the option name. -/// @param[out] rettv Location where result is saved. -/// @param[in] evaluate If not true, rettv is not populated. +/// @param[out] rettv Location where result is saved. +/// @param[in] evaluate If not true, rettv is not populated. /// -/// @return OK or FAIL. +/// @return OK or FAIL. int get_option_tv(const char **const arg, typval_T *const rettv, const bool evaluate) FUNC_ATTR_NONNULL_ARG(1) { @@ -4910,10 +4866,9 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval return ret; } -/* - * Allocate a variable for a string constant. - * Return OK or FAIL. - */ +/// Allocate a variable for a string constant. +/// +/// @return OK or FAIL. static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *p; @@ -5050,10 +5005,9 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) return OK; } -/* - * Allocate a variable for a 'str''ing' constant. - * Return OK or FAIL. - */ +/// Allocate a variable for a 'str''ing' constant. +/// +/// @return OK or FAIL. static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *p; @@ -5106,7 +5060,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) return OK; } -/// @return the function name of the partial. +/// @return the function name of the partial. char_u *partial_name(partial_T *pt) { if (pt->pt_name != NULL) { @@ -5145,7 +5099,8 @@ void partial_unref(partial_T *pt) } /// Allocate a variable for a List and fill it from "*arg". -/// Return OK or FAIL. +/// +/// @return OK or FAIL. static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate) { list_T *l = NULL; @@ -5283,7 +5238,8 @@ int get_copyID(void) /// Do garbage collection for lists and dicts. /// /// @param testing true if called from test_garbagecollect_now(). -/// @returns true if some memory was freed. +/// +/// @return true if some memory was freed. bool garbage_collect(bool testing) { bool abort = false; @@ -5461,10 +5417,11 @@ bool garbage_collect(bool testing) /// Free lists and dictionaries that are no longer referenced. /// -/// @note This function may only be called from garbage_collect(). +/// @note This function may only be called from garbage_collect(). /// -/// @param copyID Free lists/dictionaries that don't have this ID. -/// @return true, if something was freed. +/// @param copyID Free lists/dictionaries that don't have this ID. +/// +/// @return true, if something was freed. static int free_unref_items(int copyID) { bool did_free = false; @@ -5699,7 +5656,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack /// Mark all lists and dicts referenced in given mark /// -/// @returns true if setting references failed somehow. +/// @return true if setting references failed somehow. static inline bool set_ref_in_fmark(fmark_T fm, int copyID) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -5713,7 +5670,7 @@ static inline bool set_ref_in_fmark(fmark_T fm, int copyID) /// Mark all lists and dicts referenced in given list and the list itself /// -/// @returns true if setting references failed somehow. +/// @return true if setting references failed somehow. static inline bool set_ref_list(list_T *list, int copyID) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -5729,7 +5686,7 @@ static inline bool set_ref_list(list_T *list, int copyID) /// Mark all lists and dicts referenced in given dict and the dict itself /// -/// @returns true if setting references failed somehow. +/// @return true if setting references failed somehow. static inline bool set_ref_dict(dict_T *dict, int copyID) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -5744,8 +5701,9 @@ static inline bool set_ref_dict(dict_T *dict, int copyID) } -// Get the key for *{key: val} into "tv" and advance "arg". -// Return FAIL when there is no valid key. +/// Get the key for *{key: val} into "tv" and advance "arg". +/// +/// @return FAIL when there is no valid key. static int get_literal_key(char_u **arg, typval_T *tv) FUNC_ATTR_NONNULL_ALL { @@ -5763,9 +5721,10 @@ static int get_literal_key(char_u **arg, typval_T *tv) return OK; } -// Allocate a variable for a Dictionary and fill it from "*arg". -// "literal" is true for *{key: val} -// Return OK or FAIL. Returns NOTDONE for {expr}. +/// Allocate a variable for a Dictionary and fill it from "*arg". +/// "literal" is true for *{key: val} +/// +/// @return OK or FAIL. Returns NOTDONE for {expr}. static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal) { dict_T *d = NULL; @@ -5875,10 +5834,10 @@ failret: /// This uses strtod(). setlocale(LC_NUMERIC, "C") has been used earlier to /// make sure this always uses a decimal point. /// -/// @param[in] text String to convert. -/// @param[out] ret_value Location where conversion result is saved. +/// @param[in] text String to convert. +/// @param[out] ret_value Location where conversion result is saved. /// -/// @return Length of the text that was consumed. +/// @return Length of the text that was consumed. size_t string2float(const char *const text, float_T *const ret_value) FUNC_ATTR_NONNULL_ALL { @@ -5905,9 +5864,9 @@ size_t string2float(const char *const text, float_T *const ret_value) /// /// If the environment variable was not set, silently assume it is empty. /// -/// @param arg Points to the '$'. It is advanced to after the name. -/// @return FAIL if the name is invalid. +/// @param arg Points to the '$'. It is advanced to after the name. /// +/// @return FAIL if the name is invalid. static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *name; @@ -5956,7 +5915,7 @@ void get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv) } } -// Prepare "gap" for an assert error and add the sourcing position. +/// Prepare "gap" for an assert error and add the sourcing position. void prepare_assert_error(garray_T *gap) { char buf[NUMBUFLEN]; @@ -5977,8 +5936,8 @@ void prepare_assert_error(garray_T *gap) } } -// Append "p[clen]" to "gap", escaping unprintable characters. -// Changes NL to \n, CR to \r, etc. +/// Append "p[clen]" to "gap", escaping unprintable characters. +/// Changes NL to \n, CR to \r, etc. static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) FUNC_ATTR_NONNULL_ALL { @@ -6016,8 +5975,8 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) } } -// Append "str" to "gap", escaping unprintable characters. -// Changes NL to \n, CR to \r, etc. +/// Append "str" to "gap", escaping unprintable characters. +/// Changes NL to \n, CR to \r, etc. static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) FUNC_ATTR_NONNULL_ARG(1) { @@ -6051,7 +6010,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) } } -// Fill "gap" with information about an assert error. +/// Fill "gap" with information about an assert error. void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T atype) { @@ -6094,7 +6053,7 @@ void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typ } } -// Add an assert error to v:errors. +/// Add an assert error to v:errors. void assert_error(garray_T *gap) { struct vimvar *vp = &vimvars[VV_ERRORS]; @@ -6268,7 +6227,7 @@ int assert_inrange(typval_T *argvars) return 0; } -// Common for assert_true() and assert_false(). +/// Common for assert_true() and assert_false(). int assert_bool(typval_T *argvars, bool is_true) FUNC_ATTR_NONNULL_ALL { @@ -6442,9 +6401,7 @@ win_T *find_win_by_nr_or_id(typval_T *vp) return find_win_by_nr(vp, NULL); } -/* - * Implementation of map() and filter(). - */ +/// Implementation of map() and filter(). void filter_map(typval_T *argvars, typval_T *rettv, int map) { typval_T *expr; @@ -6806,7 +6763,7 @@ theend: xfree(trans_name); } -/// Returns buffer options, variables and other attributes in a dictionary. +/// @return buffer options, variables and other attributes in a dictionary. dict_T *get_buffer_info(buf_T *buf) { dict_T *const dict = tv_dict_alloc(); @@ -6850,12 +6807,12 @@ dict_T *get_buffer_info(buf_T *buf) /// /// @note Unlike tv_get_lnum(), this one supports only "$" special string. /// -/// @param[in] tv Object to get value from. Is expected to be a number or +/// @param[in] tv Object to get value from. Is expected to be a number or /// a special string "$". -/// @param[in] buf Buffer to take last line number from in case tv is "$". May -/// be NULL, in this case "$" results in zero return. +/// @param[in] buf Buffer to take last line number from in case tv is "$". May +/// be NULL, in this case "$" results in zero return. /// -/// @return Line number or 0 in case of error. +/// @return Line number or 0 in case of error. linenr_T tv_get_lnum_buf(const typval_T *const tv, const buf_T *const buf) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -6891,8 +6848,8 @@ void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv) } } -/// Returns information (variables, options, etc.) about a tab page -/// as a dictionary. +/// @return information (variables, options, etc.) about a tab page +/// as a dictionary. dict_T *get_tabpage_info(tabpage_T *tp, int tp_idx) { dict_T *const dict = tv_dict_alloc(); @@ -6911,7 +6868,7 @@ dict_T *get_tabpage_info(tabpage_T *tp, int tp_idx) return dict; } -/// Returns information about a window as a dictionary. +/// @return information about a window as a dictionary. dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr) { dict_T *const dict = tv_dict_alloc(); @@ -7064,12 +7021,10 @@ void getwinvar(typval_T *argvars, typval_T *rettv, int off) } } -/* - * This function is used by f_input() and f_inputdialog() functions. The third - * argument to f_input() specifies the type of completion to use at the - * prompt. The third argument to f_inputdialog() specifies the value to return - * when the user cancels the prompt. - */ +/// This function is used by f_input() and f_inputdialog() functions. The third +/// argument to f_input() specifies the type of completion to use at the +/// prompt. The third argument to f_inputdialog() specifies the value to return +/// when the user cancels the prompt. void get_user_input(const typval_T *const argvars, typval_T *const rettv, const bool inputdialog, const bool secret) FUNC_ATTR_NONNULL_ALL @@ -7201,10 +7156,10 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const /// Turn a dictionary into a list /// -/// @param[in] tv Dictionary to convert. Is checked for actually being -/// a dictionary, will give an error if not. -/// @param[out] rettv Location where result will be saved. -/// @param[in] what What to save in rettv. +/// @param[in] tv Dictionary to convert. Is checked for actually being +/// a dictionary, will give an error if not. +/// @param[out] rettv Location where result will be saved. +/// @param[in] what What to save in rettv. void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType what) { if (tv->v_type != VAR_DICT) { @@ -7257,7 +7212,7 @@ void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType wha /// @param[out] cmd Returns the command or executable name. /// @param[out] executable Returns `false` if argv[0] is not executable. /// -/// @returns Result of `shell_build_argv()` if `cmd_tv` is a String. +/// @return Result of `shell_build_argv()` if `cmd_tv` is a String. /// Else, string values of `cmd_tv` copied to a (char **) list with /// argv[0] resolved to full path ($PATHEXT-resolved on Windows). char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) @@ -7321,10 +7276,10 @@ char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) /// Fill a dictionary with all applicable maparg() like dictionaries /// -/// @param dict The dictionary to be filled -/// @param mp The maphash that contains the mapping information -/// @param buffer_value The "buffer" value -/// @param compatible True for compatible with old maparg() dict +/// @param dict The dictionary to be filled +/// @param mp The maphash that contains the mapping information +/// @param buffer_value The "buffer" value +/// @param compatible True for compatible with old maparg() dict void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buffer_value, bool compatible) FUNC_ATTR_NONNULL_ALL @@ -7621,7 +7576,7 @@ static list_T *string_to_list(const char *str, size_t len, const bool keepempty) return list; } -// os_system wrapper. Handles 'verbose', :profile, and v:shell_error. +/// os_system wrapper. Handles 'verbose', :profile, and v:shell_error. void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist) { proftime_T wait_time; @@ -7886,7 +7841,7 @@ void add_timer_info_all(typval_T *rettv) }) } -// invoked on the main loop +/// invoked on the main loop void timer_due_cb(TimeWatcher *tw, void *data) { timer_T *timer = (timer_T *)data; @@ -7972,8 +7927,8 @@ void timer_stop(timer_T *timer) time_watcher_close(&timer->tw, timer_close_cb); } -// This will be run on the main loop after the last timer_due_cb, so at this -// point it is safe to free the callback. +/// This will be run on the main loop after the last timer_due_cb, so at this +/// point it is safe to free the callback. static void timer_close_cb(TimeWatcher *tw, void *data) { timer_T *timer = (timer_T *)data; @@ -8235,8 +8190,10 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) } /// Convert the specified character index of line 'lnum' in buffer 'buf' to a -/// byte index. Works only for loaded buffers. Returns -1 on failure. +/// byte index. Works only for loaded buffers. /// The index of the first byte and the first character is zero. +/// +/// @return -1 on failure. int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) { if (buf == NULL || buf->b_ml.ml_mfp == NULL) { @@ -8400,8 +8357,9 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret /// When "fnump" is NULL there is no file number, only 3 items. /// Note that the column is passed on as-is, the caller may want to decrement /// it to use 1 for the first column. -/// Return FAIL when conversion is not possible, doesn't check the position for -/// validity. +/// +/// @return FAIL when conversion is not possible, doesn't check the position for +/// validity. int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool charcol) { list_T *l; @@ -8463,11 +8421,10 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c return OK; } -/* - * Get the length of an environment variable name. - * Advance "arg" to the first character after the name. - * Return 0 for error. - */ +/// Get the length of an environment variable name. +/// Advance "arg" to the first character after the name. +/// +/// @return 0 for error. static int get_env_len(const char_u **arg) { int len; @@ -8484,9 +8441,11 @@ static int get_env_len(const char_u **arg) return len; } -// Get the length of the name of a function or internal variable. -// "arg" is advanced to the first non-white character after the name. -// Return 0 if something is wrong. +/// Get the length of the name of a function or internal variable. +/// +/// @param arg is advanced to the first non-white character after the name. +/// +/// @return 0 if something is wrong. int get_id_len(const char **const arg) { int len; @@ -8514,15 +8473,15 @@ int get_id_len(const char **const arg) return len; } -/* - * Get the length of the name of a variable or function. - * Only the name is recognized, does not handle ".key" or "[idx]". - * "arg" is advanced to the first non-white character after the name. - * Return -1 if curly braces expansion failed. - * Return 0 if something else is wrong. - * If the name contains 'magic' {}'s, expand them and return the - * expanded name in an allocated string via 'alias' - caller must free. - */ +/// Get the length of the name of a variable or function. +/// Only the name is recognized, does not handle ".key" or "[idx]". +/// +/// @param arg is advanced to the first non-white character after the name. +/// If the name contains 'magic' {}'s, expand them and return the +/// expanded name in an allocated string via 'alias' - caller must free. +/// +/// @return -1 if curly braces expansion failed or +/// 0 if something else is wrong. int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbose) { int len; @@ -8579,12 +8538,15 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo return len; } -// Find the end of a variable or function name, taking care of magic braces. -// If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the -// start and end of the first magic braces item. -// "flags" can have FNE_INCL_BR and FNE_CHECK_START. -// Return a pointer to just after the name. Equal to "arg" if there is no -// valid name. +/// Find the end of a variable or function name, taking care of magic braces. +/// +/// @param expr_start if not NULL, then `expr_start` and `expr_end` are set to the +/// start and end of the first magic braces item. +/// +/// @param flags can have FNE_INCL_BR and FNE_CHECK_START. +/// +/// @return a pointer to just after the name. Equal to "arg" if there is no +/// valid name. const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const char_u **expr_end, int flags) { @@ -8662,19 +8624,17 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const return p; } -/* - * Expands out the 'magic' {}'s in a variable/function name. - * Note that this can call itself recursively, to deal with - * constructs like foo{bar}{baz}{bam} - * The four pointer arguments point to "foo{expre}ss{ion}bar" - * "in_start" ^ - * "expr_start" ^ - * "expr_end" ^ - * "in_end" ^ - * - * Returns a new allocated string, which the caller must free. - * Returns NULL for failure. - */ +/// Expands out the 'magic' {}'s in a variable/function name. +/// Note that this can call itself recursively, to deal with +/// constructs like foo{bar}{baz}{bam} +/// The four pointer arguments point to "foo{expre}ss{ion}bar" +/// "in_start" ^ +/// "expr_start" ^ +/// "expr_end" ^ +/// "in_end" ^ +/// +/// @return a new allocated string, which the caller must free or +/// NULL for failure. static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end) { @@ -8721,44 +8681,36 @@ static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, ch return retval; } -/* - * Return TRUE if character "c" can be used in a variable or function name. - * Does not include '{' or '}' for magic braces. - */ +/// @return TRUE if character "c" can be used in a variable or function name. +/// Does not include '{' or '}' for magic braces. int eval_isnamec(int c) { return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR; } -/* - * Return TRUE if character "c" can be used as the first character in a - * variable or function name (excluding '{' and '}'). - */ +/// @return TRUE if character "c" can be used as the first character in a +/// variable or function name (excluding '{' and '}'). int eval_isnamec1(int c) { return ASCII_ISALPHA(c) || c == '_'; } -/* - * Get number v: variable value. - */ +/// Get number v: variable value. varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE { return vimvars[idx].vv_nr; } -// Get string v: variable value. Uses a static buffer, can only be used once. -// If the String variable has never been set, return an empty string. -// Never returns NULL; +/// Get string v: variable value. Uses a static buffer, can only be used once. +/// If the String variable has never been set, return an empty string. +/// Never returns NULL; char_u *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET { return (char_u *)tv_get_string(&vimvars[idx].vv_tv); } -/* - * Get List v: variable value. Caller must take care of reference count when - * needed. - */ +/// Get List v: variable value. Caller must take care of reference count when +/// needed. list_T *get_vim_var_list(int idx) FUNC_ATTR_PURE { return vimvars[idx].vv_list; @@ -8771,9 +8723,7 @@ dict_T *get_vim_var_dict(int idx) FUNC_ATTR_PURE return vimvars[idx].vv_dict; } -/* - * Set v:char to character "c". - */ +/// Set v:char to character "c". void set_vim_var_char(int c) { char buf[MB_MAXBYTES + 1]; @@ -8782,10 +8732,9 @@ void set_vim_var_char(int c) set_vim_var_string(VV_CHAR, buf, -1); } -/* - * Set v:count to "count" and v:count1 to "count1". - * When "set_prevcount" is TRUE first set v:prevcount from v:count. - */ +/// Set v:count to "count" and v:count1 to "count1". +/// +/// @param set_prevcount if TRUE, first set v:prevcount from v:count. void set_vcount(long count, long count1, int set_prevcount) { if (set_prevcount) { @@ -8893,9 +8842,7 @@ void set_argv_var(char **argv, int argc) set_vim_var_list(VV_ARGV, l); } -/* - * Set v:register if needed. - */ +/// Set v:register if needed. void set_reg_var(int c) { char regname; @@ -8911,12 +8858,10 @@ void set_reg_var(int c) } } -/* - * Get or set v:exception. If "oldval" == NULL, return the current value. - * Otherwise, restore the value to "oldval" and return NULL. - * Must always be called in pairs to save and restore v:exception! Does not - * take care of memory allocations. - */ +/// Get or set v:exception. If "oldval" == NULL, return the current value. +/// Otherwise, restore the value to "oldval" and return NULL. +/// Must always be called in pairs to save and restore v:exception! Does not +/// take care of memory allocations. char_u *v_exception(char_u *oldval) { if (oldval == NULL) { @@ -8927,12 +8872,10 @@ char_u *v_exception(char_u *oldval) return NULL; } -/* - * Get or set v:throwpoint. If "oldval" == NULL, return the current value. - * Otherwise, restore the value to "oldval" and return NULL. - * Must always be called in pairs to save and restore v:throwpoint! Does not - * take care of memory allocations. - */ +/// Get or set v:throwpoint. If "oldval" == NULL, return the current value. +/// Otherwise, restore the value to "oldval" and return NULL. +/// Must always be called in pairs to save and restore v:throwpoint! Does not +/// take care of memory allocations. char_u *v_throwpoint(char_u *oldval) { if (oldval == NULL) { @@ -8943,12 +8886,10 @@ char_u *v_throwpoint(char_u *oldval) return NULL; } -/* - * Set v:cmdarg. - * If "eap" != NULL, use "eap" to generate the value and return the old value. - * If "oldarg" != NULL, restore the value to "oldarg" and return NULL. - * Must always be called in pairs! - */ +/// Set v:cmdarg. +/// If "eap" != NULL, use "eap" to generate the value and return the old value. +/// If "oldarg" != NULL, restore the value to "oldarg" and return NULL. +/// Must always be called in pairs! char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) { char_u *oldval = vimvars[VV_CMDARG].vv_str; @@ -9213,11 +9154,12 @@ void set_selfdict(typval_T *const rettv, dict_T *const selfdict) make_partial(selfdict, rettv); } -// Find variable "name" in the list of variables. -// Return a pointer to it if found, NULL if not found. -// Careful: "a:0" variables don't have a name. -// When "htp" is not NULL we are writing to the variable, set "htp" to the -// hashtab_T used. +/// Find variable "name" in the list of variables. +/// Careful: "a:0" variables don't have a name. +/// When "htp" is not NULL we are writing to the variable, set "htp" to the +/// hashtab_T used. +/// +/// @return a pointer to it if found, NULL if not found. dictitem_T *find_var(const char *const name, const size_t name_len, hashtab_T **htp, int no_autoload) { @@ -9415,11 +9357,10 @@ hashtab_T *find_var_ht(const char *name, const size_t name_len, const char **var return find_var_ht_dict(name, name_len, varname, &d); } -/* - * Get the string value of a (global/local) variable. - * Note: see tv_get_string() for how long the pointer remains valid. - * Returns NULL when it doesn't exist. - */ +/// @return the string value of a (global/local) variable or +/// NULL when it doesn't exist. +/// +/// @see tv_get_string() for how long the pointer remains valid. char_u *get_var_value(const char *const name) { dictitem_T *v; @@ -9431,10 +9372,8 @@ char_u *get_var_value(const char *const name) return (char_u *)tv_get_string(&v->di_tv); } -/* - * Allocate a new hashtab for a sourced script. It will be used while - * sourcing this script and when executing functions defined in the script. - */ +/// Allocate a new hashtab for a sourced script. It will be used while +/// sourcing this script and when executing functions defined in the script. void new_script_vars(scid_T id) { hashtab_T *ht; @@ -9462,10 +9401,8 @@ void new_script_vars(scid_T id) } } -/* - * Initialize dictionary "dict" as a scope and set variable "dict_var" to - * point to it. - */ +/// Initialize dictionary "dict" as a scope and set variable "dict_var" to +/// point to it. void init_var_dict(dict_T *dict, ScopeDictDictItem *dict_var, int scope) { hash_init(&dict->dv_hashtab); @@ -9481,9 +9418,7 @@ void init_var_dict(dict_T *dict, ScopeDictDictItem *dict_var, int scope) QUEUE_INIT(&dict->watchers); } -/* - * Unreference a dictionary initialized by init_var_dict(). - */ +/// Unreference a dictionary initialized by init_var_dict(). void unref_var_dict(dict_T *dict) { /* Now the dict needs to be freed if no one else is using it, go back to @@ -9492,19 +9427,15 @@ void unref_var_dict(dict_T *dict) tv_dict_unref(dict); } -/* - * Clean up a list of internal variables. - * Frees all allocated variables and the value they contain. - * Clears hashtab "ht", does not free it. - */ +/// Clean up a list of internal variables. +/// Frees all allocated variables and the value they contain. +/// Clears hashtab "ht", does not free it. void vars_clear(hashtab_T *ht) { vars_clear_ext(ht, TRUE); } -/* - * Like vars_clear(), but only free the value if "free_val" is TRUE. - */ +/// Like vars_clear(), but only free the value if "free_val" is TRUE. void vars_clear_ext(hashtab_T *ht, int free_val) { int todo; @@ -9533,10 +9464,8 @@ void vars_clear_ext(hashtab_T *ht, int free_val) ht->ht_used = 0; } -/* - * Delete a variable from hashtab "ht" at item "hi". - * Clear the variable value and free the dictitem. - */ +/// Delete a variable from hashtab "ht" at item "hi". +/// Clear the variable value and free the dictitem. static void delete_var(hashtab_T *ht, hashitem_T *hi) { dictitem_T *di = TV_DICT_HI2DI(hi); @@ -9546,9 +9475,7 @@ static void delete_var(hashtab_T *ht, hashitem_T *hi) xfree(di); } -/* - * List the value of one internal variable. - */ +/// List the value of one internal variable. static void list_one_var(dictitem_T *v, const char *prefix, int *first) { char *const s = encode_tv2echo(&v->di_tv, NULL); @@ -9981,11 +9908,9 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c return ret; } -/* - * ":echo expr1 ..." print each argument separated with a space, add a - * newline at the end. - * ":echon expr1 ..." print each argument plain. - */ +/// ":echo expr1 ..." print each argument separated with a space, add a +/// newline at the end. +/// ":echon expr1 ..." print each argument plain. void ex_echo(exarg_T *eap) { char_u *arg = eap->arg; @@ -10059,21 +9984,17 @@ void ex_echo(exarg_T *eap) } } -/* - * ":echohl {name}". - */ +/// ":echohl {name}". void ex_echohl(exarg_T *eap) { echo_attr = syn_name2attr(eap->arg); } -/* - * ":execute expr1 ..." execute the result of an expression. - * ":echomsg expr1 ..." Print a message - * ":echoerr expr1 ..." Print an error - * Each gets spaces around each argument and a newline at the end for - * echo commands - */ +/// ":execute expr1 ..." execute the result of an expression. +/// ":echomsg expr1 ..." Print a message +/// ":echoerr expr1 ..." Print an error +/// Each gets spaces around each argument and a newline at the end for +/// echo commands void ex_execute(exarg_T *eap) { char_u *arg = eap->arg; @@ -10150,12 +10071,12 @@ void ex_execute(exarg_T *eap) eap->nextcmd = check_nextcmd(arg); } -/* - * Skip over the name of an option: "&option", "&g:option" or "&l:option". - * "arg" points to the "&" or '+' when called, to "option" when returning. - * Returns NULL when no option name found. Otherwise pointer to the char - * after the option name. - */ +/// Skip over the name of an option: "&option", "&g:option" or "&l:option". +/// +/// @param arg points to the "&" or '+' when called, to "option" when returning. +/// +/// @return NULL when no option name found. Otherwise pointer to the char +/// after the option name. static const char *find_option_end(const char **const arg, int *const opt_flags) { const char *p = *arg; @@ -10218,9 +10139,7 @@ void func_do_profile(ufunc_T *fp) fp->uf_profiling = TRUE; } -/* - * Dump the profiling results for all functions in file "fd". - */ +/// Dump the profiling results for all functions in file "fd". void func_dump_profile(FILE *fd) { hashitem_T *hi; @@ -10340,9 +10259,7 @@ static void prof_func_line(FILE *fd, int count, proftime_T *total, proftime_T *s } } -/* - * Compare function for total time sorting. - */ +/// Compare function for total time sorting. static int prof_total_cmp(const void *s1, const void *s2) { ufunc_T *p1 = *(ufunc_T **)s1; @@ -10350,9 +10267,7 @@ static int prof_total_cmp(const void *s1, const void *s2) return profile_cmp(p1->uf_tm_total, p2->uf_tm_total); } -/* - * Compare function for self time sorting. - */ +/// Compare function for self time sorting. static int prof_self_cmp(const void *s1, const void *s2) { ufunc_T *p1 = *(ufunc_T **)s1; @@ -10434,12 +10349,10 @@ bool script_autoload(const char *const name, const size_t name_len, const bool r return ret; } -/* - * Called when starting to read a function line. - * "sourcing_lnum" must be correct! - * When skipping lines it may not actually be executed, but we won't find out - * until later and we need to store the time now. - */ +/// Called when starting to read a function line. +/// "sourcing_lnum" must be correct! +/// When skipping lines it may not actually be executed, but we won't find out +/// until later and we need to store the time now. void func_line_start(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; @@ -10459,9 +10372,7 @@ void func_line_start(void *cookie) } } -/* - * Called when actually executing a function line. - */ +/// Called when actually executing a function line. void func_line_exec(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; @@ -10472,9 +10383,7 @@ void func_line_exec(void *cookie) } } -/* - * Called when done with a function line. - */ +/// Called when done with a function line. void func_line_end(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; @@ -10609,10 +10518,8 @@ int store_session_globals(FILE *fd) return OK; } -/* - * Display script name where an item was last set. - * Should only be invoked when 'verbose' is non-zero. - */ +/// Display script name where an item was last set. +/// Should only be invoked when 'verbose' is non-zero. void last_set_msg(sctx_T script_ctx) { const LastSet last_set = (LastSet){ @@ -10965,7 +10872,8 @@ repeat: /// Perform a substitution on "str" with pattern "pat" and substitute "sub". /// When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. /// "flags" can be "g" to do a global substitute. -/// Returns an allocated string, NULL for error. +/// +/// @return an allocated string, NULL for error. char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags) { int sublen; @@ -11301,7 +11209,7 @@ void invoke_prompt_callback(void) tv_clear(&rettv); } -// Return true When the interrupt callback was invoked. +/// @return true when the interrupt callback was invoked. bool invoke_prompt_interrupt(void) { typval_T rettv; -- cgit From 00effff56944d5b59440dcdb5e3496d49a76d3e2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Mar 2022 04:47:08 +0000 Subject: vim-patch:8.1.1693: syntax coloring and highlighting is in one big file (#17721) Problem: Syntax coloring and highlighting is in one big file. Solution: Move the highlighting to a separate file. (Yegappan Lakshmanan, closes vim/vim#4674) https://github.com/vim/vim/commit/f9cc9f209ede9f15959e4c2351e970477c139614 Name the new file highlight_group.c instead. Co-authored-by: zeertzjq --- src/nvim/eval.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f4ce6e3b39..af7c3d4985 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -33,6 +33,7 @@ #include "nvim/ex_session.h" #include "nvim/fileio.h" #include "nvim/getchar.h" +#include "nvim/highlight_group.h" #include "nvim/lua/executor.h" #include "nvim/mark.h" #include "nvim/memline.h" -- cgit From be35d3c5ad501abb029279f8e1812d0e4525284f Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sat, 19 Mar 2022 18:57:58 -0600 Subject: feat(api): remove Lua autocommand callbacks when they return true (#17784) This copies the semantics of nvim_buf_attach callbacks, and is a convenient way to create oneshot autocommands gated by some condition. --- src/nvim/eval.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index af7c3d4985..33e8469768 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7730,6 +7730,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co partial_T *partial; char_u *name; Array args = ARRAY_DICT_INIT; + Object rv; switch (callback->type) { case kCallbackFuncref: name = callback->data.funcref; @@ -7742,10 +7743,13 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co break; case kCallbackLua: - nlua_call_ref(callback->data.luaref, NULL, args, false, NULL); - - return false; - break; + rv = nlua_call_ref(callback->data.luaref, NULL, args, true, NULL); + switch (rv.type) { + case kObjectTypeBoolean: + return rv.data.boolean; + default: + return false; + } case kCallbackNone: return false; -- cgit From 6566a4bdbd800ff1850a001a5c40f65b3dc13e46 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Mar 2022 10:51:38 +0000 Subject: vim-patch:8.1.1734: the evalfunc.c file is too big Problem: The evalfunc.c file is too big. Solution: Move some functions to other files. https://github.com/vim/vim/commit/29b7d7a9aac591f920edb89241c8cde27378e50b --- src/nvim/eval.c | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 33e8469768..7f937a3137 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -68,7 +68,6 @@ static char *e_illvar = N_("E461: Illegal variable name: %s"); static char *e_cannot_mod = N_("E995: Cannot modify existing variable"); static char *e_nowhitespace = N_("E274: No white space allowed before parenthesis"); -static char *e_invalwindow = N_("E957: Invalid window number"); static char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s"); static char *e_write2 = N_("E80: Error while writing: %s"); static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob required"); @@ -7323,30 +7322,6 @@ void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buf tv_dict_add_allocated_str(dict, S_LEN("mode"), mapmode); } -int matchadd_dict_arg(typval_T *tv, const char **conceal_char, win_T **win) -{ - dictitem_T *di; - - if (tv->v_type != VAR_DICT) { - emsg(_(e_dictreq)); - return FAIL; - } - - if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("conceal"))) != NULL) { - *conceal_char = tv_get_string(&di->di_tv); - } - - if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) != NULL) { - *win = find_win_by_nr_or_id(&di->di_tv); - if (*win == NULL) { - emsg(_(e_invalwindow)); - return FAIL; - } - } - - return OK; -} - void return_register(int regname, typval_T *rettv) { char_u buf[2] = { regname, 0 }; -- cgit From fcd57980f91ca01227b46de1659e6228115e1278 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 24 Mar 2022 11:14:04 +0000 Subject: chore: add additional compiler flags (#17815) Added: - -Wdouble-promotion - -Wmissing-noreturn - -Wmissing-format-attribute - -Wsuggest-attribute={pure,const,malloc,cold} Resolves: #343 --- src/nvim/eval.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7f937a3137..fbbc543893 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3976,18 +3976,11 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) f1 = f1 * f2; } else if (op == '/') { // Division by zero triggers error from AddressSanitizer - f1 = (f2 == 0 - ? ( + f1 = (f2 == 0 ? ( #ifdef NAN - f1 == 0 - ? NAN - : + f1 == 0 ? (float_T)NAN : #endif - (f1 > 0 - ? INFINITY - : -INFINITY) - ) - : f1 / f2); + (f1 > 0 ? (float_T)INFINITY : (float_T)-INFINITY)) : f1 / f2); } else { emsg(_("E804: Cannot use '%' with Float")); return FAIL; @@ -5842,15 +5835,15 @@ size_t string2float(const char *const text, float_T *const ret_value) // MS-Windows does not deal with "inf" and "nan" properly if (STRNICMP(text, "inf", 3) == 0) { - *ret_value = INFINITY; + *ret_value = (float_T)INFINITY; return 3; } if (STRNICMP(text, "-inf", 3) == 0) { - *ret_value = -INFINITY; + *ret_value = (float_T)-INFINITY; return 4; } if (STRNICMP(text, "nan", 3) == 0) { - *ret_value = NAN; + *ret_value = (float_T)NAN; return 3; } *ret_value = strtod(text, &s); -- cgit From 72652cbc46f568128bfc296ba63fb2d26941da8e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Mar 2022 10:25:55 -0700 Subject: feat(test): use nvim_exec in helpers.source() #16064 helpers.source() was a hack to work around the lack of anonymous :source. Its "create tempfile" behavior is not a required part of most tests that use it. Some tests still need the old "create tempfile" behavior either because they test SID behavior, or because of missing nvim_exec features: #16071 --- src/nvim/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index fbbc543893..6c72c2866e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9217,6 +9217,8 @@ dictitem_T *find_var_in_ht(hashtab_T *const ht, int htname, const char *const va /// Finds the dict (g:, l:, s:, …) and hashtable used for a variable. /// +/// Assigns SID if s: scope is accessed from Lua or anonymous Vimscript. #15994 +/// /// @param[in] name Variable name, possibly with scope prefix. /// @param[in] name_len Variable name length. /// @param[out] varname Will be set to the start of the name without scope @@ -9304,6 +9306,7 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, cons } } if (current_sctx.sc_sid == SID_STR || current_sctx.sc_sid == SID_LUA) { + // Create SID if s: scope is accessed from Lua or anon Vimscript. #15994 new_script_item(NULL, ¤t_sctx.sc_sid); } *d = &SCRIPT_SV(current_sctx.sc_sid)->sv_dict; -- cgit From 6786b6afade97771027fda3c1438969def320cc5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 3 Apr 2022 02:26:59 +0100 Subject: vim-patch:8.1.1687: the evalfunc.c file is too big (#17949) Problem: The evalfunc.c file is too big. Solution: Move testing support to a separate file. https://github.com/vim/vim/commit/ecaa70ea29c269dd0dabd3cd5acdfa0ce42ccd54 --- src/nvim/eval.c | 470 +------------------------------------------------------- 1 file changed, 7 insertions(+), 463 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6c72c2866e..c1905b31d0 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -28,7 +28,6 @@ #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds2.h" -#include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/ex_session.h" #include "nvim/fileio.h" @@ -41,7 +40,6 @@ #include "nvim/ops.h" #include "nvim/option.h" #include "nvim/os/input.h" -#include "nvim/os/os.h" #include "nvim/os/shell.h" #include "nvim/path.h" #include "nvim/quickfix.h" @@ -3271,7 +3269,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) /// Does not use 'cpo' and always uses 'magic'. /// /// @return TRUE if "pat" matches "text". -static int pattern_match(char_u *pat, char_u *text, bool ic) +int pattern_match(char_u *pat, char_u *text, bool ic) { int matches = 0; regmatch_T regmatch; @@ -5905,144 +5903,6 @@ void get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv) } } -/// Prepare "gap" for an assert error and add the sourcing position. -void prepare_assert_error(garray_T *gap) -{ - char buf[NUMBUFLEN]; - - ga_init(gap, 1, 100); - if (sourcing_name != NULL) { - ga_concat(gap, (char *)sourcing_name); - if (sourcing_lnum > 0) { - ga_concat(gap, " "); - } - } - if (sourcing_lnum > 0) { - vim_snprintf(buf, ARRAY_SIZE(buf), "line %" PRId64, (int64_t)sourcing_lnum); - ga_concat(gap, buf); - } - if (sourcing_name != NULL || sourcing_lnum > 0) { - ga_concat(gap, ": "); - } -} - -/// Append "p[clen]" to "gap", escaping unprintable characters. -/// Changes NL to \n, CR to \r, etc. -static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) - FUNC_ATTR_NONNULL_ALL -{ - char_u buf[NUMBUFLEN]; - - if (clen > 1) { - memmove(buf, p, clen); - buf[clen] = NUL; - ga_concat(gap, (char *)buf); - } else { - switch (*p) { - case BS: - ga_concat(gap, "\\b"); break; - case ESC: - ga_concat(gap, "\\e"); break; - case FF: - ga_concat(gap, "\\f"); break; - case NL: - ga_concat(gap, "\\n"); break; - case TAB: - ga_concat(gap, "\\t"); break; - case CAR: - ga_concat(gap, "\\r"); break; - case '\\': - ga_concat(gap, "\\\\"); break; - default: - if (*p < ' ') { - vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); - ga_concat(gap, (char *)buf); - } else { - ga_append(gap, *p); - } - break; - } - } -} - -/// Append "str" to "gap", escaping unprintable characters. -/// Changes NL to \n, CR to \r, etc. -static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) - FUNC_ATTR_NONNULL_ARG(1) -{ - char_u buf[NUMBUFLEN]; - - if (str == NULL) { - ga_concat(gap, "NULL"); - return; - } - - for (const char_u *p = str; *p != NUL; p++) { - int same_len = 1; - const char_u *s = p; - const int c = mb_ptr2char_adv(&s); - const int clen = s - p; - while (*s != NUL && c == utf_ptr2char(s)) { - same_len++; - s += clen; - } - if (same_len > 20) { - ga_concat(gap, "\\["); - ga_concat_esc(gap, p, clen); - ga_concat(gap, " occurs "); - vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len); - ga_concat(gap, (char *)buf); - ga_concat(gap, " times]"); - p = s - 1; - } else { - ga_concat_esc(gap, p, clen); - } - } -} - -/// Fill "gap" with information about an assert error. -void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, - typval_T *got_tv, assert_type_T atype) -{ - char_u *tofree; - - if (opt_msg_tv->v_type != VAR_UNKNOWN) { - tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL); - ga_concat(gap, (char *)tofree); - xfree(tofree); - ga_concat(gap, ": "); - } - - if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH) { - ga_concat(gap, "Pattern "); - } else if (atype == ASSERT_NOTEQUAL) { - ga_concat(gap, "Expected not equal to "); - } else { - ga_concat(gap, "Expected "); - } - - if (exp_str == NULL) { - tofree = (char_u *)encode_tv2string(exp_tv, NULL); - ga_concat_shorten_esc(gap, tofree); - xfree(tofree); - } else { - ga_concat_shorten_esc(gap, exp_str); - } - - if (atype != ASSERT_NOTEQUAL) { - if (atype == ASSERT_MATCH) { - ga_concat(gap, " does not match "); - } else if (atype == ASSERT_NOTMATCH) { - ga_concat(gap, " does match "); - } else { - ga_concat(gap, " but got "); - } - tofree = (char_u *)encode_tv2string(got_tv, NULL); - ga_concat_shorten_esc(gap, tofree); - xfree(tofree); - } -} - /// Add an assert error to v:errors. void assert_error(garray_T *gap) { @@ -6056,328 +5916,6 @@ void assert_error(garray_T *gap) (const char *)gap->ga_data, (ptrdiff_t)gap->ga_len); } -int assert_equal_common(typval_T *argvars, assert_type_T atype) - FUNC_ATTR_NONNULL_ALL -{ - garray_T ga; - - if (tv_equal(&argvars[0], &argvars[1], false, false) - != (atype == ASSERT_EQUAL)) { - prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[2], NULL, - &argvars[0], &argvars[1], atype); - assert_error(&ga); - ga_clear(&ga); - return 1; - } - return 0; -} - -int assert_equalfile(typval_T *argvars) - FUNC_ATTR_NONNULL_ALL -{ - char buf1[NUMBUFLEN]; - char buf2[NUMBUFLEN]; - const char *const fname1 = tv_get_string_buf_chk(&argvars[0], buf1); - const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); - garray_T ga; - - if (fname1 == NULL || fname2 == NULL) { - return 0; - } - - IObuff[0] = NUL; - FILE *const fd1 = os_fopen(fname1, READBIN); - char line1[200]; - char line2[200]; - ptrdiff_t lineidx = 0; - if (fd1 == NULL) { - snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname1); - } else { - FILE *const fd2 = os_fopen(fname2, READBIN); - if (fd2 == NULL) { - fclose(fd1); - snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2); - } else { - int64_t linecount = 1; - for (int64_t count = 0;; count++) { - const int c1 = fgetc(fd1); - const int c2 = fgetc(fd2); - if (c1 == EOF) { - if (c2 != EOF) { - STRCPY(IObuff, "first file is shorter"); - } - break; - } else if (c2 == EOF) { - STRCPY(IObuff, "second file is shorter"); - break; - } else { - line1[lineidx] = c1; - line2[lineidx] = c2; - lineidx++; - if (c1 != c2) { - snprintf((char *)IObuff, IOSIZE, - "difference at byte %" PRId64 ", line %" PRId64, - count, linecount); - break; - } - } - if (c1 == NL) { - linecount++; - lineidx = 0; - } else if (lineidx + 2 == (ptrdiff_t)sizeof(line1)) { - memmove(line1, line1 + 100, lineidx - 100); - memmove(line2, line2 + 100, lineidx - 100); - lineidx -= 100; - } - } - fclose(fd1); - fclose(fd2); - } - } - if (IObuff[0] != NUL) { - prepare_assert_error(&ga); - if (argvars[2].v_type != VAR_UNKNOWN) { - char *const tofree = encode_tv2echo(&argvars[2], NULL); - ga_concat(&ga, tofree); - xfree(tofree); - ga_concat(&ga, ": "); - } - ga_concat(&ga, (char *)IObuff); - if (lineidx > 0) { - line1[lineidx] = NUL; - line2[lineidx] = NUL; - ga_concat(&ga, " after \""); - ga_concat(&ga, line1); - if (STRCMP(line1, line2) != 0) { - ga_concat(&ga, "\" vs \""); - ga_concat(&ga, line2); - } - ga_concat(&ga, "\""); - } - assert_error(&ga); - ga_clear(&ga); - return 1; - } - return 0; -} - -int assert_inrange(typval_T *argvars) - FUNC_ATTR_NONNULL_ALL -{ - bool error = false; - - if (argvars[0].v_type == VAR_FLOAT - || argvars[1].v_type == VAR_FLOAT - || argvars[2].v_type == VAR_FLOAT) { - const float_T flower = tv_get_float(&argvars[0]); - const float_T fupper = tv_get_float(&argvars[1]); - const float_T factual = tv_get_float(&argvars[2]); - - if (factual < flower || factual > fupper) { - garray_T ga; - prepare_assert_error(&ga); - if (argvars[3].v_type != VAR_UNKNOWN) { - char_u *const tofree = (char_u *)encode_tv2string(&argvars[3], NULL); - ga_concat(&ga, (char *)tofree); - xfree(tofree); - } else { - char msg[80]; - vim_snprintf(msg, sizeof(msg), "Expected range %g - %g, but got %g", - flower, fupper, factual); - ga_concat(&ga, msg); - } - assert_error(&ga); - ga_clear(&ga); - return 1; - } - } else { - const varnumber_T lower = tv_get_number_chk(&argvars[0], &error); - const varnumber_T upper = tv_get_number_chk(&argvars[1], &error); - const varnumber_T actual = tv_get_number_chk(&argvars[2], &error); - - if (error) { - return 0; - } - if (actual < lower || actual > upper) { - garray_T ga; - prepare_assert_error(&ga); - - char msg[55]; - vim_snprintf(msg, sizeof(msg), - "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", - lower, upper); // -V576 - fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], - ASSERT_INRANGE); - assert_error(&ga); - ga_clear(&ga); - return 1; - } - } - return 0; -} - -/// Common for assert_true() and assert_false(). -int assert_bool(typval_T *argvars, bool is_true) - FUNC_ATTR_NONNULL_ALL -{ - bool error = false; - garray_T ga; - - if ((argvars[0].v_type != VAR_NUMBER - || (tv_get_number_chk(&argvars[0], &error) == 0) == is_true - || error) - && (argvars[0].v_type != VAR_BOOL - || (argvars[0].vval.v_bool - != (BoolVarValue)(is_true - ? kBoolVarTrue - : kBoolVarFalse)))) { - prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[1], - (char_u *)(is_true ? "True" : "False"), - NULL, &argvars[0], ASSERT_OTHER); - assert_error(&ga); - ga_clear(&ga); - return 1; - } - return 0; -} - -int assert_exception(typval_T *argvars) - FUNC_ATTR_NONNULL_ALL -{ - garray_T ga; - - const char *const error = tv_get_string_chk(&argvars[0]); - if (vimvars[VV_EXCEPTION].vv_str == NULL) { - prepare_assert_error(&ga); - ga_concat(&ga, "v:exception is not set"); - assert_error(&ga); - ga_clear(&ga); - return 1; - } else if (error != NULL - && strstr((char *)vimvars[VV_EXCEPTION].vv_str, error) == NULL) { - prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[1], NULL, &argvars[0], - &vimvars[VV_EXCEPTION].vv_tv, ASSERT_OTHER); - assert_error(&ga); - ga_clear(&ga); - return 1; - } - return 0; -} - -static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, const char *cmd) - FUNC_ATTR_NONNULL_ALL -{ - if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) { - char *const tofree = encode_tv2echo(&argvars[2], NULL); - ga_concat(gap, tofree); - xfree(tofree); - } else { - ga_concat(gap, cmd); - } -} - -int assert_beeps(typval_T *argvars, bool no_beep) - FUNC_ATTR_NONNULL_ALL -{ - const char *const cmd = tv_get_string_chk(&argvars[0]); - int ret = 0; - - called_vim_beep = false; - suppress_errthrow = true; - emsg_silent = false; - do_cmdline_cmd(cmd); - if (no_beep ? called_vim_beep : !called_vim_beep) { - garray_T ga; - prepare_assert_error(&ga); - if (no_beep) { - ga_concat(&ga, "command did beep: "); - } else { - ga_concat(&ga, "command did not beep: "); - } - ga_concat(&ga, cmd); - assert_error(&ga); - ga_clear(&ga); - ret = 1; - } - - suppress_errthrow = false; - emsg_on_display = false; - return ret; -} - -int assert_fails(typval_T *argvars) - FUNC_ATTR_NONNULL_ALL -{ - const char *const cmd = tv_get_string_chk(&argvars[0]); - garray_T ga; - int ret = 0; - int save_trylevel = trylevel; - - // trylevel must be zero for a ":throw" command to be considered failed - trylevel = 0; - called_emsg = false; - suppress_errthrow = true; - emsg_silent = true; - - do_cmdline_cmd(cmd); - if (!called_emsg) { - prepare_assert_error(&ga); - ga_concat(&ga, "command did not fail: "); - assert_append_cmd_or_arg(&ga, argvars, cmd); - assert_error(&ga); - ga_clear(&ga); - ret = 1; - } else if (argvars[1].v_type != VAR_UNKNOWN) { - char buf[NUMBUFLEN]; - const char *const error = tv_get_string_buf_chk(&argvars[1], buf); - - if (error == NULL - || strstr((char *)vimvars[VV_ERRMSG].vv_str, error) == NULL) { - prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], - &vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER); - ga_concat(&ga, ": "); - assert_append_cmd_or_arg(&ga, argvars, cmd); - assert_error(&ga); - ga_clear(&ga); - ret = 1; - } - } - - trylevel = save_trylevel; - called_emsg = false; - suppress_errthrow = false; - emsg_silent = false; - emsg_on_display = false; - set_vim_var_string(VV_ERRMSG, NULL, 0); - return ret; -} - -int assert_match_common(typval_T *argvars, assert_type_T atype) - FUNC_ATTR_NONNULL_ALL -{ - char buf1[NUMBUFLEN]; - char buf2[NUMBUFLEN]; - const char *const pat = tv_get_string_buf_chk(&argvars[0], buf1); - const char *const text = tv_get_string_buf_chk(&argvars[1], buf2); - - if (pat == NULL || text == NULL) { - emsg(_(e_invarg)); - } else if (pattern_match((char_u *)pat, (char_u *)text, false) - != (atype == ASSERT_MATCH)) { - garray_T ga; - prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype); - assert_error(&ga); - ga_clear(&ga); - return 1; - } - return 0; -} - /// Find a window: When using a Window ID in any tab page, when using a number /// in the current tab page. win_T *find_win_by_nr_or_id(typval_T *vp) @@ -8665,6 +8203,12 @@ int eval_isnamec1(int c) return ASCII_ISALPHA(c) || c == '_'; } +/// Get typval_T v: variable value. +typval_T *get_vim_var_tv(int idx) +{ + return &vimvars[idx].vv_tv; +} + /// Get number v: variable value. varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE { -- cgit From 356cff78ece597059133e33eceb955f72286a319 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 11 Apr 2022 21:29:18 +0800 Subject: vim-patch:8.2.4734: getcharpos() may change a mark position (#18077) Problem: getcharpos() may change a mark position. Solution: Copy the mark position. (closes vim/vim#10148) https://github.com/vim/vim/commit/3caf1cce2b85a8f24195d057f0ad63082543e99e --- src/nvim/eval.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c1905b31d0..3e855ece15 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7739,7 +7739,6 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { static pos_T pos; - pos_T *pp; // Argument can be [lnum, col, coladd]. if (tv->v_type == VAR_LIST) { @@ -7799,33 +7798,31 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret if (name == NULL) { return NULL; } - if (name[0] == '.') { // Cursor. + + pos.lnum = 0; + if (name[0] == '.') { + // cursor pos = curwin->w_cursor; - if (charcol) { - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); - } - return &pos; - } - if (name[0] == 'v' && name[1] == NUL) { // Visual start. + } else if (name[0] == 'v' && name[1] == NUL) { + // Visual start if (VIsual_active) { pos = VIsual; } else { pos = curwin->w_cursor; } - if (charcol) { - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); - } - return &pos; - } - if (name[0] == '\'') { // Mark. - pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum); + } else if (name[0] == '\'') { + // mark + const pos_T *const pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) { return NULL; } + pos = *pp; + } + if (pos.lnum != 0) { if (charcol) { - pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col); + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); } - return pp; + return &pos; } pos.coladd = 0; -- cgit From 87e1693ba63ff6d936ad0bf8a6a9cbacfe2413e9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 21 Apr 2022 07:04:40 +0800 Subject: vim-patch:8.2.4797: getwininfo() may get oudated values Problem: getwininfo() may get oudated values. Solution: Make sure w_botline is up-to-date. (closes vim/vim#10226) https://github.com/vim/vim/commit/8530b41fd3872c9a1349b083470d565677948518 Correct test order and add a modeline in test_bufwintabinfo.vim. --- src/nvim/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3e855ece15..0c45f05640 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6401,6 +6401,9 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr) { dict_T *const dict = tv_dict_alloc(); + // make sure w_botline is valid + validate_botline(wp); + tv_dict_add_nr(dict, S_LEN("tabnr"), tpnr); tv_dict_add_nr(dict, S_LEN("winnr"), winnr); tv_dict_add_nr(dict, S_LEN("winid"), wp->handle); -- cgit From c58219413514caf035ac52eb85b84b1ff31d4722 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 25 Apr 2022 04:12:47 +0200 Subject: refactor: add pure attribute to pure functions (#18165) This will allow the compilers that support the pure attribute to make further optimizations. --- src/nvim/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0c45f05640..bebadc1282 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5050,6 +5050,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) /// @return the function name of the partial. char_u *partial_name(partial_T *pt) + FUNC_ATTR_PURE { if (pt->pt_name != NULL) { return pt->pt_name; @@ -8525,6 +8526,7 @@ static void check_vars(const char *name, size_t len) /// check if special v:lua value for calling lua functions bool is_luafunc(partial_T *partial) + FUNC_ATTR_PURE { return partial == vvlua_partial; } @@ -9922,6 +9924,7 @@ void func_line_end(void *cookie) } static var_flavour_T var_flavour(char_u *varname) + FUNC_ATTR_PURE { char_u *p = varname; -- cgit From 0648100fed65cbe8efe774ae997ab841cae01872 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 25 Apr 2022 04:18:43 +0200 Subject: refactor: convert macros to all-caps (#17895) Closes https://github.com/neovim/neovim/issues/6297 --- src/nvim/eval.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index bebadc1282..e192a6de6b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2720,7 +2720,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) if (cmdidx == CMD_let || cmdidx == CMD_const) { xp->xp_context = EXPAND_USER_VARS; - if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) { + if (strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) { // ":let var1 var2 ...": find last space. for (p = arg + STRLEN(arg); p >= arg;) { xp->xp_pattern = p; @@ -2735,8 +2735,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS : EXPAND_EXPRESSION; } - while ((xp->xp_pattern = vim_strpbrk(arg, - (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) { + while ((xp->xp_pattern = (char_u *)strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { c = *xp->xp_pattern; if (c == '&') { c = xp->xp_pattern[1]; @@ -10202,7 +10201,7 @@ repeat: // Do not call shorten_fname() here since it removes the prefix // even though the path does not have a prefix. - if (fnamencmp(p, dirname, namelen) == 0) { + if (FNAMENCMP(p, dirname, namelen) == 0) { p += namelen; if (vim_ispathsep(*p)) { while (*p && vim_ispathsep(*p)) { -- cgit From dde4f09f51ffaf8df5cc2a81eed935e31e1f94ba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 31 Mar 2022 15:47:53 +0800 Subject: vim-patch:8.1.2145: cannot map when modifyOtherKeys is enabled Problem: Cannot map when modifyOtherKeys is enabled. Solution: Add the mapping twice, both with modifier and as 0x08. Use only the first one when modifyOtherKeys has been detected. https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84 Add REPTERM_NO_SPECIAL instead of REPTERM_SPECIAL because the meaning of "special" is different between Vim and Nvim. Omit seenModifyOtherKeys as Nvim supports attaching multiple UIs. Omit tests as they send terminal codes. Keep the behavior of API functions. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e192a6de6b..af6e7e470d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4965,7 +4965,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) // Special key, e.g.: "\" case '<': - extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true); + extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true, true, NULL); if (extra != 0) { name += extra; if (name >= rettv->vval.v_string + len) { -- cgit From abe91e1efec84c47c03a69ab8a998bb16f628084 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Apr 2022 15:05:56 +0800 Subject: vim-patch:8.2.0855: GUI tests fail because the test doesn't use a modifier Problem: GUI tests fail because the test doesn't use a modifier. Solution: Add "\{xxx}" to be able to encode a modifier. https://github.com/vim/vim/commit/ebe9d34aa07037cff2188a8dd424ee1f59cbb0bf Change macros to enums to use them in unit tests. --- src/nvim/eval.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index af6e7e470d..4427179633 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4963,9 +4963,17 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) ++name; break; - // Special key, e.g.: "\" + // Special key, e.g.: "\" or "\{C-W}" case '<': - extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true, true, NULL); + case '{': { + int flags = FSK_KEYCODE | FSK_IN_STRING; + + if (*p == '<') { + flags |= FSK_SIMPLIFY; + } else { + flags |= FSK_CURLY; + } + extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, NULL); if (extra != 0) { name += extra; if (name >= rettv->vval.v_string + len) { @@ -4973,6 +4981,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) } break; } + } FALLTHROUGH; default: -- cgit From d531ef6813919dd6df8ca6927cd99ec3c0a65635 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Apr 2022 15:31:29 +0800 Subject: vim-patch:8.2.0867: using \{xxx} for encoding a modifier is not nice Problem: Using \{xxx} for encoding a modifier is not nice. Solution: Use \<*xxx> instead, since it's the same as \ but producing a different code. https://github.com/vim/vim/commit/fccd93f0917234b962ce07d1df3adf9d7105936f Use this notation in langmap_spec. --- src/nvim/eval.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4427179633..f8e2f913bf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4963,15 +4963,12 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) ++name; break; - // Special key, e.g.: "\" or "\{C-W}" - case '<': - case '{': { + // Special key, e.g.: "\" + case '<': { int flags = FSK_KEYCODE | FSK_IN_STRING; - if (*p == '<') { + if (p[1] != '*') { flags |= FSK_SIMPLIFY; - } else { - flags |= FSK_CURLY; } extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, NULL); if (extra != 0) { -- cgit From 995c1863685d7fa0cc2638b55efee55c4cb7ffc9 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Mon, 18 Apr 2022 12:54:25 +0200 Subject: refactor(uncrustify): disable formatting in problematic code sections --- src/nvim/eval.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f8e2f913bf..b7177792db 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3972,12 +3972,16 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) if (op == '*') { f1 = f1 * f2; } else if (op == '/') { + // uncrustify:off + // Division by zero triggers error from AddressSanitizer f1 = (f2 == 0 ? ( #ifdef NAN f1 == 0 ? (float_T)NAN : #endif (f1 > 0 ? (float_T)INFINITY : (float_T)-INFINITY)) : f1 / f2); + + // uncrustify:on } else { emsg(_("E804: Cannot use '%' with Float")); return FAIL; -- cgit From eef8de4df0247157e57f306062b1b86e01a41454 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 29 Apr 2022 13:53:42 +0200 Subject: refactor(uncrustify): change rules to better align with the style guide Add space around arithmetic operators '+' and '-'. Remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. Remove space between '((' or '))' of control statements. Add space between ')' and '{' of control statements. Remove space between function name and '(' on function declaration. Collapse empty blocks between '{' and '}'. Remove newline at the end of the file. Remove newline between 'enum' and '{'. Remove newline between '}' and ')' in a function invocation. Remove newline between '}' and 'while' of 'do' statement. --- src/nvim/eval.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b7177792db..9b03af8d32 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -161,7 +161,7 @@ static struct vimvar { VV(VV_STATUSMSG, "statusmsg", VAR_STRING, 0), VV(VV_SHELL_ERROR, "shell_error", VAR_NUMBER, VV_RO), VV(VV_THIS_SESSION, "this_session", VAR_STRING, 0), - VV(VV_VERSION, "version", VAR_NUMBER, VV_COMPAT+VV_RO), + VV(VV_VERSION, "version", VAR_NUMBER, VV_COMPAT + VV_RO), VV(VV_LNUM, "lnum", VAR_NUMBER, VV_RO_SBX), VV(VV_TERMRESPONSE, "termresponse", VAR_STRING, VV_RO), VV(VV_FNAME, "fname", VAR_STRING, VV_RO), @@ -2095,8 +2095,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co char_u *key = NULL; if (*p == '.') { key = p + 1; - for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) { - } + for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} if (len == 0) { if (!quiet) { emsg(_("E713: Cannot use empty key after .")); @@ -2444,6 +2443,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co ? lp->ll_tv->v_lock : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, TV_CSTRING)) { + // Skip } else if (lp->ll_range) { listitem_T *ll_li = lp->ll_li; int ll_n1 = lp->ll_n1; @@ -2774,8 +2774,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) xp->xp_context = EXPAND_NOTHING; } else if (c == '\'') { // literal string // Trick: '' is like stopping and starting a literal string. - while ((c = *++xp->xp_pattern) != NUL && c != '\'') { - } + while ((c = *++xp->xp_pattern) != NUL && c != '\'') {} xp->xp_context = EXPAND_NOTHING; } else if (c == '|') { if (xp->xp_pattern[1] == '|') { @@ -2794,8 +2793,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) } arg = xp->xp_pattern; if (*arg != NUL) { - while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) { - } + while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) {} } } @@ -4536,8 +4534,7 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) * dict.name */ key = *arg + 1; - for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) { - } + for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} if (len == 0) { return FAIL; } @@ -5710,8 +5707,7 @@ static int get_literal_key(char_u **arg, typval_T *tv) if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') { return FAIL; } - for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) { - } + for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {} tv->v_type = VAR_STRING; tv->vval.v_string = vim_strnsave(*arg, p - *arg); @@ -5847,7 +5843,7 @@ size_t string2float(const char *const text, float_T *const ret_value) return 3; } if (STRNICMP(text, "-inf", 3) == 0) { - *ret_value = (float_T)-INFINITY; + *ret_value = (float_T) - INFINITY; return 4; } if (STRNICMP(text, "nan", 3) == 0) { @@ -6663,7 +6659,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const if (!ui_has(kUICmdline)) { const char *lastnl = strrchr(prompt, '\n'); if (lastnl != NULL) { - p = lastnl+1; + p = lastnl + 1; msg_start(); msg_clr_eos(); msg_puts_attr_len(prompt, p - prompt, echo_attr); @@ -7948,8 +7944,7 @@ static int get_env_len(const char_u **arg) int len; const char_u *p; - for (p = *arg; vim_isIDc(*p); p++) { - } + for (p = *arg; vim_isIDc(*p); p++) {} if (p == *arg) { // No name found. return 0; } @@ -8091,8 +8086,7 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const || br_nest != 0); MB_PTR_ADV(p)) { if (*p == '\'') { // skip over 'string' to avoid counting [ and ] inside it. - for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) { - } + for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) {} if (*p == NUL) { break; } @@ -8566,7 +8560,7 @@ int check_luafunc_name(const char *const str, const bool paren) if (*p != (paren ? '(' : NUL)) { return 0; } else { - return (int)(p-str); + return (int)(p - str); } } -- cgit From 3c23100130725bb79c04e933c505bbeda96fb3bb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 30 Apr 2022 16:48:00 +0200 Subject: refactor: replace char_u variables and functions with char (#18288) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9b03af8d32..da869df5cc 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6644,8 +6644,8 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const const int xp_namelen = (int)strlen(xp_name); uint32_t argt; - if (parse_compl_arg((char_u *)xp_name, xp_namelen, &xp_type, - &argt, (char_u **)&xp_arg) == FAIL) { + if (parse_compl_arg(xp_name, xp_namelen, &xp_type, + &argt, &xp_arg) == FAIL) { return; } } @@ -9579,8 +9579,7 @@ void ex_execute(exarg_T *eap) did_emsg = save_did_emsg; } } else if (eap->cmdidx == CMD_execute) { - do_cmdline((char_u *)ga.ga_data, - eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); + do_cmdline(ga.ga_data, eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); } } -- cgit From 27149e0071c3fa38c81526f63a997bedfd6e2be8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 May 2022 06:11:22 +0800 Subject: vim-patch:8.2.4858: K_SPECIAL may be escaped twice Problem: K_SPECIAL may be escaped twice. Solution: Avoid double escaping. (closes vim/vim#10340) https://github.com/vim/vim/commit/db08887f24d20be11d184ce321bc0890613e42bd --- src/nvim/eval.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index da869df5cc..3023b1e774 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4869,11 +4869,10 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) if (*p == '\\' && p[1] != NUL) { p++; // A "\" form occupies at least 4 characters, and produces up - // to 21 characters (3 * 6 for the char and 3 for a modifier): - // reserve space for 18 extra. - // Each byte in the char could be encoded as K_SPECIAL K_EXTRA x. + // to 9 characters (6 for the char and 3 for a modifier): + // reserve space for 5 extra. if (*p == '<') { - extra += 18; + extra += 5; } } } @@ -4971,7 +4970,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) if (p[1] != '*') { flags |= FSK_SIMPLIFY; } - extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, NULL); + extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, false, NULL); if (extra != 0) { name += extra; if (name >= rettv->vval.v_string + len) { -- cgit From b9bdd0f61e5e7365c07aadbc3f796556b6d85fdf Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 1 May 2022 11:18:17 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 964 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 475 insertions(+), 489 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3023b1e774..b4c3e62ddf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -73,7 +73,7 @@ static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob re // TODO(ZyX-I): move to eval/executor static char *e_letwrong = N_("E734: Wrong variable type for %s="); -static char_u * const namespace_char = (char_u *)"abglstvw"; +static char * const namespace_char = "abglstvw"; /// Variable used for g: static ScopeDictDictItem globvars_var; @@ -103,7 +103,7 @@ static garray_T ga_scripts = { 0, 0, sizeof(scriptvar_T *), 4, NULL }; static int echo_attr = 0; // attributes used for ":echo" // The names of packages that once were loaded are remembered. -static garray_T ga_loaded = { 0, 0, sizeof(char_u *), 4, NULL }; +static garray_T ga_loaded = { 0, 0, sizeof(char *), 4, NULL }; /* * Info used by a ":for" loop. @@ -115,7 +115,7 @@ typedef struct { list_T *fi_list; // list being used int fi_bi; // index of blob blob_T *fi_blob; // blob being used - char_u *fi_string; // copy of string being used + char *fi_string; // copy of string being used int fi_byte_idx; // byte index in fi_string } forinfo_T; @@ -500,12 +500,12 @@ void eval_clear(void) /// Set an internal variable to a string value. Creates the variable if it does /// not already exist. -void set_internal_string_var(const char *name, char_u *value) +void set_internal_string_var(const char *name, char *value) FUNC_ATTR_NONNULL_ARG(1) { typval_T tv = { .v_type = VAR_STRING, - .vval.v_string = value, + .vval.v_string = (char_u *)value, }; set_var(name, strlen(name), &tv, true); @@ -513,15 +513,15 @@ void set_internal_string_var(const char *name, char_u *value) static lval_T *redir_lval = NULL; static garray_T redir_ga; // Only valid when redir_lval is not NULL. -static char_u *redir_endp = NULL; -static char_u *redir_varname = NULL; +static char *redir_endp = NULL; +static char *redir_varname = NULL; /// Start recording command output to a variable /// /// @param append append to an existing variable /// /// @return OK if successfully completed the setup. FAIL otherwise. -int var_redir_start(char_u *name, int append) +int var_redir_start(char *name, int append) { int save_emsg; int err; @@ -534,7 +534,7 @@ int var_redir_start(char_u *name, int append) } // Make a copy of the name, it is used in redir_lval until redir ends. - redir_varname = vim_strsave(name); + redir_varname = xstrdup(name); redir_lval = xcalloc(1, sizeof(lval_T)); @@ -588,7 +588,7 @@ int var_redir_start(char_u *name, int append) /// :redir => foo /// :let foo /// :redir END -void var_redir_str(char_u *value, int value_len) +void var_redir_str(char *value, int value_len) { int len; @@ -646,7 +646,7 @@ int eval_charconvert(const char *const enc_from, const char *const enc_to, set_vim_var_string(VV_CC_TO, enc_to, -1); set_vim_var_string(VV_FNAME_IN, fname_from, -1); set_vim_var_string(VV_FNAME_OUT, fname_to, -1); - if (eval_to_bool(p_ccv, &err, NULL, false)) { + if (eval_to_bool((char *)p_ccv, &err, NULL, false)) { err = true; } set_vim_var_string(VV_CC_FROM, NULL, -1); @@ -666,7 +666,7 @@ int eval_printexpr(const char *const fname, const char *const args) set_vim_var_string(VV_FNAME_IN, fname, -1); set_vim_var_string(VV_CMDARG, args, -1); - if (eval_to_bool(p_pexpr, &err, NULL, false)) { + if (eval_to_bool((char *)p_pexpr, &err, NULL, false)) { err = true; } set_vim_var_string(VV_FNAME_IN, NULL, -1); @@ -686,7 +686,7 @@ void eval_diff(const char *const origfile, const char *const newfile, const char set_vim_var_string(VV_FNAME_IN, origfile, -1); set_vim_var_string(VV_FNAME_NEW, newfile, -1); set_vim_var_string(VV_FNAME_OUT, outfile, -1); - (void)eval_to_bool(p_dex, &err, NULL, FALSE); + (void)eval_to_bool((char *)p_dex, &err, NULL, false); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_NEW, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); @@ -699,7 +699,7 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch set_vim_var_string(VV_FNAME_IN, origfile, -1); set_vim_var_string(VV_FNAME_DIFF, difffile, -1); set_vim_var_string(VV_FNAME_OUT, outfile, -1); - (void)eval_to_bool(p_pex, &err, NULL, FALSE); + (void)eval_to_bool((char *)p_pex, &err, NULL, false); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_DIFF, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); @@ -711,7 +711,7 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch /// @param skip only parse, don't execute /// /// @return TRUE or FALSE. -int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) +int eval_to_bool(char *arg, bool *error, char **nextcmd, int skip) { typval_T tv; bool retval = false; @@ -736,10 +736,10 @@ int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) } /// Call eval1() and give an error message if not done at a lower level. -static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) +static int eval1_emsg(char **arg, typval_T *rettv, bool evaluate) FUNC_ATTR_NONNULL_ARG(1, 2) { - const char_u *const start = *arg; + const char *const start = *arg; const int did_emsg_before = did_emsg; const int called_emsg_before = called_emsg; @@ -773,36 +773,36 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r funcexe_T funcexe = FUNCEXE_INIT; if (expr->v_type == VAR_FUNC) { - const char_u *const s = expr->vval.v_string; + const char *const s = (char *)expr->vval.v_string; if (s == NULL || *s == NUL) { return FAIL; } funcexe.evaluate = true; - if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else if (expr->v_type == VAR_PARTIAL) { partial_T *const partial = expr->vval.v_partial; - const char_u *const s = partial_name(partial); + const char *const s = partial_name(partial); if (s == NULL || *s == NUL) { return FAIL; } funcexe.evaluate = true; funcexe.partial = partial; - if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else { char buf[NUMBUFLEN]; - char_u *s = (char_u *)tv_get_string_buf_chk(expr, buf); + char *s = (char *)tv_get_string_buf_chk(expr, buf); if (s == NULL) { return FAIL; } - s = skipwhite(s); + s = (char *)skipwhite((char_u *)s); if (eval1_emsg(&s, rettv, true) == FAIL) { return FAIL; } - if (*skipwhite(s) != NUL) { // check for trailing chars after expr + if (*skipwhite((char_u *)s) != NUL) { // check for trailing chars after expr tv_clear(rettv); semsg(_(e_invexpr2), s); return FAIL; @@ -845,7 +845,7 @@ char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip if (skip) { emsg_skip++; } - if (eval0((char_u *)arg, &tv, (char_u **)nextcmd, !skip) == FAIL || skip) { + if (eval0((char *)arg, &tv, (char **)nextcmd, !skip) == FAIL || skip) { retval = NULL; } else { retval = xstrdup(tv_get_string(&tv)); @@ -861,12 +861,12 @@ char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip /// Skip over an expression at "*pp". /// /// @return FAIL for an error, OK otherwise. -int skip_expr(char_u **pp) +int skip_expr(char **pp) { typval_T rettv; - *pp = skipwhite(*pp); - return eval1(pp, &rettv, FALSE); + *pp = (char *)skipwhite((char_u *)(*pp)); + return eval1(pp, &rettv, false); } /// Top level evaluation function, returning a string. @@ -875,7 +875,7 @@ int skip_expr(char_u **pp) /// a Float to a String. /// /// @return pointer to allocated memory, or NULL for failure. -char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) +char *eval_to_string(char *arg, char **nextcmd, bool convert) { typval_T tv; char *retval; @@ -904,16 +904,16 @@ char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) tv_clear(&tv); } - return (char_u *)retval; + return retval; } /// Call eval_to_string() without using current local variables and using /// textlock. /// /// @param use_sandbox when TRUE, use the sandbox. -char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) +char *eval_to_string_safe(char *arg, char **nextcmd, int use_sandbox) { - char_u *retval; + char *retval; funccal_entry_T funccal_entry; save_funccal(&funccal_entry); @@ -934,11 +934,11 @@ char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) /// Evaluates "expr" silently. /// /// @return -1 for an error. -varnumber_T eval_to_number(char_u *expr) +varnumber_T eval_to_number(char *expr) { typval_T rettv; varnumber_T retval; - char_u *p = skipwhite(expr); + char *p = (char *)skipwhite((char_u *)expr); ++emsg_off; @@ -957,7 +957,7 @@ varnumber_T eval_to_number(char_u *expr) /// /// @return an allocated typval_T with the result or /// NULL when there is an error. -typval_T *eval_expr(char_u *arg) +typval_T *eval_expr(char *arg) { typval_T *tv = xmalloc(sizeof(*tv)); if (eval0(arg, tv, NULL, true) == FAIL) { @@ -1009,17 +1009,17 @@ void find_win_for_curbuf(void) /// For the "expr:" part of 'spellsuggest'. /// /// @return NULL when there is an error. -list_T *eval_spell_expr(char_u *badword, char_u *expr) +list_T *eval_spell_expr(char *badword, char *expr) { typval_T save_val; typval_T rettv; list_T *list = NULL; - char_u *p = skipwhite(expr); + char *p = (char *)skipwhite((char_u *)expr); // Set "v:val" to the bad word. prepare_vimvar(VV_VAL, &save_val); vimvars[VV_VAL].vv_type = VAR_STRING; - vimvars[VV_VAL].vv_str = badword; + vimvars[VV_VAL].vv_str = (char_u *)badword; if (p_verbose == 0) { ++emsg_off; } @@ -1073,7 +1073,7 @@ int get_spellword(list_T *const list, const char **ret_word) // should have type VAR_UNKNOWN. // // @return OK or FAIL. -int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *rettv) +int call_vim_function(const char *func, int argc, typval_T *argv, typval_T *rettv) FUNC_ATTR_NONNULL_ALL { int ret; @@ -1082,7 +1082,7 @@ int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *re if (len >= 6 && !memcmp(func, "v:lua.", 6)) { func += 6; - len = check_luafunc_name((const char *)func, false); + len = check_luafunc_name(func, false); if (len == 0) { ret = FAIL; goto fail; @@ -1096,7 +1096,7 @@ int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *re funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; funcexe.partial = pt; - ret = call_func(func, len, rettv, argc, argv, &funcexe); + ret = call_func((char_u *)func, len, rettv, argc, argv, &funcexe); fail: if (ret == FAIL) { @@ -1112,13 +1112,13 @@ fail: /// @param[in] argv Array with typval_T arguments. /// /// @return -1 when calling function fails, result of function otherwise. -varnumber_T call_func_retnr(const char_u *func, int argc, typval_T *argv) +varnumber_T call_func_retnr(const char *func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL { typval_T rettv; varnumber_T retval; - if (call_vim_function(func, argc, argv, &rettv) == FAIL) { + if (call_vim_function((char *)func, argc, argv, &rettv) == FAIL) { return -1; } retval = tv_get_number_chk(&rettv, NULL); @@ -1138,7 +1138,7 @@ char *call_func_retstr(const char *const func, int argc, typval_T *argv) { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function((const char_u *)func, argc, argv, &rettv) + if (call_vim_function(func, argc, argv, &rettv) == FAIL) { return NULL; } @@ -1155,13 +1155,13 @@ char *call_func_retstr(const char *const func, int argc, typval_T *argv) /// /// @return [allocated] NULL when calling function fails or return tv is not a /// List, allocated List otherwise. -void *call_func_retlist(const char_u *func, int argc, typval_T *argv) +void *call_func_retlist(const char *func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function(func, argc, argv, &rettv) == FAIL) { + if (call_vim_function((char *)func, argc, argv, &rettv) == FAIL) { return NULL; } @@ -1212,7 +1212,7 @@ void prof_child_exit(proftime_T *tm) /// Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding /// it in "*cp". Doesn't give error messages. -int eval_foldexpr(char_u *arg, int *cp) +int eval_foldexpr(char *arg, int *cp) { typval_T tv; varnumber_T retval; @@ -1235,11 +1235,11 @@ int eval_foldexpr(char_u *arg, int *cp) } else { // If the result is a string, check if there is a non-digit before // the number. - char_u *s = tv.vval.v_string; + char *s = (char *)tv.vval.v_string; if (!ascii_isdigit(*s) && *s != '-') { - *cp = *s++; + *cp = (char_u)(*s++); } - retval = atol((char *)s); + retval = atol(s); } tv_clear(&tv); } @@ -1273,13 +1273,13 @@ void ex_const(exarg_T *eap) /// indentation in the 'cmd' line) is stripped. /// /// @return a List with {lines} or NULL. -static list_T *heredoc_get(exarg_T *eap, char_u *cmd) +static list_T *heredoc_get(exarg_T *eap, char *cmd) { - char_u *marker; - char_u *p; + char *marker; + char *p; int marker_indent_len = 0; int text_indent_len = 0; - char_u *text_indent = NULL; + char *text_indent = NULL; if (eap->getline == NULL) { emsg(_("E991: cannot use =<< here")); @@ -1287,16 +1287,16 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) } // Check for the optional 'trim' word before the marker - cmd = skipwhite(cmd); + cmd = (char *)skipwhite((char_u *)cmd); if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || ascii_iswhite(cmd[4]))) { - cmd = skipwhite(cmd + 4); + cmd = (char *)skipwhite((char_u *)cmd + 4); // Trim the indentation from all the lines in the here document. // The amount of indentation trimmed is the same as the indentation of // the first line after the :let command line. To find the end marker // the indent of the :let command line is trimmed. - p = *eap->cmdlinep; + p = (char *)(*eap->cmdlinep); while (ascii_iswhite(*p)) { p++; marker_indent_len++; @@ -1306,9 +1306,9 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) // The marker is the next word. if (*cmd != NUL && *cmd != '"') { - marker = skipwhite(cmd); - p = skiptowhite(marker); - if (*skipwhite(p) != NUL && *skipwhite(p) != '"') { + marker = (char *)skipwhite((char_u *)cmd); + p = (char *)skiptowhite((char_u *)marker); + if (*skipwhite((char_u *)p) != NUL && *skipwhite((char_u *)p) != '"') { emsg(_(e_trailing)); return NULL; } @@ -1327,7 +1327,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) int mi = 0; int ti = 0; - char_u *theline = eap->getline(NUL, eap->cookie, 0, false); + char *theline = (char *)eap->getline(NUL, eap->cookie, 0, false); if (theline == NULL) { semsg(_("E990: Missing end marker '%s'"), marker); break; @@ -1351,7 +1351,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) p++; text_indent_len++; } - text_indent = vim_strnsave(theline, text_indent_len); + text_indent = xstrnsave(theline, text_indent_len); } // with "trim": skip the indent matching the first line if (text_indent != NULL) { @@ -1362,7 +1362,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) } } - tv_list_append_string(l, (char *)(theline + ti), -1); + tv_list_append_string(l, theline + ti, -1); xfree(theline); } xfree(text_indent); @@ -1389,24 +1389,24 @@ void ex_let(exarg_T *eap) static void ex_let_const(exarg_T *eap, const bool is_const) { - char_u *arg = eap->arg; - char_u *expr = NULL; + char *arg = (char *)eap->arg; + char *expr = NULL; typval_T rettv; int i; int var_count = 0; int semicolon = 0; - char_u op[2]; - char_u *argend; - int first = TRUE; + char op[2]; + char *argend; + int first = true; - argend = (char_u *)skip_var_list(arg, &var_count, &semicolon); + argend = (char *)skip_var_list(arg, &var_count, &semicolon); if (argend == NULL) { return; } if (argend > arg && argend[-1] == '.') { // For var.='str'. argend--; } - expr = skipwhite(argend); + expr = (char *)skipwhite((char_u *)argend); if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) { // ":let" without "=": list variables @@ -1414,7 +1414,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) emsg(_(e_invarg)); } else if (!ends_excmd(*arg)) { // ":let var1 var2" - arg = (char_u *)list_arg_vars(eap, (const char *)arg, &first); + arg = (char *)list_arg_vars(eap, (const char *)arg, &first); } else if (!eap->skip) { // ":let" list_glob_vars(&first); @@ -1425,7 +1425,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) list_func_vars(&first); list_vim_vars(&first); } - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char_u *)arg); } else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') { // HERE document list_T *l = heredoc_get(eap, expr + 3); @@ -1434,8 +1434,8 @@ static void ex_let_const(exarg_T *eap, const bool is_const) if (!eap->skip) { op[0] = '='; op[1] = NUL; - (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, - is_const, op); + (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + is_const, (char *)op); } tv_clear(&rettv); } @@ -1449,23 +1449,23 @@ static void ex_let_const(exarg_T *eap, const bool is_const) expr++; } } - expr = skipwhite(expr + 2); + expr = (char *)skipwhite((char_u *)expr + 2); } else { - expr = skipwhite(expr + 1); + expr = (char *)skipwhite((char_u *)expr + 1); } if (eap->skip) { ++emsg_skip; } - i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); + i = eval0(expr, &rettv, (char **)&eap->nextcmd, !eap->skip); if (eap->skip) { if (i != FAIL) { tv_clear(&rettv); } emsg_skip--; } else if (i != FAIL) { - (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, - is_const, op); + (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + is_const, (char *)op); tv_clear(&rettv); } } @@ -1483,10 +1483,10 @@ static void ex_let_const(exarg_T *eap, const bool is_const) /// @param is_const lock variables for :const /// /// @return OK or FAIL; -static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, int var_count, - int is_const, char_u *op) +static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, int var_count, + int is_const, char *op) { - char_u *arg = arg_start; + char *arg = arg_start; typval_T ltv; if (*arg != '[') { @@ -1522,16 +1522,15 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, listitem_T *item = tv_list_first(l); size_t rest_len = tv_list_len(l); while (*arg != ']') { - arg = skipwhite(arg + 1); - arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, - (const char_u *)",;]", op); + arg = (char *)skipwhite((char_u *)arg + 1); + arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, ",;]", op); if (arg == NULL) { return FAIL; } rest_len--; item = TV_LIST_ITEM_NEXT(l, item); - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); if (*arg == ';') { /* Put the rest of the list (may be empty) in the var after ';'. * Create a new list for this. */ @@ -1546,8 +1545,7 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, ltv.vval.v_list = rest_list; tv_list_ref(rest_list); - arg = ex_let_one(skipwhite(arg + 1), <v, false, is_const, (char_u *)"]", - op); + arg = ex_let_one((char *)skipwhite((char_u *)arg + 1), <v, false, is_const, "]", op); tv_clear(<v); if (arg == NULL) { return FAIL; @@ -1568,24 +1566,24 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, /// for "[var, var; var]" set "semicolon". /// /// @return NULL for an error. -static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semicolon) +static const char *skip_var_list(const char *arg, int *var_count, int *semicolon) { - const char_u *p; - const char_u *s; + const char *p; + const char *s; if (*arg == '[') { // "[var, var]": find the matching ']'. p = arg; for (;;) { - p = skipwhite(p + 1); // skip whites after '[', ';' or ',' - s = skip_var_one(p); + p = (char *)skipwhite((char_u *)p + 1); // skip whites after '[', ';' or ',' + s = skip_var_one((char *)p); if (s == p) { semsg(_(e_invarg2), p); return NULL; } ++*var_count; - p = skipwhite(s); + p = (char *)skipwhite((char_u *)s); if (*p == ']') { break; } else if (*p == ';') { @@ -1601,19 +1599,19 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semic } return p + 1; } else { - return skip_var_one(arg); + return skip_var_one((char *)arg); } } /// Skip one (assignable) variable name, including @r, $VAR, &option, d.key, /// l[idx]. -static const char_u *skip_var_one(const char_u *arg) +static const char *skip_var_one(const char *arg) { if (*arg == '@' && arg[1] != NUL) { return arg + 2; } - return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, - NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); + return (char *)find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, + NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); } /// List variables for hashtab "ht" with prefix "prefix". @@ -1696,8 +1694,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) while (!ends_excmd(*arg) && !got_int) { if (error || eap->skip) { - arg = (const char *)find_name_end((char_u *)arg, NULL, NULL, - FNE_INCL_BR | FNE_CHECK_START); + arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); if (!ascii_iswhite(*arg) && !ends_excmd(*arg)) { emsg_severe = true; emsg(_(e_trailing)); @@ -1727,9 +1724,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) } else { // handle d.key, l[idx], f(expr) const char *const arg_subsc = arg; - if (handle_subscript(&arg, &tv, true, true, (const char_u *)name, - (const char_u **)&name) - == FAIL) { + if (handle_subscript(&arg, &tv, true, true, name, &name) == FAIL) { error = true; } else { if (arg == arg_subsc && len == 2 && name[1] == ':') { @@ -1790,14 +1785,14 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) /// /// @return a pointer to the char just after the var name or NULL in case of /// error. -static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, const bool is_const, - const char_u *const endchars, const char_u *const op) +static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bool is_const, + const char *const endchars, const char *const op) FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT { - char_u *arg_end = NULL; + char *arg_end = NULL; int len; int opt_flags; - char_u *tofree = NULL; + char *tofree = NULL; /* * ":let $VAR = expr": Set environment variable. @@ -1809,15 +1804,15 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons } // Find the end of the name. arg++; - char *name = (char *)arg; - len = get_env_len((const char_u **)&arg); + char *name = arg; + len = get_env_len((const char **)&arg); if (len == 0) { semsg(_(e_invarg2), name - 1); } else { if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg)) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { const char c1 = name[len]; @@ -1827,7 +1822,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons char *s = vim_getenv(name); if (s != NULL) { - tofree = concat_str((const char_u *)s, (const char_u *)p); + tofree = (char *)concat_str((const char_u *)s, (const char_u *)p); p = (const char *)tofree; xfree(s); } @@ -1860,7 +1855,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons char *const p = (char *)find_option_end((const char **)&arg, &opt_flags); if (p == NULL || (endchars != NULL - && vim_strchr(endchars, *skipwhite((const char_u *)p)) == NULL)) { + && vim_strchr((char_u *)endchars, *skipwhite((const char_u *)p)) == NULL)) { emsg(_(e_letunexp)); } else { int opt_type; @@ -1876,7 +1871,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons s = tv_get_string_chk(tv); // != NULL if number or string. } if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value((char *)arg, &numval, (char_u **)&stringval, + opt_type = get_option_value(arg, &numval, (char_u **)&stringval, opt_flags); if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { @@ -1908,7 +1903,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons if (s != NULL || tv->v_type == VAR_BOOL || tv->v_type == VAR_SPECIAL) { set_option_value((const char *)arg, n, s, opt_flags); - arg_end = (char_u *)p; + arg_end = p; } *p = c1; xfree(stringval); @@ -1923,17 +1918,17 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg + 1)) == NULL) { emsg(_(e_letunexp)); } else { - char_u *s; + char *s; - char_u *ptofree = NULL; + char *ptofree = NULL; const char *p = tv_get_string_chk(tv); if (p != NULL && op != NULL && *op == '.') { s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { - ptofree = concat_str(s, (const char_u *)p); + ptofree = (char *)concat_str((char_u *)s, (const char_u *)p); p = (const char *)ptofree; xfree(s); } @@ -1953,12 +1948,12 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons else if (eval_isnamec1(*arg) || *arg == '{') { lval_T lv; - char_u *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); + char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); if (p != NULL && lv.ll_name != NULL) { - if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) { + if (endchars != NULL && vim_strchr((char_u *)endchars, *skipwhite((char_u *)p)) == NULL) { emsg(_(e_letunexp)); } else { - set_var_lval(&lv, p, tv, copy, is_const, (const char *)op); + set_var_lval(&lv, p, tv, copy, is_const, op); arg_end = p; } } @@ -1995,8 +1990,8 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons /// /// @return A pointer to just after the name, including indexes. Returns NULL /// for a parsing error, but it is still needed to free items in lp. -char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, const bool unlet, - const bool skip, const int flags, const int fne_flags) +char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const bool unlet, + const bool skip, const int flags, const int fne_flags) FUNC_ATTR_NONNULL_ARG(1, 3) { dictitem_T *v; @@ -2013,17 +2008,16 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co if (skip) { // When skipping just find the end of the name. lp->ll_name = (const char *)name; - return (char_u *)find_name_end((const char_u *)name, NULL, NULL, - FNE_INCL_BR | fne_flags); + return (char *)find_name_end(name, NULL, NULL, + FNE_INCL_BR | fne_flags); } // Find the end of the name. - char_u *expr_start; - char_u *expr_end; - char_u *p = (char_u *)find_name_end(name, - (const char_u **)&expr_start, - (const char_u **)&expr_end, - fne_flags); + char *expr_start; + char *expr_end; + char *p = (char *)find_name_end(name, (const char **)&expr_start, + (const char **)&expr_end, + fne_flags); if (expr_start != NULL) { // Don't expand the name when we already know there is an error. if (unlet && !ascii_iswhite(*p) && !ends_excmd(*p) @@ -2032,8 +2026,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co return NULL; } - lp->ll_exp_name = (char *)make_expanded_name(name, expr_start, expr_end, - p); + lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); lp->ll_name = lp->ll_exp_name; if (lp->ll_exp_name == NULL) { // Report an invalid expression in braces, unless the @@ -2092,7 +2085,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co } int len = -1; - char_u *key = NULL; + char *key = NULL; if (*p == '.') { key = p + 1; for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} @@ -2105,7 +2098,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co p = key + len; } else { // Get the index [expr] or the first index [expr: ]. - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); if (*p == ':') { empty1 = true; } else { @@ -2118,7 +2111,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co tv_clear(&var1); return NULL; } - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); } // Optionally get the second index [ :expr]. @@ -2139,7 +2132,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co tv_clear(&var1); return NULL; } - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); if (*p == ']') { lp->ll_empty2 = true; } else { @@ -2176,7 +2169,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co if (lp->ll_tv->v_type == VAR_DICT) { if (len == -1) { // "[key]": get key from "var1" - key = (char_u *)tv_get_string(&var1); // is number or string + key = (char *)tv_get_string(&var1); // is number or string } lp->ll_list = NULL; lp->ll_dict = lp->ll_tv->vval.v_dict; @@ -2190,7 +2183,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co int wrong; if (len != -1) { - prevval = key[len]; + prevval = (char_u)key[len]; key[len] = NUL; } else { prevval = 0; // Avoid compiler warning. @@ -2232,9 +2225,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co return NULL; } if (len == -1) { - lp->ll_newkey = vim_strsave(key); + lp->ll_newkey = xstrdup(key); } else { - lp->ll_newkey = vim_strnsave(key, len); + lp->ll_newkey = xstrnsave(key, len); } tv_clear(&var1); break; @@ -2361,7 +2354,7 @@ void clear_lval(lval_T *lp) /// @param endp points to just after the parsed name. /// @param op NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", /// "%" for "%=", "." for ".=" or "=" for "=". -static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, const bool is_const, +static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, const bool is_const, const char *op) { int cc; @@ -2369,7 +2362,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co dictitem_T *di; if (lp->ll_tv == NULL) { - cc = *endp; + cc = (char_u)(*endp); *endp = NUL; if (lp->ll_blob != NULL) { if (op != NULL && *op != '=') { @@ -2398,7 +2391,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co } } else { bool error = false; - const char_u val = tv_get_number_chk(rettv, &error); + const char val = tv_get_number_chk(rettv, &error); if (!error) { garray_T *const gap = &lp->ll_blob->bv_ga; @@ -2551,7 +2544,7 @@ notify: if (watched) { if (oldtv.v_type == VAR_UNKNOWN) { assert(lp->ll_newkey != NULL); - tv_dict_watcher_notify(dict, (char *)lp->ll_newkey, lp->ll_tv, NULL); + tv_dict_watcher_notify(dict, lp->ll_newkey, lp->ll_tv, NULL); } else { dictitem_T *di_ = lp->ll_di; assert(di_->di_key != NULL); @@ -2570,21 +2563,21 @@ notify: /// @param[out] *errp set to TRUE for an error, FALSE otherwise; /// /// @return a pointer that holds the info. Null when there is an error. -void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) +void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) { forinfo_T *fi = xcalloc(1, sizeof(forinfo_T)); - const char_u *expr; + const char *expr; typval_T tv; list_T *l; *errp = true; // Default: there is an error. - expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); + expr = skip_var_list((char *)arg, &fi->fi_varcount, &fi->fi_semicolon); if (expr == NULL) { return fi; } - expr = skipwhite(expr); + expr = (char *)skipwhite((char_u *)expr); if (expr[0] != 'i' || expr[1] != 'n' || !ascii_iswhite(expr[2])) { emsg(_("E690: Missing \"in\" after :for")); return fi; @@ -2593,7 +2586,7 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) if (skip) { ++emsg_skip; } - if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) { + if (eval0((char *)skipwhite((char_u *)expr + 2), &tv, nextcmdp, !skip) == OK) { *errp = false; if (!skip) { if (tv.v_type == VAR_LIST) { @@ -2621,10 +2614,10 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) tv_clear(&tv); } else if (tv.v_type == VAR_STRING) { fi->fi_byte_idx = 0; - fi->fi_string = tv.vval.v_string; + fi->fi_string = (char *)tv.vval.v_string; tv.vval.v_string = NULL; if (fi->fi_string == NULL) { - fi->fi_string = vim_strsave((char_u *)""); + fi->fi_string = xstrdup(""); } } else { emsg(_(e_string_list_or_blob_required)); @@ -2646,7 +2639,7 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) /// /// @return true when a valid item was found, false when at end of list or /// something wrong. -bool next_for_item(void *fi_void, char_u *arg) +bool next_for_item(void *fi_void, char *arg) { forinfo_T *fi = (forinfo_T *)fi_void; @@ -2659,19 +2652,18 @@ bool next_for_item(void *fi_void, char_u *arg) tv.v_lock = VAR_FIXED; tv.vval.v_number = tv_blob_get(fi->fi_blob, fi->fi_bi); fi->fi_bi++; - return ex_let_vars(arg, &tv, true, - fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; + return ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; } if (fi->fi_string != NULL) { - const int len = utfc_ptr2len(fi->fi_string + fi->fi_byte_idx); + const int len = utfc_ptr2len((char_u *)fi->fi_string + fi->fi_byte_idx); if (len == 0) { return false; } typval_T tv; tv.v_type = VAR_STRING; tv.v_lock = VAR_FIXED; - tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len); + tv.vval.v_string = vim_strnsave((char_u *)fi->fi_string + fi->fi_byte_idx, len); fi->fi_byte_idx += len; const int result = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; @@ -2711,19 +2703,19 @@ void free_for_info(void *fi_void) } -void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) +void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) FUNC_ATTR_NONNULL_ALL { int got_eq = FALSE; int c; - char_u *p; + char *p; if (cmdidx == CMD_let || cmdidx == CMD_const) { xp->xp_context = EXPAND_USER_VARS; - if (strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) { + if (strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) { // ":let var1 var2 ...": find last space. for (p = arg + STRLEN(arg); p >= arg;) { - xp->xp_pattern = p; + xp->xp_pattern = (char_u *)p; MB_PTR_BACK(arg, p); if (ascii_iswhite(*p)) { break; @@ -2735,7 +2727,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS : EXPAND_EXPRESSION; } - while ((xp->xp_pattern = (char_u *)strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { + while ((xp->xp_pattern = (char_u *)strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { c = *xp->xp_pattern; if (c == '&') { c = xp->xp_pattern[1]; @@ -2791,9 +2783,9 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) // anyway. xp->xp_context = EXPAND_EXPRESSION; } - arg = xp->xp_pattern; + arg = (char *)xp->xp_pattern; if (*arg != NUL) { - while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) {} + while ((c = (char_u)(*++arg)) != NUL && (c == ' ' || c == '\t')) {} } } @@ -2804,22 +2796,22 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) || cmdidx == CMD_echomsg) && xp->xp_context == EXPAND_EXPRESSION) { for (;;) { - char_u *const n = skiptowhite(arg); + char *const n = (char *)skiptowhite((char_u *)arg); - if (n == arg || ascii_iswhite_or_nul(*skipwhite(n))) { + if (n == arg || ascii_iswhite_or_nul(*skipwhite((char_u *)n))) { break; } - arg = skipwhite(n); + arg = (char *)skipwhite((char_u *)n); } } - xp->xp_pattern = arg; + xp->xp_pattern = (char_u *)arg; } /// ":unlet[!] var1 ... " command. void ex_unlet(exarg_T *eap) { - ex_unletlock(eap, eap->arg, 0, do_unlet_var); + ex_unletlock(eap, (char *)eap->arg, 0, do_unlet_var); } // TODO(ZyX-I): move to eval/ex_cmds @@ -2827,14 +2819,14 @@ void ex_unlet(exarg_T *eap) /// ":lockvar" and ":unlockvar" commands void ex_lockvar(exarg_T *eap) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; int deep = 2; if (eap->forceit) { deep = -1; } else if (ascii_isdigit(*arg)) { - deep = getdigits_int(&arg, false, -1); - arg = skipwhite(arg); + deep = getdigits_int((char_u **)&arg, false, -1); + arg = (char *)skipwhite((char_u *)arg); } ex_unletlock(eap, arg, deep, do_lock_var); @@ -2851,11 +2843,11 @@ void ex_lockvar(exarg_T *eap) /// @param[in] deep Levels to (un)lock for :(un)lockvar, -1 to (un)lock /// everything. /// @param[in] callback Appropriate handler for the command. -static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_callback callback) +static void ex_unletlock(exarg_T *eap, char *argstart, int deep, ex_unletlock_callback callback) FUNC_ATTR_NONNULL_ALL { - char_u *arg = argstart; - char_u *name_end; + char *arg = argstart; + char *name_end; bool error = false; lval_T lv; @@ -2864,7 +2856,7 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_ lv.ll_name = (const char *)arg; lv.ll_tv = NULL; arg++; - if (get_env_len((const char_u **)&arg) == 0) { + if (get_env_len((const char **)&arg) == 0) { semsg(_(e_invarg2), arg - 1); return; } @@ -2899,10 +2891,10 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_ clear_lval(&lv); } } - arg = skipwhite(name_end); + arg = (char *)skipwhite((char_u *)name_end); } while (!ends_excmd(*arg)); - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char_u *)arg); } // TODO(ZyX-I): move to eval/ex_cmds @@ -2915,7 +2907,7 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_ /// @param[in] deep Unused. /// /// @return OK on success, or FAIL on failure. -static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep FUNC_ATTR_UNUSED) +static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_ATTR_UNUSED) FUNC_ATTR_NONNULL_ALL { int forceit = eap->forceit; @@ -2923,7 +2915,7 @@ static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep FUN int cc; if (lp->ll_tv == NULL) { - cc = *name_end; + cc = (char_u)(*name_end); *name_end = NUL; // Environment variable, normal name or expanded name. @@ -3081,7 +3073,7 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit) /// @param[in] deep Levels to (un)lock, -1 to (un)lock everything. /// /// @return OK on success, or FAIL on failure. -static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, exarg_T *eap, int deep) +static int do_lock_var(lval_T *lp, char *name_end FUNC_ATTR_UNUSED, exarg_T *eap, int deep) FUNC_ATTR_NONNULL_ARG(1, 3) { bool lock = eap->cmdidx == CMD_lockvar; @@ -3156,11 +3148,11 @@ void del_menutrans_vars(void) */ -static char_u *varnamebuf = NULL; +static char *varnamebuf = NULL; static size_t varnamebuflen = 0; /// Function to concatenate a prefix and a variable name. -char_u *cat_prefix_varname(int prefix, const char_u *name) +char *cat_prefix_varname(int prefix, const char *name) FUNC_ATTR_NONNULL_ALL { size_t len = STRLEN(name) + 3; @@ -3204,7 +3196,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) ++hi; } if (STRNCMP("g:", xp->xp_pattern, 2) == 0) { - return cat_prefix_varname('g', hi->hi_key); + return (char_u *)cat_prefix_varname('g', (char *)hi->hi_key); } return hi->hi_key; } @@ -3220,7 +3212,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return cat_prefix_varname('b', hi->hi_key); + return (char_u *)cat_prefix_varname('b', (char *)hi->hi_key); } // w: variables @@ -3234,7 +3226,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return cat_prefix_varname('w', hi->hi_key); + return (char_u *)cat_prefix_varname('w', (char *)hi->hi_key); } // t: variables @@ -3248,12 +3240,12 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return cat_prefix_varname('t', hi->hi_key); + return (char_u *)cat_prefix_varname('t', (char *)hi->hi_key); } // v: variables if (vidx < ARRAY_SIZE(vimvars)) { - return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); + return (char_u *)cat_prefix_varname('v', vimvars[vidx++].vv_name); } XFREE_CLEAR(varnamebuf); @@ -3266,21 +3258,21 @@ char_u *get_user_var_name(expand_T *xp, int idx) /// Does not use 'cpo' and always uses 'magic'. /// /// @return TRUE if "pat" matches "text". -int pattern_match(char_u *pat, char_u *text, bool ic) +int pattern_match(char *pat, char *text, bool ic) { int matches = 0; regmatch_T regmatch; // avoid 'l' flag in 'cpoptions' - char_u *save_cpo = p_cpo; + char *save_cpo = (char *)p_cpo; p_cpo = (char_u *)""; - regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = ic; - matches = vim_regexec_nl(®match, text, (colnr_T)0); + matches = vim_regexec_nl(®match, (char_u *)text, (colnr_T)0); vim_regfree(regmatch.regprog); } - p_cpo = save_cpo; + p_cpo = (char_u *)save_cpo; return matches; } @@ -3291,11 +3283,11 @@ int pattern_match(char_u *pat, char_u *text, bool ic) /// @param basetv "expr" for "expr->name(arg)" /// /// @return OK or FAIL. -static int eval_func(char_u **const arg, char_u *const name, const int name_len, - typval_T *const rettv, const bool evaluate, typval_T *const basetv) +static int eval_func(char **const arg, char *const name, const int name_len, typval_T *const rettv, + const bool evaluate, typval_T *const basetv) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { - char_u *s = name; + char *s = name; int len = name_len; if (!evaluate) { @@ -3305,7 +3297,7 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, // If "s" is the name of a variable of type VAR_FUNC // use its contents. partial_T *partial; - s = deref_func_name((const char *)s, &len, &partial, !evaluate); + s = (char *)deref_func_name((const char *)s, &len, &partial, !evaluate); // Need to make a copy, in case evaluating the arguments makes // the name invalid. @@ -3318,7 +3310,7 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, funcexe.evaluate = evaluate; funcexe.partial = partial; funcexe.basetv = basetv; - int ret = get_func_tv(s, len, rettv, arg, &funcexe); + int ret = get_func_tv((char_u *)s, len, rettv, (char_u **)arg, &funcexe); xfree(s); @@ -3356,14 +3348,14 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, /// Note: "rettv.v_lock" is not set. /// /// @return OK or FAIL. -int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) +int eval0(char *arg, typval_T *rettv, char **nextcmd, int evaluate) { int ret; - char_u *p; + char *p; const int did_emsg_before = did_emsg; const int called_emsg_before = called_emsg; - p = skipwhite(arg); + p = (char *)skipwhite((char_u *)arg); ret = eval1(&p, rettv, evaluate); if (ret == FAIL || !ends_excmd(*p)) { if (ret != FAIL) { @@ -3380,7 +3372,7 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) ret = FAIL; } if (nextcmd != NULL) { - *nextcmd = check_nextcmd(p); + *nextcmd = (char *)check_nextcmd((char_u *)p); } return ret; @@ -3397,7 +3389,7 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) /// Note: "rettv.v_lock" is not set. /// /// @return OK or FAIL. -int eval1(char_u **arg, typval_T *rettv, int evaluate) +int eval1(char **arg, typval_T *rettv, int evaluate) { int result; typval_T var2; @@ -3426,7 +3418,7 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (eval1(arg, rettv, evaluate && result) == FAIL) { // recursive! return FAIL; } @@ -3445,7 +3437,7 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) /* * Get the third variable. */ - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (eval1(arg, &var2, evaluate && !result) == FAIL) { // Recursive! if (evaluate && result) { tv_clear(rettv); @@ -3469,7 +3461,7 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) /// "arg" is advanced to the next non-white after the recognized expression. /// /// @return OK or FAIL. -static int eval2(char_u **arg, typval_T *rettv, int evaluate) +static int eval2(char **arg, typval_T *rettv, int evaluate) { typval_T var2; long result; @@ -3503,7 +3495,7 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = skipwhite(*arg + 2); + *arg = (char *)skipwhite((char_u *)(*arg) + 2); if (eval3(arg, &var2, evaluate && !result) == FAIL) { return FAIL; } @@ -3538,7 +3530,7 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) /// `arg` is advanced to the next non-white after the recognized expression. /// /// @return OK or FAIL. -static int eval3(char_u **arg, typval_T *rettv, int evaluate) +static int eval3(char **arg, typval_T *rettv, int evaluate) { typval_T var2; long result; @@ -3572,7 +3564,7 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = skipwhite(*arg + 2); + *arg = (char *)skipwhite((char_u *)(*arg) + 2); if (eval4(arg, &var2, evaluate && result) == FAIL) { return FAIL; } @@ -3616,10 +3608,10 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) /// "arg" is advanced to the next non-white after the recognized expression. /// /// @return OK or FAIL. -static int eval4(char_u **arg, typval_T *rettv, int evaluate) +static int eval4(char **arg, typval_T *rettv, int evaluate) { typval_T var2; - char_u *p; + char *p; exprtype_T type = EXPR_UNKNOWN; int len = 2; bool ic; @@ -3691,7 +3683,7 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) } // Get the second variable. - *arg = skipwhite(p + len); + *arg = (char *)skipwhite((char_u *)p + len); if (eval5(arg, &var2, evaluate) == FAIL) { tv_clear(rettv); return FAIL; @@ -3719,14 +3711,14 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) /// `arg` is advanced to the next non-white after the recognized expression. /// /// @return OK or FAIL. -static int eval5(char_u **arg, typval_T *rettv, int evaluate) +static int eval5(char **arg, typval_T *rettv, int evaluate) { typval_T var2; typval_T var3; int op; varnumber_T n1, n2; float_T f1 = 0, f2 = 0; - char_u *p; + char *p; /* * Get the first variable. @@ -3739,7 +3731,7 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate) * Repeat computing, until no '+', '-' or '.' is following. */ for (;;) { - op = **arg; + op = (char_u)(**arg); if (op != '+' && op != '-' && op != '.') { break; } @@ -3765,7 +3757,7 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate) if (op == '.' && *(*arg + 1) == '.') { // ..string concatenation (*arg)++; } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (eval6(arg, &var2, evaluate, op == '.') == FAIL) { tv_clear(rettv); return FAIL; @@ -3786,10 +3778,10 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate) tv_clear(&var2); return FAIL; } - p = concat_str((const char_u *)s1, (const char_u *)s2); + p = (char *)concat_str((const char_u *)s1, (const char_u *)s2); tv_clear(rettv); rettv->v_type = VAR_STRING; - rettv->vval.v_string = p; + rettv->vval.v_string = (char_u *)p; } else if (op == '+' && rettv->v_type == VAR_BLOB && var2.v_type == VAR_BLOB) { const blob_T *const b1 = rettv->vval.v_blob; @@ -3893,7 +3885,7 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate) /// @param[in] want_string True if "." is string_concatenation, otherwise /// float /// @return OK or FAIL. -static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) +static int eval6(char **arg, typval_T *rettv, int evaluate, int want_string) FUNC_ATTR_NO_SANITIZE_UNDEFINED { typval_T var2; @@ -3914,7 +3906,7 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) * Repeat computing, until no '*', '/' or '%' is following. */ for (;;) { - op = **arg; + op = (char_u)(**arg); if (op != '*' && op != '/' && op != '%') { break; } @@ -3938,8 +3930,8 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) /* * Get the second variable. */ - *arg = skipwhite(*arg + 1); - if (eval7(arg, &var2, evaluate, FALSE) == FAIL) { + *arg = (char *)skipwhite((char_u *)(*arg) + 1); + if (eval7(arg, &var2, evaluate, false) == FAIL) { return FAIL; } @@ -4034,14 +4026,14 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) /// @param want_string after "." operator /// /// @return OK or FAIL. -static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) +static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) { varnumber_T n; int len; - char_u *s; - const char_u *start_leader, *end_leader; + char *s; + const char *start_leader, *end_leader; int ret = OK; - char_u *alias; + char *alias; // Initialise variable so that tv_clear() can't mistake this for a // string and free a string that isn't there. @@ -4050,7 +4042,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) // Skip '!', '-' and '+' characters. They are handled later. start_leader = *arg; while (**arg == '!' || **arg == '-' || **arg == '+') { - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); } end_leader = *arg; @@ -4066,7 +4058,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) case '7': case '8': case '9': { - char_u *p = skipdigits(*arg + 1); + char *p = (char *)skipdigits((char_u *)(*arg) + 1); int get_float = false; // We accept a float when the format matches @@ -4076,7 +4068,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) // ":let vers = 1.2.3" doesn't fail. if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) { get_float = true; - p = skipdigits(p + 2); + p = (char *)skipdigits((char_u *)p + 2); if (*p == 'e' || *p == 'E') { ++p; if (*p == '-' || *p == '+') { @@ -4085,7 +4077,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) if (!ascii_isdigit(*p)) { get_float = false; } else { - p = skipdigits(p + 1); + p = (char *)skipdigits((char_u *)p + 1); } } if (ASCII_ISALPHA(*p) || *p == '.') { @@ -4095,7 +4087,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) if (get_float) { float_T f; - *arg += string2float((char *)*arg, &f); + *arg += string2float(*arg, &f); if (evaluate) { rettv->v_type = VAR_FLOAT; rettv->vval.v_float = f; @@ -4106,7 +4098,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) if (evaluate) { blob = tv_blob_alloc(); } - char_u *bp; + char *bp; for (bp = *arg + 2; ascii_isxdigit(bp[0]); bp += 2) { if (!ascii_isxdigit(bp[1])) { if (blob != NULL) { @@ -4131,7 +4123,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) *arg = bp; } else { // decimal, hex or octal number - vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0, true); + vim_str2nr((char_u *)(*arg), NULL, &len, STR2NR_ALL, &n, NULL, 0, true); if (len == 0) { semsg(_(e_invexpr2), *arg); ret = FAIL; @@ -4174,7 +4166,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) // Lambda: {arg, arg -> expr} // Dictionary: {'key': val, 'key': val} case '{': - ret = get_lambda_tv(arg, rettv, evaluate); + ret = get_lambda_tv((char_u **)arg, rettv, evaluate); if (ret == NOTDONE) { ret = dict_get_tv(arg, rettv, evaluate, false); } @@ -4203,7 +4195,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) // nested expression: (expression). case '(': - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); ret = eval1(arg, rettv, evaluate); // recursive! if (**arg == ')') { ++*arg; @@ -4223,7 +4215,7 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) // Must be a variable or function name. // Can also be a curly-braces kind of name: {expr}. s = *arg; - len = get_name_len((const char **)arg, (char **)&alias, evaluate, true); + len = get_name_len((const char **)arg, &alias, evaluate, true); if (alias != NULL) { s = alias; } @@ -4243,18 +4235,18 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) xfree(alias); } - *arg = skipwhite(*arg); + *arg = (char *)skipwhite((char_u *)(*arg)); // Handle following '[', '(' and '.' for expr[expr], expr.name, // expr(expr), expr->name(expr) if (ret == OK) { ret = handle_subscript((const char **)arg, rettv, evaluate, true, - start_leader, &end_leader); + (char *)start_leader, &end_leader); } // Apply logical NOT and unary '-', from right to left, ignore '+'. if (ret == OK && evaluate && end_leader > start_leader) { - ret = eval7_leader(rettv, start_leader, &end_leader); + ret = eval7_leader(rettv, (char *)start_leader, &end_leader); } return ret; } @@ -4263,11 +4255,11 @@ static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string) /// Adjusts "end_leaderp" until it is at "start_leader". /// /// @return OK on success, FAIL on failure. -static int eval7_leader(typval_T *const rettv, const char_u *const start_leader, - const char_u **const end_leaderp) +static int eval7_leader(typval_T *const rettv, const char *const start_leader, + const char **const end_leaderp) FUNC_ATTR_NONNULL_ALL { - const char_u *end_leader = *end_leaderp; + const char *end_leader = (char *)(*end_leaderp); int ret = OK; bool error = false; varnumber_T val = 0; @@ -4317,14 +4309,14 @@ static int eval7_leader(typval_T *const rettv, const char_u *const start_leader, /// to the name of the Lua function to call (after the /// "v:lua." prefix). /// @return OK on success, FAIL on failure. -static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool evaluate, +static int call_func_rettv(char **const arg, typval_T *const rettv, const bool evaluate, dict_T *const selfdict, typval_T *const basetv, - const char_u *const lua_funcname) + const char *const lua_funcname) FUNC_ATTR_NONNULL_ARG(1, 2) { partial_T *pt = NULL; typval_T functv; - const char_u *funcname; + const char *funcname; bool is_lua = false; // need to copy the funcref so that we can clear rettv @@ -4338,10 +4330,10 @@ static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool is_lua = is_luafunc(pt); funcname = is_lua ? lua_funcname : partial_name(pt); } else { - funcname = functv.vval.v_string; + funcname = (char *)functv.vval.v_string; } } else { - funcname = (char_u *)""; + funcname = ""; } funcexe_T funcexe = FUNCEXE_INIT; @@ -4351,8 +4343,8 @@ static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool funcexe.partial = pt; funcexe.selfdict = selfdict; funcexe.basetv = basetv; - const int ret = get_func_tv(funcname, is_lua ? *arg - funcname : -1, rettv, - arg, &funcexe); + const int ret = get_func_tv((char_u *)funcname, is_lua ? *arg - funcname : -1, rettv, + (char_u **)arg, &funcexe); // Clear the funcref afterwards, so that deleting it while // evaluating the arguments is possible (see test55). @@ -4371,7 +4363,7 @@ static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool /// @return FAIL or OK. /// /// @note "*arg" is advanced to after the ')'. -static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool evaluate, +static int eval_lambda(char **const arg, typval_T *const rettv, const bool evaluate, const bool verbose) FUNC_ATTR_NONNULL_ALL { @@ -4380,12 +4372,12 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool eva typval_T base = *rettv; rettv->v_type = VAR_UNKNOWN; - int ret = get_lambda_tv(arg, rettv, evaluate); + int ret = get_lambda_tv((char_u **)arg, rettv, evaluate); if (ret != OK) { return FAIL; } else if (**arg != '(') { if (verbose) { - if (*skipwhite(*arg) == '(') { + if (*skipwhite((char_u *)(*arg)) == '(') { emsg(_(e_nowhitespace)); } else { semsg(_(e_missingparen), "lambda"); @@ -4411,7 +4403,7 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool eva /// @param *arg points to the '-'. /// /// @return FAIL or OK. "*arg" is advanced to after the ')'. -static int eval_method(char_u **const arg, typval_T *const rettv, const bool evaluate, +static int eval_method(char **const arg, typval_T *const rettv, const bool evaluate, const bool verbose) FUNC_ATTR_NONNULL_ALL { @@ -4422,16 +4414,16 @@ static int eval_method(char_u **const arg, typval_T *const rettv, const bool eva // Locate the method name. int len; - char_u *name = *arg; - char_u *lua_funcname = NULL; + char *name = *arg; + char *lua_funcname = NULL; if (STRNCMP(name, "v:lua.", 6) == 0) { lua_funcname = name + 6; - *arg = (char_u *)skip_luafunc_name((const char *)lua_funcname); - *arg = skipwhite(*arg); // to detect trailing whitespace later + *arg = (char *)skip_luafunc_name((const char *)lua_funcname); + *arg = (char *)skipwhite((char_u *)(*arg)); // to detect trailing whitespace later len = *arg - lua_funcname; } else { - char_u *alias; - len = get_name_len((const char **)arg, (char **)&alias, evaluate, true); + char *alias; + len = get_name_len((const char **)arg, &alias, evaluate, true); if (alias != NULL) { name = alias; } @@ -4487,14 +4479,14 @@ static int eval_method(char_u **const arg, typval_T *const rettv, const bool eva /// @param verbose give error messages /// /// @returns FAIL or OK. "*arg" is advanced to after the ']'. -static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) +static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) { bool empty1 = false; bool empty2 = false; long n1, n2 = 0; ptrdiff_t len = -1; int range = false; - char_u *key = NULL; + char *key = NULL; switch (rettv->v_type) { case VAR_FUNC: @@ -4538,14 +4530,14 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) if (len == 0) { return FAIL; } - *arg = skipwhite(key + len); + *arg = (char *)skipwhite((char_u *)key + len); } else { /* * something[idx] * * Get the (first) variable from inside the []. */ - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (**arg == ':') { empty1 = true; } else if (eval1(arg, &var1, evaluate) == FAIL) { // Recursive! @@ -4560,8 +4552,8 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) * Get the second variable from inside the [:]. */ if (**arg == ':') { - range = TRUE; - *arg = skipwhite(*arg + 1); + range = true; + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (**arg == ']') { empty2 = true; } else if (eval1(arg, &var2, evaluate) == FAIL) { // Recursive! @@ -4590,7 +4582,7 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) } return FAIL; } - *arg = skipwhite(*arg + 1); // skip the ']' + *arg = (char *)skipwhite((char_u *)(*arg) + 1); // skip the ']' } if (evaluate) { @@ -4748,7 +4740,7 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) } if (len == -1) { - key = (char_u *)tv_get_string_chk(&var1); + key = (char *)tv_get_string_chk(&var1); if (key == NULL) { tv_clear(&var1); return FAIL; @@ -4800,7 +4792,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval FUNC_ATTR_NONNULL_ARG(1) { long numval; - char_u *stringval; + char *stringval; int opt_type; bool working = (**arg == '+'); // has("+option") int ret = OK; @@ -4823,7 +4815,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval char c = *option_end; *option_end = NUL; opt_type = get_option_value(*arg, &numval, - rettv == NULL ? NULL : &stringval, opt_flags); + rettv == NULL ? NULL : (char_u **)&stringval, opt_flags); if (opt_type == -3) { // invalid name if (rettv != NULL) { @@ -4842,7 +4834,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval rettv->vval.v_number = numval; } else { // string option rettv->v_type = VAR_STRING; - rettv->vval.v_string = stringval; + rettv->vval.v_string = (char_u *)stringval; } } else if (working && (opt_type == -2 || opt_type == -1)) { ret = FAIL; @@ -4857,9 +4849,9 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval /// Allocate a variable for a string constant. /// /// @return OK or FAIL. -static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) +static int get_string_tv(char **arg, typval_T *rettv, int evaluate) { - char_u *p; + char *p; unsigned int extra = 0; /* @@ -4893,9 +4885,9 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) * characters. */ const int len = (int)(p - *arg + extra); - char_u *name = xmalloc(len); + char *name = xmalloc(len); rettv->v_type = VAR_STRING; - rettv->vval.v_string = name; + rettv->vval.v_string = (char_u *)name; for (p = *arg + 1; *p != NUL && *p != '"';) { if (*p == '\\') { @@ -4937,7 +4929,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) // For "\u" store the number according to // 'encoding'. if (c != 'X') { - name += utf_char2bytes(nr, name); + name += utf_char2bytes(nr, (char_u *)name); } else { *name++ = nr; } @@ -4970,10 +4962,10 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) if (p[1] != '*') { flags |= FSK_SIMPLIFY; } - extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, false, NULL); + extra = trans_special((const char_u **)&p, STRLEN(p), (char_u *)name, flags, false, NULL); if (extra != 0) { name += extra; - if (name >= rettv->vval.v_string + len) { + if ((char_u *)name >= rettv->vval.v_string + len) { iemsg("get_string_tv() used more space than allocated"); } break; @@ -4982,11 +4974,11 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) FALLTHROUGH; default: - mb_copy_char((const char_u **)&p, &name); + mb_copy_char((const char_u **)&p, (char_u **)&name); break; } } else { - mb_copy_char((const char_u **)&p, &name); + mb_copy_char((const char_u **)&p, (char_u **)&name); } } *name = NUL; @@ -5001,10 +4993,10 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) /// Allocate a variable for a 'str''ing' constant. /// /// @return OK or FAIL. -static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) +static int get_lit_string_tv(char **arg, typval_T *rettv, int evaluate) { - char_u *p; - char_u *str; + char *p; + char *str; int reduce = 0; /* @@ -5036,7 +5028,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) */ str = xmalloc((p - *arg) - reduce); rettv->v_type = VAR_STRING; - rettv->vval.v_string = str; + rettv->vval.v_string = (char_u *)str; for (p = *arg + 1; *p != NUL;) { if (*p == '\'') { @@ -5045,7 +5037,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) } ++p; } - mb_copy_char((const char_u **)&p, &str); + mb_copy_char((const char_u **)&p, (char_u **)&str); } *str = NUL; *arg = p + 1; @@ -5054,13 +5046,13 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) } /// @return the function name of the partial. -char_u *partial_name(partial_T *pt) +char *partial_name(partial_T *pt) FUNC_ATTR_PURE { if (pt->pt_name != NULL) { - return pt->pt_name; + return (char *)pt->pt_name; } - return pt->pt_func->uf_name; + return (char *)pt->pt_func->uf_name; } // TODO(ZyX-I): Move to eval/typval.h @@ -5095,7 +5087,7 @@ void partial_unref(partial_T *pt) /// Allocate a variable for a List and fill it from "*arg". /// /// @return OK or FAIL. -static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate) +static int get_list_tv(char **arg, typval_T *rettv, int evaluate) { list_T *l = NULL; @@ -5103,7 +5095,7 @@ static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate) l = tv_list_alloc(kListLenShouldKnow); } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); while (**arg != ']' && **arg != NUL) { typval_T tv; if (eval1(arg, &tv, evaluate) == FAIL) { // Recursive! @@ -5121,7 +5113,7 @@ static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate) semsg(_("E696: Missing comma in List: %s"), *arg); goto failret; } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); } if (**arg != ']') { @@ -5133,7 +5125,7 @@ failret: return FAIL; } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (evaluate) { tv_list_set_ret(rettv, l); } @@ -5150,12 +5142,12 @@ bool func_equal(typval_T *tv1, typval_T *tv2, bool ic) // empty and NULL function name considered the same s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string - : partial_name(tv1->vval.v_partial); + : (char_u *)partial_name(tv1->vval.v_partial); if (s1 != NULL && *s1 == NUL) { s1 = NULL; } s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string - : partial_name(tv2->vval.v_partial); + : (char_u *)partial_name(tv2->vval.v_partial); if (s2 != NULL && *s2 == NUL) { s2 = NULL; } @@ -5698,19 +5690,19 @@ static inline bool set_ref_dict(dict_T *dict, int copyID) /// Get the key for *{key: val} into "tv" and advance "arg". /// /// @return FAIL when there is no valid key. -static int get_literal_key(char_u **arg, typval_T *tv) +static int get_literal_key(char **arg, typval_T *tv) FUNC_ATTR_NONNULL_ALL { - char_u *p; + char *p; if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') { return FAIL; } for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {} tv->v_type = VAR_STRING; - tv->vval.v_string = vim_strnsave(*arg, p - *arg); + tv->vval.v_string = vim_strnsave((char_u *)(*arg), p - *arg); - *arg = skipwhite(p); + *arg = (char *)skipwhite((char_u *)p); return OK; } @@ -5718,14 +5710,14 @@ static int get_literal_key(char_u **arg, typval_T *tv) /// "literal" is true for *{key: val} /// /// @return OK or FAIL. Returns NOTDONE for {expr}. -static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal) +static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) { dict_T *d = NULL; typval_T tvkey; typval_T tv; - char_u *key = NULL; + char *key = NULL; dictitem_T *item; - char_u *start = skipwhite(*arg + 1); + char *start = (char *)skipwhite((char_u *)(*arg) + 1); char buf[NUMBUFLEN]; /* @@ -5739,7 +5731,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal if (eval1(&start, &tv, false) == FAIL) { // recursive! return FAIL; } - if (*skipwhite(start) == '}') { + if (*skipwhite((char_u *)start) == '}') { return NOTDONE; } } @@ -5750,7 +5742,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal tvkey.v_type = VAR_UNKNOWN; tv.v_type = VAR_UNKNOWN; - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); while (**arg != '}' && **arg != NUL) { if ((literal ? get_literal_key(arg, &tvkey) @@ -5763,7 +5755,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal goto failret; } if (evaluate) { - key = (char_u *)tv_get_string_buf_chk(&tvkey, buf); + key = (char *)tv_get_string_buf_chk(&tvkey, buf); if (key == NULL) { // "key" is NULL when tv_get_string_buf_chk() gave an errmsg tv_clear(&tvkey); @@ -5771,7 +5763,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal } } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (eval1(arg, &tv, evaluate) == FAIL) { // Recursive! if (evaluate) { tv_clear(&tvkey); @@ -5802,7 +5794,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal semsg(_("E722: Missing comma in Dictionary: %s"), *arg); goto failret; } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); } if (**arg != '}') { @@ -5814,7 +5806,7 @@ failret: return FAIL; } - *arg = skipwhite(*arg + 1); + *arg = (char *)skipwhite((char_u *)(*arg) + 1); if (evaluate) { tv_dict_set_ret(rettv, d); } @@ -5860,37 +5852,37 @@ size_t string2float(const char *const text, float_T *const ret_value) /// @param arg Points to the '$'. It is advanced to after the name. /// /// @return FAIL if the name is invalid. -static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) +static int get_env_tv(char **arg, typval_T *rettv, int evaluate) { - char_u *name; - char_u *string = NULL; + char *name; + char *string = NULL; int len; int cc; ++*arg; name = *arg; - len = get_env_len((const char_u **)arg); + len = get_env_len((const char **)arg); if (evaluate) { if (len == 0) { return FAIL; // Invalid empty name. } - cc = name[len]; + cc = (char_u)name[len]; name[len] = NUL; // First try vim_getenv(), fast for normal environment vars. - string = (char_u *)vim_getenv((char *)name); + string = vim_getenv(name); if (string == NULL || *string == NUL) { xfree(string); // Next try expanding things like $VIM and ${HOME}. - string = expand_env_save(name - 1); + string = (char *)expand_env_save((char_u *)name - 1); if (string != NULL && *string == '$') { XFREE_CLEAR(string); } } name[len] = cc; rettv->v_type = VAR_STRING; - rettv->vval.v_string = string; + rettv->vval.v_string = (char_u *)string; } return OK; @@ -5948,7 +5940,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) blob_T *b = NULL; int rem = false; int todo; - char_u *ermsg = (char_u *)(map ? "map()" : "filter()"); + char *ermsg = map ? "map()" : "filter()"; const char *const arg_errmsg = (map ? N_("map() argument") : N_("filter() argument")); @@ -6050,7 +6042,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) tv_blob_set(b, i, tv.vval.v_number); } } else if (rem) { - char_u *const p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data; + char *const p = argvars[0].vval.v_blob->bv_ga.ga_data; memmove(p + i, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1); b->bv_ga.ga_len--; i--; @@ -6131,15 +6123,15 @@ theend: void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr fptr) { - char_u *s; - char_u *name; + char *s; + char *name; bool use_string = false; partial_T *arg_pt = NULL; - char_u *trans_name = NULL; + char *trans_name = NULL; if (argvars[0].v_type == VAR_FUNC) { // function(MyFunc, [arg], dict) - s = argvars[0].vval.v_string; + s = (char *)argvars[0].vval.v_string; } else if (argvars[0].v_type == VAR_PARTIAL && argvars[0].vval.v_partial != NULL) { // function(dict.MyFunc, [arg]) @@ -6148,15 +6140,15 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr // TODO(bfredl): do the entire nlua_is_table_from_lua dance } else { // function('MyFunc', [arg], dict) - s = (char_u *)tv_get_string(&argvars[0]); + s = (char *)tv_get_string(&argvars[0]); use_string = true; } - if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) { + if ((use_string && vim_strchr((char_u *)s, AUTOLOAD_CHAR) == NULL) || is_funcref) { name = s; - trans_name = trans_function_name(&name, false, - TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD - | TFN_NO_DEREF, NULL, NULL); + trans_name = (char *)trans_function_name((char_u **)&name, false, + TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD + | TFN_NO_DEREF, NULL, NULL); if (*name != NUL) { s = NULL; } @@ -6169,7 +6161,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr // Don't check an autoload name for existence here. } else if (trans_name != NULL && (is_funcref - ? find_func(trans_name) == NULL + ? find_func((char_u *)trans_name) == NULL : !translated_function_exists((const char *)trans_name))) { semsg(_("E700: Unknown function: %s"), s); } else { @@ -6190,7 +6182,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr STRCPY(name, sid_buf); STRCAT(name, s + off); } else { - name = vim_strsave(s); + name = xstrdup(s); } if (argvars[1].v_type != VAR_UNKNOWN) { @@ -6226,7 +6218,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr if (tv_list_len(list) == 0) { arg_idx = 0; } else if (tv_list_len(list) > MAX_FUNC_ARGS) { - emsg_funcname((char *)e_toomanyarg, s); + emsg_funcname((char *)e_toomanyarg, (char_u *)s); xfree(name); goto theend; } @@ -6275,12 +6267,12 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr func_ptr_ref(pt->pt_func); xfree(name); } else if (is_funcref) { - pt->pt_func = find_func(trans_name); + pt->pt_func = find_func((char_u *)trans_name); func_ptr_ref(pt->pt_func); xfree(name); } else { - pt->pt_name = name; - func_ref(name); + pt->pt_name = (char_u *)name; + func_ref((char_u *)name); } rettv->v_type = VAR_PARTIAL; @@ -6288,8 +6280,8 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr } else { // result is a VAR_FUNC rettv->v_type = VAR_FUNC; - rettv->vval.v_string = name; - func_ref(name); + rettv->vval.v_string = (char_u *)name; + func_ref((char_u *)name); } } theend: @@ -6863,10 +6855,10 @@ void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buf void return_register(int regname, typval_T *rettv) { - char_u buf[2] = { regname, 0 }; + char buf[2] = { regname, 0 }; rettv->v_type = VAR_STRING; - rettv->vval.v_string = vim_strsave(buf); + rettv->vval.v_string = vim_strsave((char_u *)buf); } void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col) @@ -7201,23 +7193,23 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) && ascii_isdigit(*arg->vval.v_string)) { r = FAIL; } else if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) { - char_u *name = arg->vval.v_string; + char *name = (char *)arg->vval.v_string; if (name == NULL) { r = FAIL; } else if (*name == NUL) { callback->type = kCallbackNone; callback->data.funcref = NULL; } else { - func_ref(name); - callback->data.funcref = vim_strsave(name); + func_ref((char_u *)name); + callback->data.funcref = vim_strsave((char_u *)name); callback->type = kCallbackFuncref; } } else if (nlua_is_table_from_lua(arg)) { // TODO(tjdvries): UnifiedCallback - char_u *name = nlua_register_table_as_callable(arg); + char *name = (char *)nlua_register_table_as_callable(arg); if (name != NULL) { - callback->data.funcref = vim_strsave(name); + callback->data.funcref = vim_strsave((char_u *)name); callback->type = kCallbackFuncref; } else { r = FAIL; @@ -7242,12 +7234,12 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co FUNC_ATTR_NONNULL_ALL { partial_T *partial; - char_u *name; + char *name; Array args = ARRAY_DICT_INIT; Object rv; switch (callback->type) { case kCallbackFuncref: - name = callback->data.funcref; + name = (char *)callback->data.funcref; partial = NULL; break; @@ -7278,7 +7270,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; funcexe.partial = partial; - return call_func(name, -1, rettv, argcount_in, argvars_in, &funcexe); + return call_func((char_u *)name, -1, rettv, argcount_in, argvars_in, &funcexe); } static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack, @@ -7615,7 +7607,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) buf_T *buf = buflist_findnr(tv->vval.v_number); if (buf) { for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char_u *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { *len += 1; } *len += 1; @@ -7633,7 +7625,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) char *ret = xmalloc(*len + 1); char *end = ret; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char_u *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { *end++ = (*p == '\n') ? NUL : *p; } *end++ = '\n'; @@ -7682,17 +7674,17 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) lnum = buf->b_ml.ml_line_count; } - char_u *str = ml_get_buf(buf, lnum, false); + char *str = (char *)ml_get_buf(buf, lnum, false); if (*str == NUL) { return 0; } // count the number of characters - char_u *t = str; + char *t = str; int count; for (count = 0; *t != NUL && t <= str + byteidx; count++) { - t += utfc_ptr2len(t); + t += utfc_ptr2len((char_u *)t); } // In insert mode, when the cursor is at the end of a non-empty line, @@ -7720,12 +7712,12 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) lnum = buf->b_ml.ml_line_count; } - char_u *str = ml_get_buf(buf, lnum, false); + char *str = (char *)ml_get_buf(buf, lnum, false); // Convert the character offset to a byte offset - char_u *t = str; + char *t = str; while (*t != NUL && --charidx > 0) { - t += utfc_ptr2len(t); + t += utfc_ptr2len((char_u *)t); } return t - str; @@ -7938,11 +7930,11 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c /// Advance "arg" to the first character after the name. /// /// @return 0 for error. -static int get_env_len(const char_u **arg) +static int get_env_len(const char **arg) { int len; - const char_u *p; + const char *p; for (p = *arg; vim_isIDc(*p); p++) {} if (p == *arg) { // No name found. return 0; @@ -7970,7 +7962,7 @@ int get_id_len(const char **const arg) // slice "[n:]". Also "xx:" is not a namespace. len = (int)(p - *arg); if (len > 1 - || (len == 1 && vim_strchr(namespace_char, **arg) == NULL)) { + || (len == 1 && vim_strchr((char_u *)namespace_char, **arg) == NULL)) { break; } } @@ -8013,12 +8005,10 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo } // Find the end of the name; check for {} construction. - char_u *expr_start; - char_u *expr_end; - const char *p = (const char *)find_name_end((char_u *)(*arg), - (const char_u **)&expr_start, - (const char_u **)&expr_end, - len > 0 ? 0 : FNE_CHECK_START); + char *expr_start; + char *expr_end; + const char *p = find_name_end((*arg), (const char **)&expr_start, (const char **)&expr_end, + len > 0 ? 0 : FNE_CHECK_START); if (expr_start != NULL) { if (!evaluate) { len += (int)(p - *arg); @@ -8030,12 +8020,11 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo * Include any etc in the expanded string: * Thus the -len here. */ - char_u *temp_string = make_expanded_name((char_u *)(*arg) - len, expr_start, - expr_end, (char_u *)p); + char *temp_string = make_expanded_name(*arg - len, expr_start, expr_end, (char *)p); if (temp_string == NULL) { return -1; } - *alias = (char *)temp_string; + *alias = temp_string; *arg = (const char *)skipwhite((const char_u *)p); return (int)STRLEN(temp_string); } @@ -8059,8 +8048,8 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo /// /// @return a pointer to just after the name. Equal to "arg" if there is no /// valid name. -const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const char_u **expr_end, - int flags) +const char *find_name_end(const char *arg, const char **expr_start, const char **expr_end, + int flags) { int mb_nest = 0; int br_nest = 0; @@ -8076,7 +8065,7 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const return arg; } - const char_u *p; + const char *p; for (p = arg; *p != NUL && (eval_isnamec(*p) || *p == '{' @@ -8104,7 +8093,7 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. len = (int)(p - arg); if ((len > 1 && p[-1] != '}') - || (len == 1 && vim_strchr(namespace_char, *arg) == NULL)) { + || (len == 1 && vim_strchr((char_u *)namespace_char, *arg) == NULL)) { break; } } @@ -8146,13 +8135,13 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const /// /// @return a new allocated string, which the caller must free or /// NULL for failure. -static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, char_u *expr_end, - char_u *in_end) +static char *make_expanded_name(const char *in_start, char *expr_start, char *expr_end, + char *in_end) { - char_u c1; - char_u *retval = NULL; - char_u *temp_result; - char_u *nextcmd = NULL; + char c1; + char *retval = NULL; + char *temp_result; + char *nextcmd = NULL; if (expr_end == NULL || in_end == NULL) { return NULL; @@ -8177,9 +8166,9 @@ static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, ch *expr_end = '}'; if (retval != NULL) { - temp_result = (char_u *)find_name_end(retval, - (const char_u **)&expr_start, - (const char_u **)&expr_end, 0); + temp_result = (char *)find_name_end(retval, + (const char **)&expr_start, + (const char **)&expr_end, 0); if (expr_start != NULL) { // Further expansion! temp_result = make_expanded_name(retval, expr_start, @@ -8379,13 +8368,13 @@ void set_reg_var(int c) /// Otherwise, restore the value to "oldval" and return NULL. /// Must always be called in pairs to save and restore v:exception! Does not /// take care of memory allocations. -char_u *v_exception(char_u *oldval) +char *v_exception(char *oldval) { if (oldval == NULL) { - return vimvars[VV_EXCEPTION].vv_str; + return (char *)vimvars[VV_EXCEPTION].vv_str; } - vimvars[VV_EXCEPTION].vv_str = oldval; + vimvars[VV_EXCEPTION].vv_str = (char_u *)oldval; return NULL; } @@ -8393,13 +8382,13 @@ char_u *v_exception(char_u *oldval) /// Otherwise, restore the value to "oldval" and return NULL. /// Must always be called in pairs to save and restore v:throwpoint! Does not /// take care of memory allocations. -char_u *v_throwpoint(char_u *oldval) +char *v_throwpoint(char *oldval) { if (oldval == NULL) { - return vimvars[VV_THROWPOINT].vv_str; + return (char *)vimvars[VV_THROWPOINT].vv_str; } - vimvars[VV_THROWPOINT].vv_str = oldval; + vimvars[VV_THROWPOINT].vv_str = (char_u *)oldval; return NULL; } @@ -8407,12 +8396,12 @@ char_u *v_throwpoint(char_u *oldval) /// If "eap" != NULL, use "eap" to generate the value and return the old value. /// If "oldarg" != NULL, restore the value to "oldarg" and return NULL. /// Must always be called in pairs! -char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) +char *set_cmdarg(exarg_T *eap, char *oldarg) { - char_u *oldval = vimvars[VV_CMDARG].vv_str; + char *oldval = (char *)vimvars[VV_CMDARG].vv_str; if (eap == NULL) { xfree(oldval); - vimvars[VV_CMDARG].vv_str = oldarg; + vimvars[VV_CMDARG].vv_str = (char_u *)oldarg; return NULL; } @@ -8438,12 +8427,12 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) } const size_t newval_len = len + 1; - char_u *newval = xmalloc(newval_len); + char *newval = xmalloc(newval_len); if (eap->force_bin == FORCE_BIN) { - snprintf((char *)newval, newval_len, " ++bin"); + snprintf(newval, newval_len, " ++bin"); } else if (eap->force_bin == FORCE_NOBIN) { - snprintf((char *)newval, newval_len, " ++nobin"); + snprintf(newval, newval_len, " ++nobin"); } else { *newval = NUL; } @@ -8453,12 +8442,12 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) } if (eap->force_ff != 0) { - snprintf((char *)newval + STRLEN(newval), newval_len, " ++ff=%s", + snprintf(newval + STRLEN(newval), newval_len, " ++ff=%s", eap->force_ff == 'u' ? "unix" : eap->force_ff == 'd' ? "dos" : "mac"); } if (eap->force_enc != 0) { - snprintf((char *)newval + STRLEN(newval), newval_len, " ++enc=%s", + snprintf(newval + STRLEN(newval), newval_len, " ++enc=%s", eap->cmd + eap->force_enc); } if (eap->bad_char == BAD_KEEP) { @@ -8466,10 +8455,10 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) } else if (eap->bad_char == BAD_DROP) { STRCPY(newval + STRLEN(newval), " ++bad=drop"); } else if (eap->bad_char != 0) { - snprintf((char *)newval + STRLEN(newval), newval_len, " ++bad=%c", + snprintf(newval + STRLEN(newval), newval_len, " ++bad=%c", eap->bad_char); } - vimvars[VV_CMDARG].vv_str = newval; + vimvars[VV_CMDARG].vv_str = (char_u *)newval; return oldval; } @@ -8576,11 +8565,11 @@ int check_luafunc_name(const char *const str, const bool paren) /// @param start_leader start of '!' and '-' prefixes /// @param end_leaderp end of '!' and '-' prefixes int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int verbose, - const char_u *const start_leader, const char_u **const end_leaderp) + const char *const start_leader, const char **const end_leaderp) { int ret = OK; dict_T *selfdict = NULL; - const char_u *lua_funcname = NULL; + const char *lua_funcname = NULL; if (tv_is_luafunc(rettv)) { if (**arg != '.') { @@ -8589,7 +8578,7 @@ int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int } else { (*arg)++; - lua_funcname = (char_u *)(*arg); + lua_funcname = *arg; const int len = check_luafunc_name(*arg, true); if (len == 0) { tv_clear(rettv); @@ -8606,8 +8595,7 @@ int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int && !ascii_iswhite(*(*arg - 1))) || (**arg == '-' && (*arg)[1] == '>'))) { if (**arg == '(') { - ret = call_func_rettv((char_u **)arg, rettv, evaluate, selfdict, NULL, - lua_funcname); + ret = call_func_rettv((char **)arg, rettv, evaluate, selfdict, NULL, lua_funcname); // Stop the expression evaluation when immediately aborting on // error, or when an interrupt occurred or an exception was thrown @@ -8624,15 +8612,15 @@ int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int // Expression "-1.0->method()" applies the leader "-" before // applying ->. if (evaluate && *end_leaderp > start_leader) { - ret = eval7_leader(rettv, start_leader, end_leaderp); + ret = eval7_leader(rettv, (char *)start_leader, end_leaderp); } if (ret == OK) { if ((*arg)[2] == '{') { // expr->{lambda}() - ret = eval_lambda((char_u **)arg, rettv, evaluate, verbose); + ret = eval_lambda((char **)arg, rettv, evaluate, verbose); } else { // expr->name() - ret = eval_method((char_u **)arg, rettv, evaluate, verbose); + ret = eval_method((char **)arg, rettv, evaluate, verbose); } } } else { // **arg == '[' || **arg == '.' @@ -8645,7 +8633,7 @@ int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int } else { selfdict = NULL; } - if (eval_index((char_u **)arg, rettv, evaluate, verbose) == FAIL) { + if (eval_index((char **)arg, rettv, evaluate, verbose) == FAIL) { tv_clear(rettv); ret = FAIL; } @@ -8849,8 +8837,8 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, cons bool should_free; // should_free is ignored as script_sctx will be resolved to a fnmae // & new_script_item will consume it. - char_u *sc_name = get_scriptname(last_set, &should_free); - new_script_item(sc_name, ¤t_sctx.sc_sid); + char *sc_name = (char *)get_scriptname(last_set, &should_free); + new_script_item((char_u *)sc_name, ¤t_sctx.sc_sid); } } if (current_sctx.sc_sid == SID_STR || current_sctx.sc_sid == SID_LUA) { @@ -9434,7 +9422,7 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c /// ":echon expr1 ..." print each argument plain. void ex_echo(exarg_T *eap) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; typval_T rettv; bool atstart = true; bool need_clear = true; @@ -9450,7 +9438,7 @@ void ex_echo(exarg_T *eap) need_clr_eos = true; { - char_u *p = arg; + char *p = arg; if (eval1(&arg, &rettv, !eap->skip) == FAIL) { // Report the invalid expression unless the expression evaluation // has been cancelled due to an aborting error, an interrupt, or an @@ -9488,9 +9476,9 @@ void ex_echo(exarg_T *eap) xfree(tofree); } tv_clear(&rettv); - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); } - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char_u *)arg); if (eap->skip) { emsg_skip--; @@ -9518,7 +9506,7 @@ void ex_echohl(exarg_T *eap) /// echo commands void ex_execute(exarg_T *eap) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; typval_T rettv; int ret = OK; garray_T ga; @@ -9554,7 +9542,7 @@ void ex_execute(exarg_T *eap) } tv_clear(&rettv); - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); } if (ret != FAIL && ga.ga_data != NULL) { @@ -9588,7 +9576,7 @@ void ex_execute(exarg_T *eap) --emsg_skip; } - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char_u *)arg); } /// Skip over the name of an option: "&option", "&g:option" or "&l:option". @@ -9693,7 +9681,7 @@ void func_dump_profile(FILE *fd) .script_ctx = fp->uf_script_ctx, .channel_id = 0, }; - char_u *p = get_scriptname(last_set, &should_free); + char *p = (char *)get_scriptname(last_set, &should_free); fprintf(fd, " Defined: %s:%" PRIdLINENR "\n", p, fp->uf_script_ctx.sc_lnum); if (should_free) { @@ -9924,10 +9912,10 @@ void func_line_end(void *cookie) } } -static var_flavour_T var_flavour(char_u *varname) +static var_flavour_T var_flavour(char *varname) FUNC_ATTR_PURE { - char_u *p = varname; + char *p = varname; if (ASCII_ISUPPER(*p)) { while (*(++p)) { @@ -9964,7 +9952,7 @@ const void *var_shada_iter(const void *const iter, const char **const name, typv hi = globvarht.ht_array; while ((size_t)(hi - hifirst) < hinum && (HASHITEM_EMPTY(hi) - || !(var_flavour(hi->hi_key) & flavour))) { + || !(var_flavour((char *)hi->hi_key) & flavour))) { hi++; } if ((size_t)(hi - hifirst) == hinum) { @@ -9976,7 +9964,7 @@ const void *var_shada_iter(const void *const iter, const char **const name, typv *name = (char *)TV_DICT_HI2DI(hi)->di_key; tv_copy(&TV_DICT_HI2DI(hi)->di_tv, rettv); while ((size_t)(++hi - hifirst) < hinum) { - if (!HASHITEM_EMPTY(hi) && (var_flavour(hi->hi_key) & flavour)) { + if (!HASHITEM_EMPTY(hi) && (var_flavour((char *)hi->hi_key) & flavour)) { return hi; } } @@ -9997,12 +9985,12 @@ int store_session_globals(FILE *fd) TV_DICT_ITER(&globvardict, this_var, { if ((this_var->di_tv.v_type == VAR_NUMBER || this_var->di_tv.v_type == VAR_STRING) - && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) { + && var_flavour((char *)this_var->di_key) == VAR_FLAVOUR_SESSION) { // Escape special characters with a backslash. Turn a LF and // CR into \n and \r. - char_u *const p = vim_strsave_escaped((const char_u *)tv_get_string(&this_var->di_tv), - (const char_u *)"\\\"\n\r"); - for (char_u *t = p; *t != NUL; t++) { + char *const p = (char *)vim_strsave_escaped((const char_u *)tv_get_string(&this_var->di_tv), + (const char_u *)"\\\"\n\r"); + for (char *t = p; *t != NUL; t++) { if (*t == '\n') { *t = 'n'; } else if (*t == '\r') { @@ -10022,7 +10010,7 @@ int store_session_globals(FILE *fd) } xfree(p); } else if (this_var->di_tv.v_type == VAR_FLOAT - && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) { + && var_flavour((char *)this_var->di_key) == VAR_FLAVOUR_SESSION) { float_T f = this_var->di_tv.vval.v_float; int sign = ' '; @@ -10057,10 +10045,10 @@ void option_last_set_msg(LastSet last_set) { if (last_set.script_ctx.sc_sid != 0) { bool should_free; - char_u *p = get_scriptname(last_set, &should_free); + char *p = (char *)get_scriptname(last_set, &should_free); verbose_enter(); msg_puts(_("\n\tLast set from ")); - msg_puts((char *)p); + msg_puts(p); if (last_set.script_ctx.sc_lnum > 0) { msg_puts(_(line_msg)); msg_outnum((long)last_set.script_ctx.sc_lnum); @@ -10096,13 +10084,13 @@ void reset_v_option_vars(void) /// @param fnamep file name so far /// @param bufp buffer for allocated file name or NULL /// @param fnamelen length of fnamep -int modify_fname(char_u *src, bool tilde_file, size_t *usedlen, char_u **fnamep, char_u **bufp, +int modify_fname(char *src, bool tilde_file, size_t *usedlen, char **fnamep, char **bufp, size_t *fnamelen) { int valid = 0; - char_u *tail; - char_u *s, *p, *pbuf; - char_u dirname[MAXPATHL]; + char *tail; + char *s, *p, *pbuf; + char dirname[MAXPATHL]; int c; bool has_fullname = false; bool has_homerelative = false; @@ -10125,7 +10113,7 @@ repeat: || (*fnamep)[1] == NUL) #endif && !(tilde_file && (*fnamep)[1] == NUL)) { - *fnamep = expand_env_save(*fnamep); + *fnamep = (char *)expand_env_save((char_u *)(*fnamep)); xfree(*bufp); // free any allocated file name *bufp = *fnamep; if (*fnamep == NULL) { @@ -10146,8 +10134,8 @@ repeat: } // FullName_save() is slow, don't use it when not needed. - if (*p != NUL || !vim_isAbsName(*fnamep)) { - *fnamep = (char_u *)FullName_save((char *)(*fnamep), *p != NUL); + if (*p != NUL || !vim_isAbsName((char_u *)(*fnamep))) { + *fnamep = FullName_save((*fnamep), *p != NUL); xfree(*bufp); // free any allocated file name *bufp = *fnamep; if (*fnamep == NULL) { @@ -10156,15 +10144,15 @@ repeat: } // Append a path separator to a directory. - if (os_isdir(*fnamep)) { + if (os_isdir((char_u *)(*fnamep))) { // Make room for one or two extra characters. - *fnamep = vim_strnsave(*fnamep, STRLEN(*fnamep) + 2); + *fnamep = xstrnsave(*fnamep, STRLEN(*fnamep) + 2); xfree(*bufp); // free any allocated file name *bufp = *fnamep; if (*fnamep == NULL) { return -1; } - add_pathsep((char *)*fnamep); + add_pathsep(*fnamep); } } @@ -10172,7 +10160,7 @@ repeat: // ":~" - path relative to the home directory // ":8" - shortname path - postponed till after while (src[*usedlen] == ':' - && ((c = src[*usedlen + 1]) == '.' || c == '~' || c == '8')) { + && ((c = (char_u)src[*usedlen + 1]) == '.' || c == '~' || c == '8')) { *usedlen += 2; if (c == '8') { continue; @@ -10181,9 +10169,9 @@ repeat: // Need full path first (use expand_env() to remove a "~/") if (!has_fullname && !has_homerelative) { if (**fnamep == '~') { - p = pbuf = expand_env_save(*fnamep); + p = pbuf = (char *)expand_env_save((char_u *)(*fnamep)); } else { - p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE); + p = pbuf = FullName_save(*fnamep, false); } } else { p = *fnamep; @@ -10193,10 +10181,10 @@ repeat: if (p != NULL) { if (c == '.') { - os_dirname(dirname, MAXPATHL); + os_dirname((char_u *)dirname, MAXPATHL); if (has_homerelative) { - s = vim_strsave(dirname); - home_replace(NULL, s, dirname, MAXPATHL, true); + s = xstrdup(dirname); + home_replace(NULL, (char_u *)s, (char_u *)dirname, MAXPATHL, true); xfree(s); } size_t namelen = STRLEN(dirname); @@ -10219,10 +10207,10 @@ repeat: } } } else { - home_replace(NULL, p, dirname, MAXPATHL, true); + home_replace(NULL, (char_u *)p, (char_u *)dirname, MAXPATHL, true); // Only replace it when it starts with '~' if (*dirname == '~') { - s = vim_strsave(dirname); + s = xstrdup(dirname); *fnamep = s; xfree(*bufp); *bufp = s; @@ -10233,7 +10221,7 @@ repeat: } } - tail = path_tail(*fnamep); + tail = (char *)path_tail((char_u *)(*fnamep)); *fnamelen = STRLEN(*fnamep); // ":h" - head, remove "/file_name", can be repeated @@ -10241,18 +10229,18 @@ repeat: while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') { valid |= VALID_HEAD; *usedlen += 2; - s = get_past_head(*fnamep); - while (tail > s && after_pathsep((char *)s, (char *)tail)) { + s = (char *)get_past_head((char_u *)(*fnamep)); + while (tail > s && after_pathsep(s, tail)) { MB_PTR_BACK(*fnamep, tail); } *fnamelen = (size_t)(tail - *fnamep); if (*fnamelen == 0) { // Result is empty. Turn it into "." to make ":cd %:h" work. xfree(*bufp); - *bufp = *fnamep = tail = vim_strsave((char_u *)"."); + *bufp = *fnamep = tail = xstrdup("."); *fnamelen = 1; } else { - while (tail > s && !after_pathsep((char *)s, (char *)tail)) { + while (tail > s && !after_pathsep(s, tail)) { MB_PTR_BACK(*fnamep, tail); } } @@ -10281,9 +10269,9 @@ repeat: */ const bool is_second_e = *fnamep > tail; if (src[*usedlen + 1] == 'e' && is_second_e) { - s = *fnamep - 2; + s = (*fnamep) - 2; } else { - s = *fnamep + *fnamelen - 1; + s = (*fnamep) + *fnamelen - 1; } for (; s > tail; s--) { @@ -10294,7 +10282,7 @@ repeat: if (src[*usedlen + 1] == 'e') { if (s > tail || (0 && is_second_e && s == tail)) { // we stopped at a '.' (so anchor to &'.' + 1) - char_u *newstart = s + 1; + char *newstart = s + 1; size_t distance_stepped_back = *fnamep - newstart; *fnamelen += distance_stepped_back; *fnamep = newstart; @@ -10317,7 +10305,7 @@ repeat: // "path/to/this.file.ext" :r:r:r // ^ ^------------- tail // +--------------------- *fnamep - if (s > MAX(tail, *fnamep)) { + if (s > MAX(tail, (char *)(*fnamep))) { *fnamelen = (size_t)(s - *fnamep); } } @@ -10330,28 +10318,28 @@ repeat: && (src[*usedlen + 1] == 's' || (src[*usedlen + 1] == 'g' && src[*usedlen + 2] == 's'))) { int sep; - char_u *flags; - int didit = FALSE; + char *flags; + int didit = false; - flags = (char_u *)""; + flags = ""; s = src + *usedlen + 2; if (src[*usedlen + 1] == 'g') { - flags = (char_u *)"g"; - ++s; + flags = "g"; + s++; } - sep = *s++; + sep = (char_u)(*s++); if (sep) { // find end of pattern - p = vim_strchr(s, sep); + p = (char *)vim_strchr((char_u *)s, sep); if (p != NULL) { - char_u *const pat = vim_strnsave(s, p - s); + char *const pat = xstrnsave(s, p - s); s = p + 1; // find end of substitution - p = vim_strchr(s, sep); + p = (char *)vim_strchr((char_u *)s, sep); if (p != NULL) { - char_u *const sub = vim_strnsave(s, p - s); - char_u *const str = vim_strnsave(*fnamep, *fnamelen); + char *const sub = xstrnsave(s, p - s); + char *const str = xstrnsave(*fnamep, *fnamelen); *usedlen = (size_t)(p + 1 - src); s = do_string_sub(str, pat, sub, NULL, flags); *fnamep = s; @@ -10373,11 +10361,11 @@ repeat: if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') { // vim_strsave_shellescape() needs a NUL terminated string. - c = (*fnamep)[*fnamelen]; + c = (char_u)(*fnamep)[*fnamelen]; if (c != NUL) { (*fnamep)[*fnamelen] = NUL; } - p = vim_strsave_shellescape(*fnamep, false, false); + p = (char *)vim_strsave_shellescape((char_u *)(*fnamep), false, false); if (c != NUL) { (*fnamep)[*fnamelen] = c; } @@ -10395,19 +10383,19 @@ repeat: /// "flags" can be "g" to do a global substitute. /// /// @return an allocated string, NULL for error. -char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags) +char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags) { int sublen; regmatch_T regmatch; int do_all; - char_u *tail; - char_u *end; + char *tail; + char *end; garray_T ga; - char_u *save_cpo; - char_u *zero_width = NULL; + char *save_cpo; + char *zero_width = NULL; // Make 'cpoptions' empty, so that the 'l' flag doesn't work here - save_cpo = p_cpo; + save_cpo = (char *)p_cpo; p_cpo = empty_option; ga_init(&ga, 1, 200); @@ -10415,22 +10403,22 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, cha do_all = (flags[0] == 'g'); regmatch.rm_ic = p_ic; - regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { tail = str; end = str + STRLEN(str); - while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) { + while (vim_regexec_nl(®match, (char_u *)str, (colnr_T)(tail - str))) { // Skip empty match except for first match. if (regmatch.startp[0] == regmatch.endp[0]) { - if (zero_width == regmatch.startp[0]) { + if ((char_u *)zero_width == regmatch.startp[0]) { // avoid getting stuck on a match with an empty string - int i = utfc_ptr2len(tail); + int i = utfc_ptr2len((char_u *)tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ga.ga_len += i; tail += i; continue; } - zero_width = regmatch.startp[0]; + zero_width = (char *)regmatch.startp[0]; } // Get some space for a temporary buffer to do the substitution @@ -10438,18 +10426,18 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, cha // - The text up to where the match is. // - The substituted text. // - The text after the match. - sublen = vim_regsub(®match, sub, expr, tail, false, true, false); + sublen = vim_regsub(®match, (char_u *)sub, expr, (char_u *)tail, false, true, false); ga_grow(&ga, (int)((end - tail) + sublen - (regmatch.endp[0] - regmatch.startp[0]))); // copy the text up to where the match is - int i = (int)(regmatch.startp[0] - tail); + int i = (int)(regmatch.startp[0] - (char_u *)tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); // add the substituted text - (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data + (void)vim_regsub(®match, (char_u *)sub, expr, (char_u *)ga.ga_data + ga.ga_len + i, true, true, false); ga.ga_len += i + sublen - 1; - tail = regmatch.endp[0]; + tail = (char *)regmatch.endp[0]; if (*tail == NUL) { break; } @@ -10465,13 +10453,13 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, cha vim_regfree(regmatch.regprog); } - char_u *ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); + char *ret = xstrdup(ga.ga_data == NULL ? str : ga.ga_data); ga_clear(&ga); if (p_cpo == empty_option) { - p_cpo = save_cpo; + p_cpo = (char_u *)save_cpo; } else { // Darn, evaluating {sub} expression or {expr} changed the value. - free_string_option(save_cpo); + free_string_option((char_u *)save_cpo); } return ret; @@ -10703,8 +10691,8 @@ void invoke_prompt_callback(void) { typval_T rettv; typval_T argv[2]; - char_u *text; - char_u *prompt; + char *text; + char *prompt; linenr_T lnum = curbuf->b_ml.ml_line_count; // Add a new line for the prompt before invoking the callback, so that @@ -10716,13 +10704,13 @@ void invoke_prompt_callback(void) if (curbuf->b_prompt_callback.type == kCallbackNone) { return; } - text = ml_get(lnum); - prompt = prompt_text(); + text = (char *)ml_get(lnum); + prompt = (char *)prompt_text(); if (STRLEN(text) >= STRLEN(prompt)) { text += STRLEN(prompt); } argv[0].v_type = VAR_STRING; - argv[0].vval.v_string = vim_strsave(text); + argv[0].vval.v_string = vim_strsave((char_u *)text); argv[1].v_type = VAR_UNKNOWN; callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv); @@ -10942,7 +10930,7 @@ int typval_compare(typval_T *typ1, typval_T *typ2, exprtype_T type, bool ic) case EXPR_MATCH: case EXPR_NOMATCH: - n1 = pattern_match((char_u *)s2, (char_u *)s1, ic); + n1 = pattern_match((char *)s2, (char *)s1, ic); if (type == EXPR_NOMATCH) { n1 = !n1; } @@ -10983,9 +10971,7 @@ bool var_exists(const char *var) n = get_var_tv(name, len, &tv, NULL, false, true) == OK; if (n) { // Handle d.key, l[idx], f(expr). - n = handle_subscript(&var, &tv, true, false, (const char_u *)name, - (const char_u **)&name) - == OK; + n = handle_subscript(&var, &tv, true, false, name, &name) == OK; if (n) { tv_clear(&tv); } -- cgit From 5576d30e89153c817fb1a8d23c30cfc0432bc7c6 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 3 May 2022 11:06:27 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b4c3e62ddf..7f99d81bb4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1296,7 +1296,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) // The amount of indentation trimmed is the same as the indentation of // the first line after the :let command line. To find the end marker // the indent of the :let command line is trimmed. - p = (char *)(*eap->cmdlinep); + p = *eap->cmdlinep; while (ascii_iswhite(*p)) { p++; marker_indent_len++; @@ -1389,7 +1389,7 @@ void ex_let(exarg_T *eap) static void ex_let_const(exarg_T *eap, const bool is_const) { - char *arg = (char *)eap->arg; + char *arg = eap->arg; char *expr = NULL; typval_T rettv; int i; @@ -1425,7 +1425,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) list_func_vars(&first); list_vim_vars(&first); } - eap->nextcmd = check_nextcmd((char_u *)arg); + eap->nextcmd = (char *)check_nextcmd((char_u *)arg); } else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') { // HERE document list_T *l = heredoc_get(eap, expr + 3); @@ -1434,7 +1434,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) if (!eap->skip) { op[0] = '='; op[1] = NUL; - (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, is_const, (char *)op); } tv_clear(&rettv); @@ -1457,14 +1457,14 @@ static void ex_let_const(exarg_T *eap, const bool is_const) if (eap->skip) { ++emsg_skip; } - i = eval0(expr, &rettv, (char **)&eap->nextcmd, !eap->skip); + i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); if (eap->skip) { if (i != FAIL) { tv_clear(&rettv); } emsg_skip--; } else if (i != FAIL) { - (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, is_const, (char *)op); tv_clear(&rettv); } @@ -2715,7 +2715,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) if (strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) { // ":let var1 var2 ...": find last space. for (p = arg + STRLEN(arg); p >= arg;) { - xp->xp_pattern = (char_u *)p; + xp->xp_pattern = p; MB_PTR_BACK(arg, p); if (ascii_iswhite(*p)) { break; @@ -2727,10 +2727,10 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS : EXPAND_EXPRESSION; } - while ((xp->xp_pattern = (char_u *)strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { - c = *xp->xp_pattern; + while ((xp->xp_pattern = strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { + c = (uint8_t)(*xp->xp_pattern); if (c == '&') { - c = xp->xp_pattern[1]; + c = (uint8_t)xp->xp_pattern[1]; if (c == '&') { ++xp->xp_pattern; xp->xp_context = cmdidx != CMD_let || got_eq @@ -2753,12 +2753,12 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) break; } else if ((c == '<' || c == '#') && xp->xp_context == EXPAND_FUNCTIONS - && vim_strchr(xp->xp_pattern, '(') == NULL) { + && vim_strchr((char_u *)xp->xp_pattern, '(') == NULL) { // Function name can start with "" and contain '#'. break; } else if (cmdidx != CMD_let || got_eq) { if (c == '"') { // string - while ((c = *++xp->xp_pattern) != NUL && c != '"') { + while ((c = (uint8_t)(*++xp->xp_pattern)) != NUL && c != '"') { if (c == '\\' && xp->xp_pattern[1] != NUL) { xp->xp_pattern++; } @@ -2766,7 +2766,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) xp->xp_context = EXPAND_NOTHING; } else if (c == '\'') { // literal string // Trick: '' is like stopping and starting a literal string. - while ((c = *++xp->xp_pattern) != NUL && c != '\'') {} + while ((c = (uint8_t)(*++xp->xp_pattern)) != NUL && c != '\'') {} xp->xp_context = EXPAND_NOTHING; } else if (c == '|') { if (xp->xp_pattern[1] == '|') { @@ -2783,7 +2783,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) // anyway. xp->xp_context = EXPAND_EXPRESSION; } - arg = (char *)xp->xp_pattern; + arg = xp->xp_pattern; if (*arg != NUL) { while ((c = (char_u)(*++arg)) != NUL && (c == ' ' || c == '\t')) {} } @@ -2805,13 +2805,13 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) } } - xp->xp_pattern = (char_u *)arg; + xp->xp_pattern = arg; } /// ":unlet[!] var1 ... " command. void ex_unlet(exarg_T *eap) { - ex_unletlock(eap, (char *)eap->arg, 0, do_unlet_var); + ex_unletlock(eap, eap->arg, 0, do_unlet_var); } // TODO(ZyX-I): move to eval/ex_cmds @@ -2819,7 +2819,7 @@ void ex_unlet(exarg_T *eap) /// ":lockvar" and ":unlockvar" commands void ex_lockvar(exarg_T *eap) { - char *arg = (char *)eap->arg; + char *arg = eap->arg; int deep = 2; if (eap->forceit) { @@ -2894,7 +2894,7 @@ static void ex_unletlock(exarg_T *eap, char *argstart, int deep, ex_unletlock_ca arg = (char *)skipwhite((char_u *)name_end); } while (!ends_excmd(*arg)); - eap->nextcmd = check_nextcmd((char_u *)arg); + eap->nextcmd = (char *)check_nextcmd((char_u *)arg); } // TODO(ZyX-I): move to eval/ex_cmds @@ -9422,7 +9422,7 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c /// ":echon expr1 ..." print each argument plain. void ex_echo(exarg_T *eap) { - char *arg = (char *)eap->arg; + char *arg = eap->arg; typval_T rettv; bool atstart = true; bool need_clear = true; @@ -9478,7 +9478,7 @@ void ex_echo(exarg_T *eap) tv_clear(&rettv); arg = (char *)skipwhite((char_u *)arg); } - eap->nextcmd = check_nextcmd((char_u *)arg); + eap->nextcmd = (char *)check_nextcmd((char_u *)arg); if (eap->skip) { emsg_skip--; @@ -9496,7 +9496,7 @@ void ex_echo(exarg_T *eap) /// ":echohl {name}". void ex_echohl(exarg_T *eap) { - echo_attr = syn_name2attr(eap->arg); + echo_attr = syn_name2attr((char_u *)eap->arg); } /// ":execute expr1 ..." execute the result of an expression. @@ -9506,7 +9506,7 @@ void ex_echohl(exarg_T *eap) /// echo commands void ex_execute(exarg_T *eap) { - char *arg = (char *)eap->arg; + char *arg = eap->arg; typval_T rettv; int ret = OK; garray_T ga; @@ -9576,7 +9576,7 @@ void ex_execute(exarg_T *eap) --emsg_skip; } - eap->nextcmd = check_nextcmd((char_u *)arg); + eap->nextcmd = (char *)check_nextcmd((char_u *)arg); } /// Skip over the name of an option: "&option", "&g:option" or "&l:option". -- cgit From 9a671e6a24243a5ff2879599d91ab5aec8b4e77d Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 18:27:22 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 113 +++++++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 58 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7f99d81bb4..d910b47c57 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -505,7 +505,7 @@ void set_internal_string_var(const char *name, char *value) { typval_T tv = { .v_type = VAR_STRING, - .vval.v_string = (char_u *)value, + .vval.v_string = value, }; set_var(name, strlen(name), &tv, true); @@ -563,7 +563,7 @@ int var_redir_start(char *name, int append) save_emsg = did_emsg; did_emsg = FALSE; tv.v_type = VAR_STRING; - tv.vval.v_string = (char_u *)""; + tv.vval.v_string = ""; if (append) { set_var_lval(redir_lval, redir_endp, &tv, true, false, "."); } else { @@ -773,7 +773,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r funcexe_T funcexe = FUNCEXE_INIT; if (expr->v_type == VAR_FUNC) { - const char *const s = (char *)expr->vval.v_string; + const char *const s = expr->vval.v_string; if (s == NULL || *s == NUL) { return FAIL; } @@ -1019,7 +1019,7 @@ list_T *eval_spell_expr(char *badword, char *expr) // Set "v:val" to the bad word. prepare_vimvar(VV_VAL, &save_val); vimvars[VV_VAL].vv_type = VAR_STRING; - vimvars[VV_VAL].vv_str = (char_u *)badword; + vimvars[VV_VAL].vv_str = badword; if (p_verbose == 0) { ++emsg_off; } @@ -1235,7 +1235,7 @@ int eval_foldexpr(char *arg, int *cp) } else { // If the result is a string, check if there is a non-digit before // the number. - char *s = (char *)tv.vval.v_string; + char *s = tv.vval.v_string; if (!ascii_isdigit(*s) && *s != '-') { *cp = (char_u)(*s++); } @@ -2614,7 +2614,7 @@ void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) tv_clear(&tv); } else if (tv.v_type == VAR_STRING) { fi->fi_byte_idx = 0; - fi->fi_string = (char *)tv.vval.v_string; + fi->fi_string = tv.vval.v_string; tv.vval.v_string = NULL; if (fi->fi_string == NULL) { fi->fi_string = xstrdup(""); @@ -2663,7 +2663,7 @@ bool next_for_item(void *fi_void, char *arg) typval_T tv; tv.v_type = VAR_STRING; tv.v_lock = VAR_FIXED; - tv.vval.v_string = vim_strnsave((char_u *)fi->fi_string + fi->fi_byte_idx, len); + tv.vval.v_string = xstrnsave(fi->fi_string + fi->fi_byte_idx, len); fi->fi_byte_idx += len; const int result = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; @@ -3318,7 +3318,7 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ // get_func_tv, but it's needed in handle_subscript() to parse // what follows. So set it here. if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') { - rettv->vval.v_string = (char_u *)tv_empty_string; + rettv->vval.v_string = (char *)tv_empty_string; rettv->v_type = VAR_FUNC; } @@ -3781,7 +3781,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) p = (char *)concat_str((const char_u *)s1, (const char_u *)s2); tv_clear(rettv); rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)p; + rettv->vval.v_string = p; } else if (op == '+' && rettv->v_type == VAR_BLOB && var2.v_type == VAR_BLOB) { const blob_T *const b1 = rettv->vval.v_blob; @@ -4330,7 +4330,7 @@ static int call_func_rettv(char **const arg, typval_T *const rettv, const bool e is_lua = is_luafunc(pt); funcname = is_lua ? lua_funcname : partial_name(pt); } else { - funcname = (char *)functv.vval.v_string; + funcname = functv.vval.v_string; } } else { funcname = ""; @@ -4637,7 +4637,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) } tv_clear(rettv); rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)v; + rettv->vval.v_string = v; break; } case VAR_BLOB: @@ -4834,7 +4834,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval rettv->vval.v_number = numval; } else { // string option rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)stringval; + rettv->vval.v_string = stringval; } } else if (working && (opt_type == -2 || opt_type == -1)) { ret = FAIL; @@ -4887,7 +4887,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) const int len = (int)(p - *arg + extra); char *name = xmalloc(len); rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)name; + rettv->vval.v_string = name; for (p = *arg + 1; *p != NUL && *p != '"';) { if (*p == '\\') { @@ -4965,7 +4965,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) extra = trans_special((const char_u **)&p, STRLEN(p), (char_u *)name, flags, false, NULL); if (extra != 0) { name += extra; - if ((char_u *)name >= rettv->vval.v_string + len) { + if (name >= rettv->vval.v_string + len) { iemsg("get_string_tv() used more space than allocated"); } break; @@ -5028,7 +5028,7 @@ static int get_lit_string_tv(char **arg, typval_T *rettv, int evaluate) */ str = xmalloc((p - *arg) - reduce); rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)str; + rettv->vval.v_string = str; for (p = *arg + 1; *p != NUL;) { if (*p == '\'') { @@ -5141,13 +5141,11 @@ bool func_equal(typval_T *tv1, typval_T *tv2, bool ic) int a1, a2; // empty and NULL function name considered the same - s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string - : (char_u *)partial_name(tv1->vval.v_partial); + s1 = (char_u *)(tv1->v_type == VAR_FUNC ? tv1->vval.v_string : partial_name(tv1->vval.v_partial)); if (s1 != NULL && *s1 == NUL) { s1 = NULL; } - s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string - : (char_u *)partial_name(tv2->vval.v_partial); + s2 = (char_u *)(tv2->v_type == VAR_FUNC ? tv2->vval.v_string : partial_name(tv2->vval.v_partial)); if (s2 != NULL && *s2 == NUL) { s2 = NULL; } @@ -5625,7 +5623,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack break; } case VAR_FUNC: - abort = set_ref_in_func(tv->vval.v_string, NULL, copyID); + abort = set_ref_in_func((char_u *)tv->vval.v_string, NULL, copyID); break; case VAR_UNKNOWN: case VAR_BOOL: @@ -5700,7 +5698,7 @@ static int get_literal_key(char **arg, typval_T *tv) } for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {} tv->v_type = VAR_STRING; - tv->vval.v_string = vim_strnsave((char_u *)(*arg), p - *arg); + tv->vval.v_string = xstrnsave(*arg, p - *arg); *arg = (char *)skipwhite((char_u *)p); return OK; @@ -5882,7 +5880,7 @@ static int get_env_tv(char **arg, typval_T *rettv, int evaluate) } name[len] = cc; rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *)string; + rettv->vval.v_string = string; } return OK; @@ -6004,7 +6002,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) break; } - vimvars[VV_KEY].vv_str = vim_strsave(di->di_key); + vimvars[VV_KEY].vv_str = (char *)vim_strsave(di->di_key); int r = filter_map_one(&di->di_tv, expr, map, &rem); tv_clear(&vimvars[VV_KEY].vv_tv); if (r == FAIL || did_emsg) { @@ -6131,7 +6129,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr if (argvars[0].v_type == VAR_FUNC) { // function(MyFunc, [arg], dict) - s = (char *)argvars[0].vval.v_string; + s = argvars[0].vval.v_string; } else if (argvars[0].v_type == VAR_PARTIAL && argvars[0].vval.v_partial != NULL) { // function(dict.MyFunc, [arg]) @@ -6280,7 +6278,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr } else { // result is a VAR_FUNC rettv->v_type = VAR_FUNC; - rettv->vval.v_string = (char_u *)name; + rettv->vval.v_string = name; func_ref((char_u *)name); } } @@ -6664,14 +6662,13 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const const int save_ex_normal_busy = ex_normal_busy; ex_normal_busy = 0; - rettv->vval.v_string = - (char_u *)getcmdline_prompt(secret ? NUL : '@', p, echo_attr, - xp_type, xp_arg, input_callback); + rettv->vval.v_string = getcmdline_prompt(secret ? NUL : '@', p, echo_attr, xp_type, xp_arg, + input_callback); ex_normal_busy = save_ex_normal_busy; callback_free(&input_callback); if (rettv->vval.v_string == NULL && cancelreturn != NULL) { - rettv->vval.v_string = (char_u *)xstrdup(cancelreturn); + rettv->vval.v_string = xstrdup(cancelreturn); } xfree(xp_arg); @@ -6706,7 +6703,7 @@ void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType wha switch (what) { case kDictListKeys: tv_item.v_type = VAR_STRING; - tv_item.vval.v_string = vim_strsave(di->di_key); + tv_item.vval.v_string = (char *)vim_strsave(di->di_key); break; case kDictListValues: tv_copy(&di->di_tv, &tv_item); @@ -6721,7 +6718,7 @@ void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType wha tv_list_append_owned_tv(sub_l, (typval_T) { .v_type = VAR_STRING, .v_lock = VAR_UNLOCKED, - .vval.v_string = (char_u *)xstrdup((const char *)di->di_key), + .vval.v_string = xstrdup((const char *)di->di_key), }); tv_list_append_tv(sub_l, &di->di_tv); @@ -6858,7 +6855,7 @@ void return_register(int regname, typval_T *rettv) char buf[2] = { regname, 0 }; rettv->v_type = VAR_STRING; - rettv->vval.v_string = vim_strsave((char_u *)buf); + rettv->vval.v_string = xstrdup(buf); } void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col) @@ -6949,7 +6946,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T // Existing line, replace it. int old_len = (int)STRLEN(ml_get(lnum)); if (u_savesub(lnum) == OK - && ml_replace(lnum, (char_u *)line, true) == OK) { + && ml_replace(lnum, (char *)line, true) == OK) { inserted_bytes(lnum, 0, old_len, STRLEN(line)); if (is_curbuf && lnum == curwin->w_cursor.lnum) { check_cursor_col(); @@ -6959,7 +6956,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T } else if (added > 0 || u_save(lnum - 1, lnum) == OK) { // append the line. added++; - if (ml_append(lnum - 1, (char_u *)line, 0, false) == OK) { + if (ml_append(lnum - 1, (char *)line, 0, false) == OK) { rettv->vval.v_number = 0; // OK } } @@ -7143,7 +7140,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist // return an empty list when there's no output tv_list_alloc_ret(rettv, 0); } else { - rettv->vval.v_string = (char_u *)xstrdup(""); + rettv->vval.v_string = xstrdup(""); } return; } @@ -7175,7 +7172,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist *d = NUL; #endif - rettv->vval.v_string = (char_u *)res; + rettv->vval.v_string = res; } } @@ -7193,7 +7190,7 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) && ascii_isdigit(*arg->vval.v_string)) { r = FAIL; } else if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) { - char *name = (char *)arg->vval.v_string; + char *name = arg->vval.v_string; if (name == NULL) { r = FAIL; } else if (*name == NUL) { @@ -7201,7 +7198,7 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) callback->data.funcref = NULL; } else { func_ref((char_u *)name); - callback->data.funcref = vim_strsave((char_u *)name); + callback->data.funcref = xstrdup(name); callback->type = kCallbackFuncref; } } else if (nlua_is_table_from_lua(arg)) { @@ -7209,7 +7206,7 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) char *name = (char *)nlua_register_table_as_callable(arg); if (name != NULL) { - callback->data.funcref = vim_strsave((char_u *)name); + callback->data.funcref = xstrdup(name); callback->type = kCallbackFuncref; } else { r = FAIL; @@ -7239,7 +7236,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co Object rv; switch (callback->type) { case kCallbackFuncref: - name = (char *)callback->data.funcref; + name = callback->data.funcref; partial = NULL; break; @@ -8296,9 +8293,9 @@ void set_vim_var_string(const VimVarIndex idx, const char *const val, const ptrd if (val == NULL) { vimvars[idx].vv_str = NULL; } else if (len == -1) { - vimvars[idx].vv_str = (char_u *)xstrdup(val); + vimvars[idx].vv_str = xstrdup(val); } else { - vimvars[idx].vv_str = (char_u *)xstrndup(val, (size_t)len); + vimvars[idx].vv_str = xstrndup(val, (size_t)len); } } @@ -8371,10 +8368,10 @@ void set_reg_var(int c) char *v_exception(char *oldval) { if (oldval == NULL) { - return (char *)vimvars[VV_EXCEPTION].vv_str; + return vimvars[VV_EXCEPTION].vv_str; } - vimvars[VV_EXCEPTION].vv_str = (char_u *)oldval; + vimvars[VV_EXCEPTION].vv_str = oldval; return NULL; } @@ -8385,10 +8382,10 @@ char *v_exception(char *oldval) char *v_throwpoint(char *oldval) { if (oldval == NULL) { - return (char *)vimvars[VV_THROWPOINT].vv_str; + return vimvars[VV_THROWPOINT].vv_str; } - vimvars[VV_THROWPOINT].vv_str = (char_u *)oldval; + vimvars[VV_THROWPOINT].vv_str = oldval; return NULL; } @@ -8398,10 +8395,10 @@ char *v_throwpoint(char *oldval) /// Must always be called in pairs! char *set_cmdarg(exarg_T *eap, char *oldarg) { - char *oldval = (char *)vimvars[VV_CMDARG].vv_str; + char *oldval = vimvars[VV_CMDARG].vv_str; if (eap == NULL) { xfree(oldval); - vimvars[VV_CMDARG].vv_str = (char_u *)oldarg; + vimvars[VV_CMDARG].vv_str = oldarg; return NULL; } @@ -8458,7 +8455,7 @@ char *set_cmdarg(exarg_T *eap, char *oldarg) snprintf(newval + STRLEN(newval), newval_len, " ++bad=%c", eap->bad_char); } - vimvars[VV_CMDARG].vv_str = (char_u *)newval; + vimvars[VV_CMDARG].vv_str = newval; return oldval; } @@ -8838,7 +8835,7 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, cons // should_free is ignored as script_sctx will be resolved to a fnmae // & new_script_item will consume it. char *sc_name = (char *)get_scriptname(last_set, &should_free); - new_script_item((char_u *)sc_name, ¤t_sctx.sc_sid); + new_script_item(sc_name, ¤t_sctx.sc_sid); } } if (current_sctx.sc_sid == SID_STR || current_sctx.sc_sid == SID_LUA) { @@ -9112,7 +9109,7 @@ static void set_var_const(const char *name, const size_t name_len, typval_T *con // Careful: when assigning to v:errmsg and tv_get_string() // causes an error message the variable will already be set. if (v->di_tv.vval.v_string == NULL) { - v->di_tv.vval.v_string = (char_u *)xstrdup(val); + v->di_tv.vval.v_string = xstrdup(val); } } else { // Take over the string to avoid an extra alloc/free. @@ -9366,11 +9363,11 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c } else { to->v_type = VAR_STRING; to->v_lock = VAR_UNLOCKED; - if ((to->vval.v_string = string_convert((vimconv_T *)conv, - from->vval.v_string, - NULL)) + if ((to->vval.v_string = (char *)string_convert((vimconv_T *)conv, + (char_u *)from->vval.v_string, + NULL)) == NULL) { - to->vval.v_string = (char_u *)xstrdup((char *)from->vval.v_string); + to->vval.v_string = xstrdup(from->vval.v_string); } } break; @@ -10560,7 +10557,7 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments, boo provider_call_nesting++; typval_T argvars[3] = { - { .v_type = VAR_STRING, .vval.v_string = (char_u *)method, + { .v_type = VAR_STRING, .vval.v_string = method, .v_lock = VAR_UNLOCKED }, { .v_type = VAR_LIST, .vval.v_list = arguments, .v_lock = VAR_UNLOCKED }, { .v_type = VAR_UNKNOWN } @@ -10697,7 +10694,7 @@ void invoke_prompt_callback(void) // Add a new line for the prompt before invoking the callback, so that // text can always be inserted above the last line. - ml_append(lnum, (char_u *)"", 0, false); + ml_append(lnum, "", 0, false); curwin->w_cursor.lnum = lnum + 1; curwin->w_cursor.col = 0; @@ -10710,7 +10707,7 @@ void invoke_prompt_callback(void) text += STRLEN(prompt); } argv[0].v_type = VAR_STRING; - argv[0].vval.v_string = vim_strsave((char_u *)text); + argv[0].vval.v_string = xstrdup(text); argv[1].v_type = VAR_UNKNOWN; callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv); -- cgit From 11631354cb6b6ca28a1bfb712719ace53c763c77 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 6 May 2022 23:17:04 +0200 Subject: vim-patch:8.2.4469: Coverity warns for uninitialized variable Problem: Coverity warns for uninitialized variable. Solution: Set the value to zero. https://github.com/vim/vim/commit/05c1734c4f70a0d7fb2f06444e26afda018f8795 --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d910b47c57..548dd96444 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6632,7 +6632,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const // input() with a third argument: completion const int xp_namelen = (int)strlen(xp_name); - uint32_t argt; + uint32_t argt = 0; if (parse_compl_arg(xp_name, xp_namelen, &xp_type, &argt, &xp_arg) == FAIL) { return; -- cgit From 2a378e6e82cececb12339f2df51ffe107039d867 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 22:35:50 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d910b47c57..c79afe41ed 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2656,7 +2656,7 @@ bool next_for_item(void *fi_void, char *arg) } if (fi->fi_string != NULL) { - const int len = utfc_ptr2len((char_u *)fi->fi_string + fi->fi_byte_idx); + const int len = utfc_ptr2len(fi->fi_string + fi->fi_byte_idx); if (len == 0) { return false; } @@ -7681,7 +7681,7 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) char *t = str; int count; for (count = 0; *t != NUL && t <= str + byteidx; count++) { - t += utfc_ptr2len((char_u *)t); + t += utfc_ptr2len(t); } // In insert mode, when the cursor is at the end of a non-empty line, @@ -7714,7 +7714,7 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) // Convert the character offset to a byte offset char *t = str; while (*t != NUL && --charidx > 0) { - t += utfc_ptr2len((char_u *)t); + t += utfc_ptr2len(t); } return t - str; @@ -10409,7 +10409,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags if (regmatch.startp[0] == regmatch.endp[0]) { if ((char_u *)zero_width == regmatch.startp[0]) { // avoid getting stuck on a match with an empty string - int i = utfc_ptr2len((char_u *)tail); + int i = utfc_ptr2len(tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ga.ga_len += i; tail += i; -- cgit From e31b32a293f6ba8708499a176234f8be1df6a145 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Thu, 5 May 2022 13:36:14 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 145 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 72 insertions(+), 73 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 901976bb16..01f913dd70 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -778,7 +778,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r return FAIL; } funcexe.evaluate = true; - if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else if (expr->v_type == VAR_PARTIAL) { @@ -789,7 +789,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r } funcexe.evaluate = true; funcexe.partial = partial; - if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else { @@ -798,11 +798,11 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r if (s == NULL) { return FAIL; } - s = (char *)skipwhite((char_u *)s); + s = skipwhite(s); if (eval1_emsg(&s, rettv, true) == FAIL) { return FAIL; } - if (*skipwhite((char_u *)s) != NUL) { // check for trailing chars after expr + if (*skipwhite(s) != NUL) { // check for trailing chars after expr tv_clear(rettv); semsg(_(e_invexpr2), s); return FAIL; @@ -865,7 +865,7 @@ int skip_expr(char **pp) { typval_T rettv; - *pp = (char *)skipwhite((char_u *)(*pp)); + *pp = skipwhite(*pp); return eval1(pp, &rettv, false); } @@ -938,7 +938,7 @@ varnumber_T eval_to_number(char *expr) { typval_T rettv; varnumber_T retval; - char *p = (char *)skipwhite((char_u *)expr); + char *p = skipwhite(expr); ++emsg_off; @@ -1014,7 +1014,7 @@ list_T *eval_spell_expr(char *badword, char *expr) typval_T save_val; typval_T rettv; list_T *list = NULL; - char *p = (char *)skipwhite((char_u *)expr); + char *p = skipwhite(expr); // Set "v:val" to the bad word. prepare_vimvar(VV_VAL, &save_val); @@ -1096,7 +1096,7 @@ int call_vim_function(const char *func, int argc, typval_T *argv, typval_T *rett funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; funcexe.partial = pt; - ret = call_func((char_u *)func, len, rettv, argc, argv, &funcexe); + ret = call_func(func, len, rettv, argc, argv, &funcexe); fail: if (ret == FAIL) { @@ -1287,10 +1287,10 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) } // Check for the optional 'trim' word before the marker - cmd = (char *)skipwhite((char_u *)cmd); + cmd = skipwhite(cmd); if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || ascii_iswhite(cmd[4]))) { - cmd = (char *)skipwhite((char_u *)cmd + 4); + cmd = skipwhite(cmd + 4); // Trim the indentation from all the lines in the here document. // The amount of indentation trimmed is the same as the indentation of @@ -1306,9 +1306,9 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) // The marker is the next word. if (*cmd != NUL && *cmd != '"') { - marker = (char *)skipwhite((char_u *)cmd); + marker = skipwhite(cmd); p = (char *)skiptowhite((char_u *)marker); - if (*skipwhite((char_u *)p) != NUL && *skipwhite((char_u *)p) != '"') { + if (*skipwhite(p) != NUL && *skipwhite(p) != '"') { emsg(_(e_trailing)); return NULL; } @@ -1406,7 +1406,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) if (argend > arg && argend[-1] == '.') { // For var.='str'. argend--; } - expr = (char *)skipwhite((char_u *)argend); + expr = skipwhite(argend); if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) { // ":let" without "=": list variables @@ -1449,9 +1449,9 @@ static void ex_let_const(exarg_T *eap, const bool is_const) expr++; } } - expr = (char *)skipwhite((char_u *)expr + 2); + expr = skipwhite(expr + 2); } else { - expr = (char *)skipwhite((char_u *)expr + 1); + expr = skipwhite(expr + 1); } if (eap->skip) { @@ -1522,7 +1522,7 @@ static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, i listitem_T *item = tv_list_first(l); size_t rest_len = tv_list_len(l); while (*arg != ']') { - arg = (char *)skipwhite((char_u *)arg + 1); + arg = skipwhite(arg + 1); arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, ",;]", op); if (arg == NULL) { return FAIL; @@ -1530,7 +1530,7 @@ static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, i rest_len--; item = TV_LIST_ITEM_NEXT(l, item); - arg = (char *)skipwhite((char_u *)arg); + arg = skipwhite(arg); if (*arg == ';') { /* Put the rest of the list (may be empty) in the var after ';'. * Create a new list for this. */ @@ -1545,7 +1545,7 @@ static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, i ltv.vval.v_list = rest_list; tv_list_ref(rest_list); - arg = ex_let_one((char *)skipwhite((char_u *)arg + 1), <v, false, is_const, "]", op); + arg = ex_let_one(skipwhite(arg + 1), <v, false, is_const, "]", op); tv_clear(<v); if (arg == NULL) { return FAIL; @@ -1575,7 +1575,7 @@ static const char *skip_var_list(const char *arg, int *var_count, int *semicolon // "[var, var]": find the matching ']'. p = arg; for (;;) { - p = (char *)skipwhite((char_u *)p + 1); // skip whites after '[', ';' or ',' + p = skipwhite(p + 1); // skip whites after '[', ';' or ',' s = skip_var_one((char *)p); if (s == p) { semsg(_(e_invarg2), p); @@ -1583,7 +1583,7 @@ static const char *skip_var_list(const char *arg, int *var_count, int *semicolon } ++*var_count; - p = (char *)skipwhite((char_u *)s); + p = skipwhite(s); if (*p == ']') { break; } else if (*p == ';') { @@ -1766,7 +1766,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) xfree(tofree); } - arg = (const char *)skipwhite((const char_u *)arg); + arg = (const char *)skipwhite(arg); } return arg; @@ -1812,7 +1812,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite(arg)) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { const char c1 = name[len]; @@ -1855,7 +1855,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = (char *)find_option_end((const char **)&arg, &opt_flags); if (p == NULL || (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite((const char_u *)p)) == NULL)) { + && vim_strchr((char_u *)endchars, *skipwhite(p)) == NULL)) { emsg(_(e_letunexp)); } else { int opt_type; @@ -1871,8 +1871,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo s = tv_get_string_chk(tv); // != NULL if number or string. } if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value(arg, &numval, (char_u **)&stringval, - opt_flags); + opt_type = get_option_value(arg, &numval, &stringval, opt_flags); if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { semsg(_(e_letwrong), op); @@ -1918,7 +1917,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg + 1)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite(arg + 1)) == NULL) { emsg(_(e_letunexp)); } else { char *s; @@ -1950,7 +1949,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); if (p != NULL && lv.ll_name != NULL) { - if (endchars != NULL && vim_strchr((char_u *)endchars, *skipwhite((char_u *)p)) == NULL) { + if (endchars != NULL && vim_strchr((char_u *)endchars, *skipwhite(p)) == NULL) { emsg(_(e_letunexp)); } else { set_var_lval(&lv, p, tv, copy, is_const, op); @@ -2098,7 +2097,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const p = key + len; } else { // Get the index [expr] or the first index [expr: ]. - p = (char *)skipwhite((char_u *)p + 1); + p = skipwhite(p + 1); if (*p == ':') { empty1 = true; } else { @@ -2111,7 +2110,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const tv_clear(&var1); return NULL; } - p = (char *)skipwhite((char_u *)p); + p = skipwhite(p); } // Optionally get the second index [ :expr]. @@ -2132,7 +2131,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const tv_clear(&var1); return NULL; } - p = (char *)skipwhite((char_u *)p + 1); + p = skipwhite(p + 1); if (*p == ']') { lp->ll_empty2 = true; } else { @@ -2577,7 +2576,7 @@ void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) return fi; } - expr = (char *)skipwhite((char_u *)expr); + expr = skipwhite(expr); if (expr[0] != 'i' || expr[1] != 'n' || !ascii_iswhite(expr[2])) { emsg(_("E690: Missing \"in\" after :for")); return fi; @@ -2586,7 +2585,7 @@ void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) if (skip) { ++emsg_skip; } - if (eval0((char *)skipwhite((char_u *)expr + 2), &tv, nextcmdp, !skip) == OK) { + if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) { *errp = false; if (!skip) { if (tv.v_type == VAR_LIST) { @@ -2798,10 +2797,10 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) for (;;) { char *const n = (char *)skiptowhite((char_u *)arg); - if (n == arg || ascii_iswhite_or_nul(*skipwhite((char_u *)n))) { + if (n == arg || ascii_iswhite_or_nul(*skipwhite(n))) { break; } - arg = (char *)skipwhite((char_u *)n); + arg = skipwhite(n); } } @@ -2826,7 +2825,7 @@ void ex_lockvar(exarg_T *eap) deep = -1; } else if (ascii_isdigit(*arg)) { deep = getdigits_int((char_u **)&arg, false, -1); - arg = (char *)skipwhite((char_u *)arg); + arg = skipwhite(arg); } ex_unletlock(eap, arg, deep, do_lock_var); @@ -2891,7 +2890,7 @@ static void ex_unletlock(exarg_T *eap, char *argstart, int deep, ex_unletlock_ca clear_lval(&lv); } } - arg = (char *)skipwhite((char_u *)name_end); + arg = skipwhite(name_end); } while (!ends_excmd(*arg)); eap->nextcmd = (char *)check_nextcmd((char_u *)arg); @@ -3355,7 +3354,7 @@ int eval0(char *arg, typval_T *rettv, char **nextcmd, int evaluate) const int did_emsg_before = did_emsg; const int called_emsg_before = called_emsg; - p = (char *)skipwhite((char_u *)arg); + p = skipwhite(arg); ret = eval1(&p, rettv, evaluate); if (ret == FAIL || !ends_excmd(*p)) { if (ret != FAIL) { @@ -3418,7 +3417,7 @@ int eval1(char **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (eval1(arg, rettv, evaluate && result) == FAIL) { // recursive! return FAIL; } @@ -3437,7 +3436,7 @@ int eval1(char **arg, typval_T *rettv, int evaluate) /* * Get the third variable. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (eval1(arg, &var2, evaluate && !result) == FAIL) { // Recursive! if (evaluate && result) { tv_clear(rettv); @@ -3495,7 +3494,7 @@ static int eval2(char **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 2); + *arg = skipwhite(*arg + 2); if (eval3(arg, &var2, evaluate && !result) == FAIL) { return FAIL; } @@ -3564,7 +3563,7 @@ static int eval3(char **arg, typval_T *rettv, int evaluate) /* * Get the second variable. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 2); + *arg = skipwhite(*arg + 2); if (eval4(arg, &var2, evaluate && result) == FAIL) { return FAIL; } @@ -3683,7 +3682,7 @@ static int eval4(char **arg, typval_T *rettv, int evaluate) } // Get the second variable. - *arg = (char *)skipwhite((char_u *)p + len); + *arg = skipwhite(p + len); if (eval5(arg, &var2, evaluate) == FAIL) { tv_clear(rettv); return FAIL; @@ -3757,7 +3756,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) if (op == '.' && *(*arg + 1) == '.') { // ..string concatenation (*arg)++; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (eval6(arg, &var2, evaluate, op == '.') == FAIL) { tv_clear(rettv); return FAIL; @@ -3930,7 +3929,7 @@ static int eval6(char **arg, typval_T *rettv, int evaluate, int want_string) /* * Get the second variable. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (eval7(arg, &var2, evaluate, false) == FAIL) { return FAIL; } @@ -4042,7 +4041,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) // Skip '!', '-' and '+' characters. They are handled later. start_leader = *arg; while (**arg == '!' || **arg == '-' || **arg == '+') { - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); } end_leader = *arg; @@ -4195,7 +4194,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) // nested expression: (expression). case '(': - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); ret = eval1(arg, rettv, evaluate); // recursive! if (**arg == ')') { ++*arg; @@ -4235,7 +4234,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) xfree(alias); } - *arg = (char *)skipwhite((char_u *)(*arg)); + *arg = skipwhite(*arg); // Handle following '[', '(' and '.' for expr[expr], expr.name, // expr(expr), expr->name(expr) @@ -4377,7 +4376,7 @@ static int eval_lambda(char **const arg, typval_T *const rettv, const bool evalu return FAIL; } else if (**arg != '(') { if (verbose) { - if (*skipwhite((char_u *)(*arg)) == '(') { + if (*skipwhite(*arg) == '(') { emsg(_(e_nowhitespace)); } else { semsg(_(e_missingparen), "lambda"); @@ -4419,7 +4418,7 @@ static int eval_method(char **const arg, typval_T *const rettv, const bool evalu if (STRNCMP(name, "v:lua.", 6) == 0) { lua_funcname = name + 6; *arg = (char *)skip_luafunc_name((const char *)lua_funcname); - *arg = (char *)skipwhite((char_u *)(*arg)); // to detect trailing whitespace later + *arg = skipwhite(*arg); // to detect trailing whitespace later len = *arg - lua_funcname; } else { char *alias; @@ -4530,14 +4529,14 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) if (len == 0) { return FAIL; } - *arg = (char *)skipwhite((char_u *)key + len); + *arg = skipwhite(key + len); } else { /* * something[idx] * * Get the (first) variable from inside the []. */ - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (**arg == ':') { empty1 = true; } else if (eval1(arg, &var1, evaluate) == FAIL) { // Recursive! @@ -4553,7 +4552,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) */ if (**arg == ':') { range = true; - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (**arg == ']') { empty2 = true; } else if (eval1(arg, &var2, evaluate) == FAIL) { // Recursive! @@ -4582,7 +4581,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) } return FAIL; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); // skip the ']' + *arg = skipwhite(*arg + 1); // skip the ']' } if (evaluate) { @@ -4815,7 +4814,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval char c = *option_end; *option_end = NUL; opt_type = get_option_value(*arg, &numval, - rettv == NULL ? NULL : (char_u **)&stringval, opt_flags); + rettv == NULL ? NULL : &stringval, opt_flags); if (opt_type == -3) { // invalid name if (rettv != NULL) { @@ -4929,7 +4928,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) // For "\u" store the number according to // 'encoding'. if (c != 'X') { - name += utf_char2bytes(nr, (char_u *)name); + name += utf_char2bytes(nr, name); } else { *name++ = nr; } @@ -5095,7 +5094,7 @@ static int get_list_tv(char **arg, typval_T *rettv, int evaluate) l = tv_list_alloc(kListLenShouldKnow); } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); while (**arg != ']' && **arg != NUL) { typval_T tv; if (eval1(arg, &tv, evaluate) == FAIL) { // Recursive! @@ -5113,7 +5112,7 @@ static int get_list_tv(char **arg, typval_T *rettv, int evaluate) semsg(_("E696: Missing comma in List: %s"), *arg); goto failret; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); } if (**arg != ']') { @@ -5125,7 +5124,7 @@ failret: return FAIL; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (evaluate) { tv_list_set_ret(rettv, l); } @@ -5700,7 +5699,7 @@ static int get_literal_key(char **arg, typval_T *tv) tv->v_type = VAR_STRING; tv->vval.v_string = xstrnsave(*arg, p - *arg); - *arg = (char *)skipwhite((char_u *)p); + *arg = skipwhite(p); return OK; } @@ -5715,7 +5714,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) typval_T tv; char *key = NULL; dictitem_T *item; - char *start = (char *)skipwhite((char_u *)(*arg) + 1); + char *start = skipwhite(*arg + 1); char buf[NUMBUFLEN]; /* @@ -5729,7 +5728,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) if (eval1(&start, &tv, false) == FAIL) { // recursive! return FAIL; } - if (*skipwhite((char_u *)start) == '}') { + if (*skipwhite(start) == '}') { return NOTDONE; } } @@ -5740,7 +5739,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) tvkey.v_type = VAR_UNKNOWN; tv.v_type = VAR_UNKNOWN; - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); while (**arg != '}' && **arg != NUL) { if ((literal ? get_literal_key(arg, &tvkey) @@ -5761,7 +5760,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) } } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (eval1(arg, &tv, evaluate) == FAIL) { // Recursive! if (evaluate) { tv_clear(&tvkey); @@ -5792,7 +5791,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) semsg(_("E722: Missing comma in Dictionary: %s"), *arg); goto failret; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); } if (**arg != '}') { @@ -5804,7 +5803,7 @@ failret: return FAIL; } - *arg = (char *)skipwhite((char_u *)(*arg) + 1); + *arg = skipwhite(*arg + 1); if (evaluate) { tv_dict_set_ret(rettv, d); } @@ -7267,7 +7266,7 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; funcexe.partial = partial; - return call_func((char_u *)name, -1, rettv, argcount_in, argvars_in, &funcexe); + return call_func(name, -1, rettv, argcount_in, argvars_in, &funcexe); } static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack, @@ -7969,7 +7968,7 @@ int get_id_len(const char **const arg) } len = (int)(p - *arg); - *arg = (const char *)skipwhite((const char_u *)p); + *arg = (const char *)skipwhite(p); return len; } @@ -8009,7 +8008,7 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo if (expr_start != NULL) { if (!evaluate) { len += (int)(p - *arg); - *arg = (const char *)skipwhite((const char_u *)p); + *arg = (const char *)skipwhite(p); return len; } @@ -8022,7 +8021,7 @@ int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbo return -1; } *alias = temp_string; - *arg = (const char *)skipwhite((const char_u *)p); + *arg = (const char *)skipwhite(p); return (int)STRLEN(temp_string); } @@ -8231,7 +8230,7 @@ void set_vim_var_char(int c) { char buf[MB_MAXBYTES + 1]; - buf[utf_char2bytes(c, (char_u *)buf)] = NUL; + buf[utf_char2bytes(c, buf)] = NUL; set_vim_var_string(VV_CHAR, buf, -1); } @@ -9473,7 +9472,7 @@ void ex_echo(exarg_T *eap) xfree(tofree); } tv_clear(&rettv); - arg = (char *)skipwhite((char_u *)arg); + arg = skipwhite(arg); } eap->nextcmd = (char *)check_nextcmd((char_u *)arg); @@ -9539,7 +9538,7 @@ void ex_execute(exarg_T *eap) } tv_clear(&rettv); - arg = (char *)skipwhite((char_u *)arg); + arg = skipwhite(arg); } if (ret != FAIL && ga.ga_data != NULL) { @@ -10569,7 +10568,7 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments, boo funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; - (void)call_func((const char_u *)func, name_len, &rettv, 2, argvars, &funcexe); + (void)call_func(func, name_len, &rettv, 2, argvars, &funcexe); tv_list_unref(arguments); // Restore caller scope information -- cgit From 85aae12a6dea48621ea2d24a946b3e7b86f9014d Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 8 May 2022 14:43:16 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 01f913dd70..ba7e34b541 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1327,7 +1327,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) int mi = 0; int ti = 0; - char *theline = (char *)eap->getline(NUL, eap->cookie, 0, false); + char *theline = eap->getline(NUL, eap->cookie, 0, false); if (theline == NULL) { semsg(_("E990: Missing end marker '%s'"), marker); break; @@ -3170,7 +3170,7 @@ char *cat_prefix_varname(int prefix, const char *name) /// Function given to ExpandGeneric() to obtain the list of user defined /// (global/buffer/window/built-in) variable names. -char_u *get_user_var_name(expand_T *xp, int idx) +char *get_user_var_name(expand_T *xp, int idx) { static size_t gdone; static size_t bdone; @@ -3195,9 +3195,9 @@ char_u *get_user_var_name(expand_T *xp, int idx) ++hi; } if (STRNCMP("g:", xp->xp_pattern, 2) == 0) { - return (char_u *)cat_prefix_varname('g', (char *)hi->hi_key); + return cat_prefix_varname('g', (char *)hi->hi_key); } - return hi->hi_key; + return (char *)hi->hi_key; } // b: variables @@ -3211,7 +3211,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('b', (char *)hi->hi_key); + return cat_prefix_varname('b', (char *)hi->hi_key); } // w: variables @@ -3225,7 +3225,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('w', (char *)hi->hi_key); + return cat_prefix_varname('w', (char *)hi->hi_key); } // t: variables @@ -3239,12 +3239,12 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('t', (char *)hi->hi_key); + return cat_prefix_varname('t', (char *)hi->hi_key); } // v: variables if (vidx < ARRAY_SIZE(vimvars)) { - return (char_u *)cat_prefix_varname('v', vimvars[vidx++].vv_name); + return cat_prefix_varname('v', vimvars[vidx++].vv_name); } XFREE_CLEAR(varnamebuf); @@ -4057,7 +4057,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) case '7': case '8': case '9': { - char *p = (char *)skipdigits((char_u *)(*arg) + 1); + char *p = skipdigits(*arg + 1); int get_float = false; // We accept a float when the format matches @@ -4067,7 +4067,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) // ":let vers = 1.2.3" doesn't fail. if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) { get_float = true; - p = (char *)skipdigits((char_u *)p + 2); + p = skipdigits(p + 2); if (*p == 'e' || *p == 'E') { ++p; if (*p == '-' || *p == '+') { @@ -4076,7 +4076,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) if (!ascii_isdigit(*p)) { get_float = false; } else { - p = (char *)skipdigits((char_u *)p + 1); + p = skipdigits(p + 1); } } if (ASCII_ISALPHA(*p) || *p == '.') { @@ -8206,9 +8206,10 @@ varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE /// Get string v: variable value. Uses a static buffer, can only be used once. /// If the String variable has never been set, return an empty string. /// Never returns NULL; -char_u *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET +char *get_vim_var_str(int idx) + FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET { - return (char_u *)tv_get_string(&vimvars[idx].vv_tv); + return (char *)tv_get_string(&vimvars[idx].vv_tv); } /// Get List v: variable value. Caller must take care of reference count when @@ -10217,7 +10218,7 @@ repeat: } } - tail = (char *)path_tail((char_u *)(*fnamep)); + tail = path_tail(*fnamep); *fnamelen = STRLEN(*fnamep); // ":h" - head, remove "/file_name", can be repeated -- cgit From 793496aecc23fdee93040fc94ca3e1a66da73039 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 May 2022 15:04:56 +0200 Subject: fix PVS warnings (#18459) * fix(PVS/V547): remove ifs that are always true or false * fix(PVS/V560): remove partial conditions that are always true * fix(PVS/V1044): suppress warning about loop break conditions * fix(PVS/V1063): suppress "modulo by 1 operation is meaningless" * fix(PVS/V568): suppress "operator evaluates the size of a pointer" Also mark vim-patch:8.2.4958 as ported. --- src/nvim/eval.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ba7e34b541..a1f9b7e154 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10146,9 +10146,6 @@ repeat: *fnamep = xstrnsave(*fnamep, STRLEN(*fnamep) + 2); xfree(*bufp); // free any allocated file name *bufp = *fnamep; - if (*fnamep == NULL) { - return -1; - } add_pathsep(*fnamep); } } -- cgit From f0148de7907ec297647816d51c79745be729439e Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Mon, 9 May 2022 11:49:32 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a1f9b7e154..9c2069663d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1407,7 +1407,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) argend--; } expr = skipwhite(argend); - if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL + if (*expr != '=' && !((vim_strchr("+-*/%.", *expr) != NULL && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) { // ":let" without "=": list variables if (*arg == '[') { @@ -1443,7 +1443,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) op[0] = '='; op[1] = NUL; if (*expr != '=') { - if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) { + if (vim_strchr("+-*/%.", *expr) != NULL) { op[0] = *expr; // +=, -=, *=, /=, %= or .= if (expr[0] == '.' && expr[1] == '.') { // ..= expr++; @@ -1809,10 +1809,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (len == 0) { semsg(_(e_invarg2), name - 1); } else { - if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { + if (op != NULL && vim_strchr("+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite(arg)) == NULL) { + && vim_strchr(endchars, *skipwhite(arg)) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { const char c1 = name[len]; @@ -1855,7 +1855,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = (char *)find_option_end((const char **)&arg, &opt_flags); if (p == NULL || (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite(p)) == NULL)) { + && vim_strchr(endchars, *skipwhite(p)) == NULL)) { emsg(_(e_letunexp)); } else { int opt_type; @@ -1914,10 +1914,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo return NULL; } arg++; - if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { + if (op != NULL && vim_strchr("+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr((char_u *)endchars, *skipwhite(arg + 1)) == NULL) { + && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) { emsg(_(e_letunexp)); } else { char *s; @@ -1949,7 +1949,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); if (p != NULL && lv.ll_name != NULL) { - if (endchars != NULL && vim_strchr((char_u *)endchars, *skipwhite(p)) == NULL) { + if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) { emsg(_(e_letunexp)); } else { set_var_lval(&lv, p, tv, copy, is_const, op); @@ -2752,7 +2752,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) break; } else if ((c == '<' || c == '#') && xp->xp_context == EXPAND_FUNCTIONS - && vim_strchr((char_u *)xp->xp_pattern, '(') == NULL) { + && vim_strchr(xp->xp_pattern, '(') == NULL) { // Function name can start with "" and contain '#'. break; } else if (cmdidx != CMD_let || got_eq) { @@ -3263,15 +3263,15 @@ int pattern_match(char *pat, char *text, bool ic) regmatch_T regmatch; // avoid 'l' flag in 'cpoptions' - char *save_cpo = (char *)p_cpo; - p_cpo = (char_u *)""; - regmatch.regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING); + char *save_cpo = p_cpo; + p_cpo = ""; + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = ic; matches = vim_regexec_nl(®match, (char_u *)text, (colnr_T)0); vim_regfree(regmatch.regprog); } - p_cpo = (char_u *)save_cpo; + p_cpo = save_cpo; return matches; } @@ -5872,7 +5872,7 @@ static int get_env_tv(char **arg, typval_T *rettv, int evaluate) xfree(string); // Next try expanding things like $VIM and ${HOME}. - string = (char *)expand_env_save((char_u *)name - 1); + string = expand_env_save(name - 1); if (string != NULL && *string == '$') { XFREE_CLEAR(string); } @@ -6141,7 +6141,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr use_string = true; } - if ((use_string && vim_strchr((char_u *)s, AUTOLOAD_CHAR) == NULL) || is_funcref) { + if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) { name = s; trans_name = (char *)trans_function_name((char_u **)&name, false, TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD @@ -7958,7 +7958,7 @@ int get_id_len(const char **const arg) // slice "[n:]". Also "xx:" is not a namespace. len = (int)(p - *arg); if (len > 1 - || (len == 1 && vim_strchr((char_u *)namespace_char, **arg) == NULL)) { + || (len == 1 && vim_strchr(namespace_char, **arg) == NULL)) { break; } } @@ -8089,7 +8089,7 @@ const char *find_name_end(const char *arg, const char **expr_start, const char * // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. len = (int)(p - arg); if ((len > 1 && p[-1] != '}') - || (len == 1 && vim_strchr((char_u *)namespace_char, *arg) == NULL)) { + || (len == 1 && vim_strchr(namespace_char, *arg) == NULL)) { break; } } @@ -9279,7 +9279,7 @@ bool var_check_func_name(const char *const name, const bool new_var) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { // Allow for w: b: s: and t:. - if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') + if (!(vim_strchr("wbst", name[0]) != NULL && name[1] == ':') && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') ? name[2] : name[0])) { semsg(_("E704: Funcref variable name must start with a capital: %s"), name); @@ -10110,7 +10110,7 @@ repeat: || (*fnamep)[1] == NUL) #endif && !(tilde_file && (*fnamep)[1] == NUL)) { - *fnamep = (char *)expand_env_save((char_u *)(*fnamep)); + *fnamep = expand_env_save(*fnamep); xfree(*bufp); // free any allocated file name *bufp = *fnamep; if (*fnamep == NULL) { @@ -10163,7 +10163,7 @@ repeat: // Need full path first (use expand_env() to remove a "~/") if (!has_fullname && !has_homerelative) { if (**fnamep == '~') { - p = pbuf = (char *)expand_env_save((char_u *)(*fnamep)); + p = pbuf = expand_env_save(*fnamep); } else { p = pbuf = FullName_save(*fnamep, false); } @@ -10325,12 +10325,12 @@ repeat: sep = (char_u)(*s++); if (sep) { // find end of pattern - p = (char *)vim_strchr((char_u *)s, sep); + p = vim_strchr(s, sep); if (p != NULL) { char *const pat = xstrnsave(s, p - s); s = p + 1; // find end of substitution - p = (char *)vim_strchr((char_u *)s, sep); + p = vim_strchr(s, sep); if (p != NULL) { char *const sub = xstrnsave(s, p - s); char *const str = xstrnsave(*fnamep, *fnamelen); @@ -10389,15 +10389,15 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags char *zero_width = NULL; // Make 'cpoptions' empty, so that the 'l' flag doesn't work here - save_cpo = (char *)p_cpo; - p_cpo = empty_option; + save_cpo = p_cpo; + p_cpo = (char *)empty_option; ga_init(&ga, 1, 200); do_all = (flags[0] == 'g'); regmatch.rm_ic = p_ic; - regmatch.regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { tail = str; end = str + STRLEN(str); @@ -10449,8 +10449,8 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags char *ret = xstrdup(ga.ga_data == NULL ? str : ga.ga_data); ga_clear(&ga); - if (p_cpo == empty_option) { - p_cpo = (char_u *)save_cpo; + if ((char_u *)p_cpo == empty_option) { + p_cpo = save_cpo; } else { // Darn, evaluating {sub} expression or {expr} changed the value. free_string_option((char_u *)save_cpo); -- cgit From e1bdb2a258cbe6c5cb981acc6bac82cd9e7706fb Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 13 May 2022 20:47:11 +0600 Subject: feat(ui): add `'winbar'` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for a bar at the top of each window, enabled through the `'winbar'` option. Co-authored-by: Björn Linse --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9c2069663d..f9c6b6fbb2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6405,7 +6405,7 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr) tv_dict_add_nr(dict, S_LEN("winrow"), wp->w_winrow + 1); tv_dict_add_nr(dict, S_LEN("topline"), wp->w_topline); tv_dict_add_nr(dict, S_LEN("botline"), wp->w_botline - 1); - tv_dict_add_nr(dict, S_LEN("winbar"), 0); + tv_dict_add_nr(dict, S_LEN("winbar"), wp->w_winbar_height); tv_dict_add_nr(dict, S_LEN("width"), wp->w_width); tv_dict_add_nr(dict, S_LEN("bufnr"), wp->w_buffer->b_fnum); tv_dict_add_nr(dict, S_LEN("wincol"), wp->w_wincol + 1); -- cgit From 028329850e4a4fc9171518566ba7947d9e435f83 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 18 May 2022 13:06:02 +0200 Subject: refactor: grid->rows and grid->cols --- src/nvim/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f9c6b6fbb2..641dcae55e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6865,8 +6865,8 @@ void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col) // have its own buffer, this should just read from it instead. msg_scroll_flush(); if (msg_grid.chars && msg_grid.comp_index > 0 && *row >= msg_grid.comp_row - && *row < (msg_grid.Rows + msg_grid.comp_row) - && *col < msg_grid.Columns) { + && *row < (msg_grid.rows + msg_grid.comp_row) + && *col < msg_grid.cols) { *grid = &msg_grid; *row -= msg_grid.comp_row; } -- cgit From eae4eddc54add4cbf16131edee28acf9ab53cdbb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 22 May 2022 19:03:17 +0800 Subject: vim-patch:8.2.4996: setbufline() may change Visual selection Problem: setbufline() may change Visual selection. (Qiming Zhao) Solution: Disable Visual mode when using another buffer. (closes vim/vim#10466) https://github.com/vim/vim/commit/0ad00a7fd3e0389f565876521e395c35144d8009 --- src/nvim/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 641dcae55e..33080c145d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6886,6 +6886,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T buf_T *curbuf_save = NULL; win_T *curwin_save = NULL; const bool is_curbuf = buf == curbuf; + const bool save_VIsual_active = VIsual_active; // When using the current buffer ml_mfp will be set if needed. Useful when // setline() is used on startup. For other buffers the buffer must be @@ -6896,6 +6897,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T } if (!is_curbuf) { + VIsual_active = false; curbuf_save = curbuf; curwin_save = curwin; curbuf = buf; @@ -6986,6 +6988,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T if (!is_curbuf) { curbuf = curbuf_save; curwin = curwin_save; + VIsual_active = save_VIsual_active; } } -- cgit From 9fec6dc9a25b5cf9c9a444ac2bd0728e8af3229e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 25 May 2022 20:31:14 +0200 Subject: refactor(uncrustify): set maximum number of consecutive newlines to 2 (#18695) --- src/nvim/eval.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 33080c145d..792c8d3aec 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -53,12 +53,10 @@ #include "nvim/version.h" #include "nvim/window.h" - // TODO(ZyX-I): Remove DICT_MAXNEST, make users be non-recursive instead #define DICT_MAXNEST 100 // maximum nesting of lists and dicts - static char *e_letunexp = N_("E18: Unexpected characters in :let"); static char *e_missbrac = N_("E111: Missing ']'"); static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); @@ -1067,7 +1065,6 @@ int get_spellword(list_T *const list, const char **ret_word) return tv_list_find_nr(list, -1, NULL); } - // Call some vim script function and return the result in "*rettv". // Uses argv[0] to argv[argc-1] for the function arguments. argv[argc] // should have type VAR_UNKNOWN. @@ -1209,7 +1206,6 @@ void prof_child_exit(proftime_T *tm) script_prof_restore(tm); } - /// Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding /// it in "*cp". Doesn't give error messages. int eval_foldexpr(char *arg, int *cp) @@ -2701,7 +2697,6 @@ void free_for_info(void *fi_void) xfree(fi); } - void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) FUNC_ATTR_NONNULL_ALL { @@ -3146,7 +3141,6 @@ void del_menutrans_vars(void) * get_user_var_name(). */ - static char *varnamebuf = NULL; static size_t varnamebuflen = 0; @@ -5636,7 +5630,6 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack return abort; } - /// Mark all lists and dicts referenced in given mark /// /// @return true if setting references failed somehow. @@ -5683,7 +5676,6 @@ static inline bool set_ref_dict(dict_T *dict, int copyID) return false; } - /// Get the key for *{key: val} into "tv" and advance "arg". /// /// @return FAIL when there is no valid key. @@ -7287,7 +7279,6 @@ static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_ return set_ref_in_item(&tv, copyID, ht_stack, list_stack); break; - default: abort(); } @@ -10248,7 +10239,6 @@ repeat: *usedlen += 2; } - // ":t" - tail, just the basename if (src[*usedlen] == ':' && src[*usedlen + 1] == 't') { *usedlen += 2; @@ -10489,7 +10479,6 @@ bool common_job_callbacks(dict_T *vopts, CallbackReader *on_stdout, CallbackRead return false; } - Channel *find_job(uint64_t id, bool show_error) { Channel *data = find_channel(id); @@ -10507,7 +10496,6 @@ Channel *find_job(uint64_t id, bool show_error) return data; } - void script_host_eval(char *name, typval_T *argvars, typval_T *rettv) { if (check_secure()) { -- cgit From 7b952793d5c46e862a9cdec3d6ac4762370296ed Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 May 2022 04:49:25 +0200 Subject: refactor: missing parenthesis may cause unexpected problems (#17443) related vim-8.2.{4402,4639} --- src/nvim/eval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 792c8d3aec..02dc5ec954 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -124,13 +124,13 @@ typedef struct { #define VV(idx, name, type, flags) \ [idx] = { \ - .vv_name = name, \ + .vv_name = (name), \ .vv_di = { \ - .di_tv = { .v_type = type }, \ + .di_tv = { .v_type = (type) }, \ .di_flags = 0, \ .di_key = { 0 }, \ }, \ - .vv_flags = flags, \ + .vv_flags = (flags), \ } #define VIMVAR_KEY_LEN 16 // Maximum length of the key of v:variables -- cgit From 0c95028688dfee776750c4732811508294557ba2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 May 2022 19:55:04 +0800 Subject: vim-patch:8.2.5046: vim_regsub() can overwrite the destination (#18812) Problem: vim_regsub() can overwrite the destination. Solution: Pass the destination length, give an error when it doesn't fit. https://github.com/vim/vim/commit/4aaf3e7f4db599932d01d87e5bbcdc342cccee27 --- src/nvim/eval.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 02dc5ec954..6eb210fc79 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10413,7 +10413,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags // - The text up to where the match is. // - The substituted text. // - The text after the match. - sublen = vim_regsub(®match, (char_u *)sub, expr, (char_u *)tail, false, true, false); + sublen = vim_regsub(®match, (char_u *)sub, expr, (char_u *)tail, 0, REGSUB_MAGIC); ga_grow(&ga, (int)((end - tail) + sublen - (regmatch.endp[0] - regmatch.startp[0]))); @@ -10421,8 +10421,9 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags int i = (int)(regmatch.startp[0] - (char_u *)tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); // add the substituted text - (void)vim_regsub(®match, (char_u *)sub, expr, (char_u *)ga.ga_data - + ga.ga_len + i, true, true, false); + (void)vim_regsub(®match, (char_u *)sub, expr, + (char_u *)ga.ga_data + ga.ga_len + i, sublen, + REGSUB_COPY | REGSUB_MAGIC); ga.ga_len += i + sublen - 1; tail = (char *)regmatch.endp[0]; if (*tail == NUL) { -- cgit From cd9e08cb94663558891fdd46dfa58f662e947be5 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 14 Jun 2022 14:57:06 +0200 Subject: refactor: enable -Wconversion warning for eval.c (#18448) Work on https://github.com/neovim/neovim/issues/567 --- src/nvim/eval.c | 212 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 106 insertions(+), 106 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6eb210fc79..fd69b5b726 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -601,7 +601,7 @@ void var_redir_str(char *value, int value_len) } ga_grow(&redir_ga, len); - memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len); + memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, (size_t)len); redir_ga.ga_len += len; } @@ -1062,7 +1062,7 @@ int get_spellword(list_T *const list, const char **ret_word) if (*ret_word == NULL) { return -1; } - return tv_list_find_nr(list, -1, NULL); + return (int)tv_list_find_nr(list, -1, NULL); } // Call some vim script function and return the result in "*rettv". @@ -1347,7 +1347,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) p++; text_indent_len++; } - text_indent = xstrnsave(theline, text_indent_len); + text_indent = xstrnsave(theline, (size_t)text_indent_len); } // with "trim": skip the indent matching the first line if (text_indent != NULL) { @@ -1516,7 +1516,7 @@ static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, i assert(l != NULL); listitem_T *item = tv_list_first(l); - size_t rest_len = tv_list_len(l); + size_t rest_len = (size_t)tv_list_len(l); while (*arg != ']') { arg = skipwhite(arg + 1); arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, ",;]", op); @@ -1530,7 +1530,7 @@ static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, i if (*arg == ';') { /* Put the rest of the list (may be empty) in the var after ';'. * Create a new list for this. */ - list_T *const rest_list = tv_list_alloc(rest_len); + list_T *const rest_list = tv_list_alloc((ptrdiff_t)rest_len); while (item != NULL) { tv_list_append_tv(rest_list, TV_LIST_ITEM_TV(item)); item = TV_LIST_ITEM_NEXT(l, item); @@ -1930,7 +1930,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } if (p != NULL) { write_reg_contents(*arg == '@' ? '"' : *arg, - (const char_u *)p, STRLEN(p), false); + (const char_u *)p, (ssize_t)STRLEN(p), false); arg_end = arg + 1; } xfree(ptofree); @@ -2174,11 +2174,11 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const // variable name is valid (only variable name unless it is l: or // g: dictionary). Disallow overwriting a builtin function. if (rettv != NULL && lp->ll_dict->dv_scope != 0) { - int prevval; + char prevval; int wrong; if (len != -1) { - prevval = (char_u)key[len]; + prevval = key[len]; key[len] = NUL; } else { prevval = 0; // Avoid compiler warning. @@ -2222,7 +2222,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const if (len == -1) { lp->ll_newkey = xstrdup(key); } else { - lp->ll_newkey = xstrnsave(key, len); + lp->ll_newkey = xstrnsave(key, (size_t)len); } tv_clear(&var1); break; @@ -2280,11 +2280,11 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const lp->ll_dict = NULL; lp->ll_list = lp->ll_tv->vval.v_list; - lp->ll_li = tv_list_find(lp->ll_list, lp->ll_n1); + lp->ll_li = tv_list_find(lp->ll_list, (int)lp->ll_n1); if (lp->ll_li == NULL) { if (lp->ll_n1 < 0) { lp->ll_n1 = 0; - lp->ll_li = tv_list_find(lp->ll_list, lp->ll_n1); + lp->ll_li = tv_list_find(lp->ll_list, (int)lp->ll_n1); } } if (lp->ll_li == NULL) { @@ -2303,7 +2303,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const lp->ll_n2 = (long)tv_get_number(&var2); // Is number or string. tv_clear(&var2); if (lp->ll_n2 < 0) { - ni = tv_list_find(lp->ll_list, lp->ll_n2); + ni = tv_list_find(lp->ll_list, (int)lp->ll_n2); if (ni == NULL) { if (!quiet) { semsg(_(e_listidx), (int64_t)lp->ll_n2); @@ -2381,12 +2381,12 @@ static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, cons lp->ll_n2 = tv_blob_len(lp->ll_blob); } - for (int il = lp->ll_n1, ir = 0; il <= lp->ll_n2; il++) { + for (int il = (int)lp->ll_n1, ir = 0; il <= (int)lp->ll_n2; il++) { tv_blob_set(lp->ll_blob, il, tv_blob_get(rettv->vval.v_blob, ir++)); } } else { bool error = false; - const char val = tv_get_number_chk(rettv, &error); + const char val = (char)tv_get_number_chk(rettv, &error); if (!error) { garray_T *const gap = &lp->ll_blob->bv_ga; @@ -2394,7 +2394,7 @@ static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, cons // the end is an error otherwise. if (lp->ll_n1 < gap->ga_len || lp->ll_n1 == gap->ga_len) { ga_grow(&lp->ll_blob->bv_ga, 1); - tv_blob_set(lp->ll_blob, lp->ll_n1, val); + tv_blob_set(lp->ll_blob, (int)lp->ll_n1, (char_u)val); if (lp->ll_n1 == gap->ga_len) { gap->ga_len++; } @@ -2407,7 +2407,7 @@ static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, cons if (is_const) { emsg(_(e_cannot_mod)); - *endp = cc; + *endp = (char)cc; return; } @@ -2426,7 +2426,7 @@ static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, cons } else { set_var_const(lp->ll_name, lp->ll_name_len, rettv, copy, is_const); } - *endp = cc; + *endp = (char)cc; } else if (var_check_lock(lp->ll_newkey == NULL ? lp->ll_tv->v_lock : lp->ll_tv->vval.v_dict->dv_lock, @@ -2434,7 +2434,7 @@ static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, cons // Skip } else if (lp->ll_range) { listitem_T *ll_li = lp->ll_li; - int ll_n1 = lp->ll_n1; + int ll_n1 = (int)lp->ll_n1; if (is_const) { emsg(_("E996: Cannot lock a range")); @@ -2658,7 +2658,7 @@ bool next_for_item(void *fi_void, char *arg) typval_T tv; tv.v_type = VAR_STRING; tv.v_lock = VAR_FIXED; - tv.vval.v_string = xstrnsave(fi->fi_string + fi->fi_byte_idx, len); + tv.vval.v_string = xstrnsave(fi->fi_string + fi->fi_byte_idx, (size_t)len); fi->fi_byte_idx += len; const int result = ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK; @@ -2918,7 +2918,7 @@ static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_ } else if (do_unlet(lp->ll_name, lp->ll_name_len, forceit) == FAIL) { ret = FAIL; } - *name_end = cc; + *name_end = (char)cc; } else if ((lp->ll_list != NULL // ll_list is not NULL when lvalue is not in a list, NULL lists // yield E689. @@ -3098,7 +3098,7 @@ static int do_lock_var(lval_T *lp, char *name_end FUNC_ATTR_UNUSED, exarg_T *eap if (lock) { di->di_flags |= DI_FLAGS_LOCK; } else { - di->di_flags &= ~DI_FLAGS_LOCK; + di->di_flags &= (uint8_t)(~DI_FLAGS_LOCK); } tv_item_lock(&di->di_tv, deep, lock, false); } @@ -3156,7 +3156,7 @@ char *cat_prefix_varname(int prefix, const char *name) varnamebuf = xmalloc(len); varnamebuflen = len; } - *varnamebuf = prefix; + *varnamebuf = (char)prefix; varnamebuf[1] = ':'; STRCPY(varnamebuf + 2, name); return varnamebuf; @@ -3284,7 +3284,7 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ int len = name_len; if (!evaluate) { - check_vars((const char *)s, len); + check_vars((const char *)s, (size_t)len); } // If "s" is the name of a variable of type VAR_FUNC @@ -3294,7 +3294,7 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ // Need to make a copy, in case evaluating the arguments makes // the name invalid. - s = xmemdupz(s, len); + s = xmemdupz(s, (size_t)len); // Invoke the function. funcexe_T funcexe = FUNCEXE_INIT; @@ -3782,10 +3782,10 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) blob_T *const b = tv_blob_alloc(); for (int i = 0; i < tv_blob_len(b1); i++) { - ga_append(&b->bv_ga, tv_blob_get(b1, i)); + ga_append(&b->bv_ga, (char)tv_blob_get(b1, i)); } for (int i = 0; i < tv_blob_len(b2); i++) { - ga_append(&b->bv_ga, tv_blob_get(b2, i)); + ga_append(&b->bv_ga, (char)tv_blob_get(b2, i)); } tv_clear(rettv); @@ -3819,7 +3819,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) return FAIL; } if (var2.v_type == VAR_FLOAT) { - f1 = n1; + f1 = (float_T)n1; } } if (var2.v_type == VAR_FLOAT) { @@ -3833,7 +3833,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) return FAIL; } if (rettv->v_type == VAR_FLOAT) { - f2 = n2; + f2 = (float_T)n2; } } tv_clear(rettv); @@ -3931,7 +3931,7 @@ static int eval6(char **arg, typval_T *rettv, int evaluate, int want_string) if (evaluate) { if (var2.v_type == VAR_FLOAT) { if (!use_float) { - f1 = n1; + f1 = (float_T)n1; use_float = true; } f2 = var2.vval.v_float; @@ -3943,7 +3943,7 @@ static int eval6(char **arg, typval_T *rettv, int evaluate, int want_string) return FAIL; } if (use_float) { - f2 = n2; + f2 = (float_T)n2; } } @@ -4104,7 +4104,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) break; } if (blob != NULL) { - ga_append(&blob->bv_ga, (hex2nr(*bp) << 4) + hex2nr(*(bp + 1))); + ga_append(&blob->bv_ga, (char)((hex2nr(*bp) << 4) + hex2nr(*(bp + 1)))); } if (bp[2] == '.' && ascii_isxdigit(bp[3])) { bp++; @@ -4221,7 +4221,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) } else if (evaluate) { ret = get_var_tv((const char *)s, len, rettv, NULL, true, false); } else { - check_vars((const char *)s, len); + check_vars((const char *)s, (size_t)len); ret = OK; } } @@ -4271,7 +4271,7 @@ static int eval7_leader(typval_T *const rettv, const char *const start_leader, end_leader--; if (*end_leader == '!') { if (rettv->v_type == VAR_FLOAT) { - f = !f; + f = !(bool)f; } else { val = !val; } @@ -4336,7 +4336,7 @@ static int call_func_rettv(char **const arg, typval_T *const rettv, const bool e funcexe.partial = pt; funcexe.selfdict = selfdict; funcexe.basetv = basetv; - const int ret = get_func_tv((char_u *)funcname, is_lua ? *arg - funcname : -1, rettv, + const int ret = get_func_tv((char_u *)funcname, is_lua ? (int)(*arg - funcname) : -1, rettv, (char_u **)arg, &funcexe); // Clear the funcref afterwards, so that deleting it while @@ -4413,7 +4413,7 @@ static int eval_method(char **const arg, typval_T *const rettv, const bool evalu lua_funcname = name + 6; *arg = (char *)skip_luafunc_name((const char *)lua_funcname); *arg = skipwhite(*arg); // to detect trailing whitespace later - len = *arg - lua_funcname; + len = (int)(*arg - lua_funcname); } else { char *alias; len = get_name_len((const char **)arg, &alias, evaluate, true); @@ -4655,10 +4655,10 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) rettv->vval.v_blob = NULL; } else { blob_T *const blob = tv_blob_alloc(); - ga_grow(&blob->bv_ga, n2 - n1 + 1); - blob->bv_ga.ga_len = n2 - n1 + 1; + ga_grow(&blob->bv_ga, (int)(n2 - n1 + 1)); + blob->bv_ga.ga_len = (int)(n2 - n1 + 1); for (long i = n1; i <= n2; i++) { - tv_blob_set(blob, i - n1, tv_blob_get(rettv->vval.v_blob, i)); + tv_blob_set(blob, (int)(i - n1), tv_blob_get(rettv->vval.v_blob, (int)i)); } tv_clear(rettv); tv_blob_set_ret(rettv, blob); @@ -4670,7 +4670,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) n1 = len + n1; } if (n1 < len && n1 >= 0) { - const int v = (int)tv_blob_get(rettv->vval.v_blob, n1); + const int v = (int)tv_blob_get(rettv->vval.v_blob, (int)n1); tv_clear(rettv); rettv->v_type = VAR_NUMBER; rettv->vval.v_number = v; @@ -4708,7 +4708,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) n2 = -1; } l = tv_list_alloc(n2 - n1 + 1); - item = tv_list_find(rettv->vval.v_list, n1); + item = tv_list_find(rettv->vval.v_list, (int)n1); while (n1++ <= n2) { tv_list_append_tv(l, TV_LIST_ITEM_TV(item)); item = TV_LIST_ITEM_NEXT(rettv->vval.v_list, item); @@ -4716,7 +4716,7 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose) tv_clear(rettv); tv_list_set_ret(rettv, l); } else { - tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, n1)), &var1); + tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, (int)n1)), &var1); tv_clear(rettv); *rettv = var1; } @@ -4878,7 +4878,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) * characters. */ const int len = (int)(p - *arg + extra); - char *name = xmalloc(len); + char *name = xmalloc((size_t)len); rettv->v_type = VAR_STRING; rettv->vval.v_string = name; @@ -4924,7 +4924,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) if (c != 'X') { name += utf_char2bytes(nr, name); } else { - *name++ = nr; + *name++ = (char)nr; } } break; @@ -4938,11 +4938,11 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) case '5': case '6': case '7': - *name = *p++ - '0'; + *name = (char)(*p++ - '0'); if (*p >= '0' && *p <= '7') { - *name = (*name << 3) + *p++ - '0'; + *name = (char)((*name << 3) + *p++ - '0'); if (*p >= '0' && *p <= '7') { - *name = (*name << 3) + *p++ - '0'; + *name = (char)((*name << 3) + *p++ - '0'); } } ++name; @@ -5019,7 +5019,7 @@ static int get_lit_string_tv(char **arg, typval_T *rettv, int evaluate) /* * Copy the string into allocated memory, handling '' to ' reduction. */ - str = xmalloc((p - *arg) - reduce); + str = xmalloc((size_t)((p - *arg) - reduce)); rettv->v_type = VAR_STRING; rettv->vval.v_string = str; @@ -5689,7 +5689,7 @@ static int get_literal_key(char **arg, typval_T *tv) } for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {} tv->v_type = VAR_STRING; - tv->vval.v_string = xstrnsave(*arg, p - *arg); + tv->vval.v_string = xstrnsave(*arg, (size_t)(p - *arg)); *arg = skipwhite(p); return OK; @@ -5869,7 +5869,7 @@ static int get_env_tv(char **arg, typval_T *rettv, int evaluate) XFREE_CLEAR(string); } } - name[len] = cc; + name[len] = (char)cc; rettv->v_type = VAR_STRING; rettv->vval.v_string = string; } @@ -5909,7 +5909,7 @@ win_T *find_win_by_nr_or_id(typval_T *vp) int nr = (int)tv_get_number_chk(vp, NULL); if (nr >= LOWEST_WIN_ID) { - return win_id2wp(tv_get_number(vp)); + return win_id2wp((int)tv_get_number(vp)); } return find_win_by_nr(vp, NULL); @@ -6028,11 +6028,11 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) } if (map) { if (tv.vval.v_number != val) { - tv_blob_set(b, i, tv.vval.v_number); + tv_blob_set(b, i, (char_u)tv.vval.v_number); } } else if (rem) { char *const p = argvars[0].vval.v_blob->bv_ga.ga_data; - memmove(p + i, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1); + memmove(p + i, p + i + 1, (size_t)(b->bv_ga.ga_len - i - 1)); b->bv_ga.ga_len--; i--; } @@ -6222,7 +6222,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr const int lv_len = tv_list_len(list); pt->pt_argc = arg_len + lv_len; - pt->pt_argv = xmalloc(sizeof(pt->pt_argv[0]) * pt->pt_argc); + pt->pt_argv = xmalloc(sizeof(pt->pt_argv[0]) * (size_t)pt->pt_argc); int i = 0; for (; i < arg_len; i++) { tv_copy(&arg_pt->pt_argv[i], &pt->pt_argv[i]); @@ -6336,7 +6336,7 @@ linenr_T tv_get_lnum_buf(const typval_T *const tv, const buf_T *const buf) && buf != NULL) { return buf->b_ml.ml_line_count; } - return tv_get_number_chk(tv, NULL); + return (linenr_T)tv_get_number_chk(tv, NULL); } void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv) @@ -6455,7 +6455,7 @@ win_T *find_tabwin(typval_T *wvp, typval_T *tvp) if (tvp->v_type != VAR_UNKNOWN) { long n = tv_get_number(tvp); if (n >= 0) { - tp = find_tabpage(n); + tp = find_tabpage((int)n); } } else { tp = curtab; @@ -6771,7 +6771,7 @@ char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) // Build the argument vector int i = 0; - char **argv = xcalloc(argc + 1, sizeof(char *)); + char **argv = xcalloc((size_t)argc + 1, sizeof(char *)); TV_LIST_ITER_CONST(argl, arg, { const char *a = tv_get_string_chk(TV_LIST_ITEM_TV(arg)); if (!a) { @@ -6843,7 +6843,7 @@ void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buf void return_register(int regname, typval_T *rettv) { - char buf[2] = { regname, 0 }; + char buf[2] = { (char)regname, 0 }; rettv->v_type = VAR_STRING; rettv->vval.v_string = xstrdup(buf); @@ -6940,7 +6940,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T int old_len = (int)STRLEN(ml_get(lnum)); if (u_savesub(lnum) == OK && ml_replace(lnum, (char *)line, true) == OK) { - inserted_bytes(lnum, 0, old_len, STRLEN(line)); + inserted_bytes(lnum, 0, old_len, (int)STRLEN(line)); if (is_curbuf && lnum == curwin->w_cursor.lnum) { check_cursor_col(); } @@ -6970,7 +6970,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T if (wp->w_buffer == buf && (wp->w_buffer != curbuf || wp == curwin) && wp->w_cursor.lnum > append_lnum) { - wp->w_cursor.lnum += added; + wp->w_cursor.lnum += (linenr_T)added; } } check_cursor_col(); @@ -7054,7 +7054,7 @@ void get_xdg_var_list(const XDGVarType xdg, typval_T *rettv) if (dir != NULL && dir_len > 0) { char *dir_with_nvim = xmemdupz(dir, dir_len); dir_with_nvim = concat_fnames_realloc(dir_with_nvim, "nvim", true); - tv_list_append_string(list, dir_with_nvim, strlen(dir_with_nvim)); + tv_list_append_string(list, dir_with_nvim, (ssize_t)strlen(dir_with_nvim)); xfree(dir_with_nvim); } } while (iter != NULL); @@ -7119,7 +7119,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist // execute the command size_t nread = 0; char *res = NULL; - int status = os_system(argv, input, input_len, &res, &nread); + int status = os_system(argv, input, (size_t)input_len, &res, &nread); if (profiling) { prof_child_exit(&wait_time); @@ -7142,7 +7142,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist if (retlist) { int keepempty = 0; if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) { - keepempty = tv_get_number(&argvars[2]); + keepempty = (int)tv_get_number(&argvars[2]); } rettv->vval.v_list = string_to_list(res, nread, (bool)keepempty); tv_list_ref(rettv->vval.v_list); @@ -7303,7 +7303,7 @@ static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID, ht_st timer_T *find_timer_by_nr(varnumber_T xx) { - return pmap_get(uint64_t)(&timers, xx); + return pmap_get(uint64_t)(&timers, (uint64_t)xx); } void add_timer_info(typval_T *rettv, timer_T *timer) @@ -7401,17 +7401,17 @@ uint64_t timer_start(const long timeout, const int repeat_count, const Callback timer->emsg_count = 0; timer->repeat_count = repeat_count; timer->timeout = timeout; - timer->timer_id = last_timer_id++; + timer->timer_id = (int)last_timer_id++; timer->callback = *callback; time_watcher_init(&main_loop, &timer->tw, timer); timer->tw.events = multiqueue_new_child(main_loop.events); // if main loop is blocked, don't queue up multiple events timer->tw.blockable = true; - time_watcher_start(&timer->tw, timer_due_cb, timeout, timeout); + time_watcher_start(&timer->tw, timer_due_cb, (uint64_t)timeout, (uint64_t)timeout); - pmap_put(uint64_t)(&timers, timer->timer_id, timer); - return timer->timer_id; + pmap_put(uint64_t)(&timers, (uint64_t)timer->timer_id, timer); + return (uint64_t)timer->timer_id; } void timer_stop(timer_T *timer) @@ -7432,7 +7432,7 @@ static void timer_close_cb(TimeWatcher *tw, void *data) timer_T *timer = (timer_T *)data; multiqueue_free(timer->tw.events); callback_free(&timer->callback); - pmap_del(uint64_t)(&timers, timer->timer_id); + pmap_del(uint64_t)(&timers, (uint64_t)timer->timer_id); timer_decref(timer); } @@ -7556,7 +7556,7 @@ bool read_blob(FILE *const fd, blob_T *const blob) const int size = (int)os_fileinfo_size(&file_info); ga_grow(&blob->bv_ga, size); blob->bv_ga.ga_len = size; - if (fread(blob->bv_ga.ga_data, 1, blob->bv_ga.ga_len, fd) + if (fread(blob->bv_ga.ga_data, 1, (size_t)blob->bv_ga.ga_len, fd) < (size_t)blob->bv_ga.ga_len) { return false; } @@ -7585,7 +7585,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) if (tv->v_type != VAR_LIST && tv->v_type != VAR_NUMBER) { const char *ret = tv_get_string_chk(tv); if (ret) { - *len = strlen(ret); + *len = (ptrdiff_t)strlen(ret); return xmemdupz(ret, (size_t)(*len)); } else { *len = -1; @@ -7594,7 +7594,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) } if (tv->v_type == VAR_NUMBER) { // Treat number as a buffer-id. - buf_T *buf = buflist_findnr(tv->vval.v_number); + buf_T *buf = buflist_findnr((int)tv->vval.v_number); if (buf) { for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { @@ -7612,7 +7612,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) return NULL; } - char *ret = xmalloc(*len + 1); + char *ret = xmalloc((size_t)(*len) + 1); char *end = ret; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { @@ -7629,14 +7629,14 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) // Pre-calculate the resulting length. list_T *list = tv->vval.v_list; TV_LIST_ITER_CONST(list, li, { - *len += strlen(tv_get_string(TV_LIST_ITEM_TV(li))) + 1; + *len += (ptrdiff_t)strlen(tv_get_string(TV_LIST_ITEM_TV(li))) + 1; }); if (*len == 0) { return NULL; } - char *ret = xmalloc(*len + endnl); + char *ret = xmalloc((size_t)(*len) + endnl); char *end = ret; TV_LIST_ITER_CONST(list, li, { for (const char *s = tv_get_string(TV_LIST_ITEM_TV(li)); *s != NUL; s++) { @@ -7654,7 +7654,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) /// Convert the specified byte index of line 'lnum' in buffer 'buf' to a /// character index. Works only for loaded buffers. Returns -1 on failure. /// The index of the first byte and the first character is zero. -int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) +int buf_byteidx_to_charidx(buf_T *buf, linenr_T lnum, int byteidx) { if (buf == NULL || buf->b_ml.ml_mfp == NULL) { return -1; @@ -7692,7 +7692,7 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) /// The index of the first byte and the first character is zero. /// /// @return -1 on failure. -int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) +int buf_charidx_to_byteidx(buf_T *buf, linenr_T lnum, int charidx) { if (buf == NULL || buf->b_ml.ml_mfp == NULL) { return -1; @@ -7710,7 +7710,7 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) t += utfc_ptr2len(t); } - return t - str; + return (int)(t - str); } /// Translate a VimL object into a position @@ -7743,21 +7743,21 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret } // Get the line number. - pos.lnum = tv_list_find_nr(l, 0L, &error); + pos.lnum = (linenr_T)tv_list_find_nr(l, 0L, &error); if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count) { // Invalid line number. return NULL; } // Get the column number. - pos.col = tv_list_find_nr(l, 1L, &error); + pos.col = (colnr_T)tv_list_find_nr(l, 1L, &error); if (error) { return NULL; } if (charcol) { len = mb_charlen(ml_get(pos.lnum)); } else { - len = STRLEN(ml_get(pos.lnum)); + len = (int)STRLEN(ml_get(pos.lnum)); } // We accept "$" for the column number: last column. @@ -7776,7 +7776,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret pos.col--; // Get the virtual offset. Defaults to zero. - pos.coladd = tv_list_find_nr(l, 2L, &error); + pos.coladd = (colnr_T)tv_list_find_nr(l, 2L, &error); if (error) { pos.coladd = 0; } @@ -7858,7 +7858,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool charcol) { list_T *l; - long i = 0; + int i = 0; long n; // List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only @@ -7878,14 +7878,14 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c if (n == 0) { n = curbuf->b_fnum; // Current buffer. } - *fnump = n; + *fnump = (int)n; } n = tv_list_find_nr(l, i++, NULL); // lnum if (n < 0) { return FAIL; } - posp->lnum = n; + posp->lnum = (linenr_T)n; n = tv_list_find_nr(l, i++, NULL); // col if (n < 0) { @@ -7898,19 +7898,19 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c if (buf == NULL || buf->b_ml.ml_mfp == NULL) { return FAIL; } - n = buf_charidx_to_byteidx(buf, posp->lnum, n) + 1; + n = buf_charidx_to_byteidx(buf, posp->lnum, (int)n) + 1; } - posp->col = n; + posp->col = (colnr_T)n; n = tv_list_find_nr(l, i, NULL); // off if (n < 0) { posp->coladd = 0; } else { - posp->coladd = n; + posp->coladd = (colnr_T)n; } if (curswantp != NULL) { - *curswantp = tv_list_find_nr(l, i + 1, NULL); // curswant + *curswantp = (colnr_T)tv_list_find_nr(l, i + 1, NULL); // curswant } return OK; @@ -8143,8 +8143,8 @@ static char *make_expanded_name(const char *in_start, char *expr_start, char *ex temp_result = eval_to_string(expr_start + 1, &nextcmd, false); if (temp_result != NULL && nextcmd == NULL) { - retval = xmalloc(STRLEN(temp_result) + (expr_start - in_start) - + (in_end - expr_end) + 1); + retval = xmalloc(STRLEN(temp_result) + (size_t)(expr_start - in_start) + + (size_t)(in_end - expr_end) + 1); STRCPY(retval, in_start); STRCAT(retval, temp_result); STRCAT(retval, expr_end + 1); @@ -8347,7 +8347,7 @@ void set_reg_var(int c) if (c == 0 || c == ' ') { regname = '"'; } else { - regname = c; + regname = (char)c; } // Avoid free/alloc when the value is already right. if (vimvars[VV_REG].vv_str == NULL || vimvars[VV_REG].vv_str[0] != c) { @@ -8903,7 +8903,7 @@ void new_script_vars(scid_T id) /// Initialize dictionary "dict" as a scope and set variable "dict_var" to /// point to it. -void init_var_dict(dict_T *dict, ScopeDictDictItem *dict_var, int scope) +void init_var_dict(dict_T *dict, ScopeDictDictItem *dict_var, ScopeType scope) { hash_init(&dict->dv_hashtab); dict->dv_lock = VAR_UNLOCKED; @@ -8979,7 +8979,7 @@ static void delete_var(hashtab_T *ht, hashitem_T *hi) static void list_one_var(dictitem_T *v, const char *prefix, int *first) { char *const s = encode_tv2echo(&v->di_tv, NULL); - list_one_var_a(prefix, (const char *)v->di_key, STRLEN(v->di_key), + list_one_var_a(prefix, (const char *)v->di_key, (ptrdiff_t)STRLEN(v->di_key), v->di_tv.v_type, (s == NULL ? "" : s), first); xfree(s); } @@ -8988,7 +8988,7 @@ static void list_one_var(dictitem_T *v, const char *prefix, int *first) /// will be used. /// @param[in,out] first When true clear rest of screen and set to false. static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t name_len, - const int type, const char *string, int *first) + const VarType type, const char *string, int *first) { // don't use msg() or msg_attr() to avoid overwriting "v:statusmsg" msg_start(); @@ -9521,7 +9521,7 @@ void ex_execute(exarg_T *eap) ? encode_tv2echo(&rettv, NULL) : encode_tv2string(&rettv, NULL); const size_t len = strlen(argstr); - ga_grow(&ga, len + 2); + ga_grow(&ga, (int)len + 2); if (!GA_EMPTY(&ga)) { ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; } @@ -9529,7 +9529,7 @@ void ex_execute(exarg_T *eap) if (eap->cmdidx != CMD_execute) { xfree((void *)argstr); } - ga.ga_len += len; + ga.ga_len += (int)len; } tv_clear(&rettv); @@ -9620,15 +9620,15 @@ void func_do_profile(ufunc_T *fp) fp->uf_tm_total = profile_zero(); if (fp->uf_tml_count == NULL) { - fp->uf_tml_count = xcalloc(len, sizeof(int)); + fp->uf_tml_count = xcalloc((size_t)len, sizeof(int)); } if (fp->uf_tml_total == NULL) { - fp->uf_tml_total = xcalloc(len, sizeof(proftime_T)); + fp->uf_tml_total = xcalloc((size_t)len, sizeof(proftime_T)); } if (fp->uf_tml_self == NULL) { - fp->uf_tml_self = xcalloc(len, sizeof(proftime_T)); + fp->uf_tml_self = xcalloc((size_t)len, sizeof(proftime_T)); } fp->uf_tml_idx = -1; @@ -9652,7 +9652,7 @@ void func_dump_profile(FILE *fd) return; // nothing to dump } - sorttab = xmalloc(sizeof(ufunc_T *) * todo); + sorttab = xmalloc(sizeof(ufunc_T *) * (size_t)todo); for (hi = func_hashtab.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { @@ -9859,7 +9859,7 @@ void func_line_start(void *cookie) if (fp->uf_profiling && sourcing_lnum >= 1 && sourcing_lnum <= fp->uf_lines.ga_len) { - fp->uf_tml_idx = sourcing_lnum - 1; + fp->uf_tml_idx = (int)(sourcing_lnum - 1); // Skip continuation lines. while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL) { fp->uf_tml_idx--; @@ -10270,7 +10270,7 @@ repeat: if (s > tail || (0 && is_second_e && s == tail)) { // we stopped at a '.' (so anchor to &'.' + 1) char *newstart = s + 1; - size_t distance_stepped_back = *fnamep - newstart; + size_t distance_stepped_back = (size_t)(*fnamep - newstart); *fnamelen += distance_stepped_back; *fnamep = newstart; } else if (*fnamep <= tail) { @@ -10320,12 +10320,12 @@ repeat: // find end of pattern p = vim_strchr(s, sep); if (p != NULL) { - char *const pat = xstrnsave(s, p - s); + char *const pat = xstrnsave(s, (size_t)(p - s)); s = p + 1; // find end of substitution p = vim_strchr(s, sep); if (p != NULL) { - char *const sub = xstrnsave(s, p - s); + char *const sub = xstrnsave(s, (size_t)(p - s)); char *const str = xstrnsave(*fnamep, *fnamelen); *usedlen = (size_t)(p + 1 - src); s = do_string_sub(str, pat, sub, NULL, flags); @@ -10354,7 +10354,7 @@ repeat: } p = (char *)vim_strsave_shellescape((char_u *)(*fnamep), false, false); if (c != NUL) { - (*fnamep)[*fnamelen] = c; + (*fnamep)[*fnamelen] = (char)c; } xfree(*bufp); *bufp = *fnamep = p; @@ -10599,7 +10599,7 @@ bool eval_has_provider(const char *feat) if (get_var_tv(buf, len, &tv, NULL, false, true) == FAIL) { // Trigger autoload once. len = snprintf(buf, sizeof(buf), "provider#%s#bogus", name); - script_autoload(buf, len, false); + script_autoload(buf, (size_t)len, false); // Retry the (non-autoload-style) variable. len = snprintf(buf, sizeof(buf), "g:loaded_%s_provider", name); -- cgit From 9c0f2253a5c014ba1ab7ee6e403a0b07c4e01b40 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 18 Jun 2022 18:30:54 +0200 Subject: fix(logging): try harder to resolve Nvim "name" #19016 Problem: If startup finishes (starting=false) before the logger ever happens to see a v:servername, we're stuck with the "?." fallback name forever. Solution: Drop the `starting` condition. Discard the "?." fallback after using it for the current log message. So logging will always check v:servername next time. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index fd69b5b726..a4f56b47e6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8199,7 +8199,7 @@ varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE /// Get string v: variable value. Uses a static buffer, can only be used once. /// If the String variable has never been set, return an empty string. -/// Never returns NULL; +/// Never returns NULL. char *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET { -- cgit From 9f28eddfab368697c21e6628fdf55af5ec4f4c39 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sun, 19 Jun 2022 16:08:43 +0300 Subject: fix(float): make `screen*()` functions respect floating windows Resolves #19013. --- src/nvim/eval.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a4f56b47e6..43d6ed558f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -49,6 +49,7 @@ #include "nvim/sign.h" #include "nvim/syntax.h" #include "nvim/ui.h" +#include "nvim/ui_compositor.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" @@ -6849,19 +6850,19 @@ void return_register(int regname, typval_T *rettv) rettv->vval.v_string = xstrdup(buf); } -void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col) +void screenchar_adjust(ScreenGrid **grid, int *row, int *col) { // TODO(bfredl): this is a hack for legacy tests which use screenchar() // to check printed messages on the screen (but not floats etc // as these are not legacy features). If the compositor is refactored to // have its own buffer, this should just read from it instead. msg_scroll_flush(); - if (msg_grid.chars && msg_grid.comp_index > 0 && *row >= msg_grid.comp_row - && *row < (msg_grid.rows + msg_grid.comp_row) - && *col < msg_grid.cols) { - *grid = &msg_grid; - *row -= msg_grid.comp_row; - } + + *grid = ui_comp_get_grid_at_coord(*row, *col); + + // Make `row` and `col` relative to the grid + *row -= (*grid)->comp_row; + *col -= (*grid)->comp_col; } /// Set line or list of lines in buffer "buf". -- cgit From 7718b758461265d8966468c104ce5454538471e2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Jun 2022 21:17:11 +0800 Subject: refactor: move some mapping-related code to a separate file (#19061) This marks the following Vim patches as ported: vim-patch:8.1.1785: map functionality mixed with character input Problem: Map functionality mixed with character input. Solution: Move the map functionality to a separate file. (Yegappan Lakshmanan, closes vim/vim#4740) Graduate the +localmap feature. https://github.com/vim/vim/commit/b66bab381c8ba71fd6e92327d1d34c6f8a65f2a7 vim-patch:8.2.3643: header for source file is outdated Problem: Header for source file is outdated. Solution: Make the header more accurate. (closes vim/vim#9186) https://github.com/vim/vim/commit/a3f83feb63eae5464a620ae793c002eb45f7a838 Also cherry-pick a change for mappings from patch 8.2.0807. Rename map_clear_mode() to do_mapclear(). --- src/nvim/eval.c | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 43d6ed558f..be2df9488e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6791,57 +6791,6 @@ char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) return argv; } -/// Fill a dictionary with all applicable maparg() like dictionaries -/// -/// @param dict The dictionary to be filled -/// @param mp The maphash that contains the mapping information -/// @param buffer_value The "buffer" value -/// @param compatible True for compatible with old maparg() dict -void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buffer_value, - bool compatible) - FUNC_ATTR_NONNULL_ALL -{ - char *const lhs = str2special_save((const char *)mp->m_keys, - compatible, !compatible); - char *const mapmode = map_mode_to_chars(mp->m_mode); - varnumber_T noremap_value; - - if (compatible) { - // Keep old compatible behavior - // This is unable to determine whether a mapping is a