From ebfe083337701534887ac3ea3d8e7ad47f7a206a Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 8 Jan 2022 00:39:44 +0600 Subject: feat(lua): show proper verbose output for lua configuration `:verbose` didn't work properly with lua configs (For example: options or keymaps are set from lua, just say that they were set from lua, doesn't say where they were set at. This fixes that issue. Now `:verbose` will provide filename and line no when option/keymap is set from lua. Changes: - compiles lua/vim/keymap.lua as vim/keymap.lua - When souring a lua file current_sctx.sc_sid is set to SID_LUA - Moved finding scripts SID out of `do_source()` to `get_current_script_id()`. So it can be reused for lua files. - Added new function `nlua_get_sctx` that extracts current lua scripts name and line no with debug library. And creates a sctx for it. NOTE: This function ignores C functions and blacklist which currently contains only vim/_meta.lua so vim.o/opt wrappers aren't targeted. - Added function `nlua_set_sctx` that changes provided sctx to current lua scripts sctx if a lua file is being executed. - Added tests in tests/functional/lua/verbose_spec.lua - add primary support for additional types (:autocmd, :function, :syntax) to lua verbose Note: These can't yet be directly set from lua but once that's possible :verbose should work for them hopefully :D - add :verbose support for nvim_exec & nvim_command within lua Currently auto commands/commands/functions ... can only be defined by nvim_exec/nvim_command this adds support for them. Means if those Are defined within lua with vim.cmd/nvim_exec :verbose will show their location . Though note it'll show the line no on which nvim_exec call was made. --- src/nvim/eval/userfunc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index eb241eb8ae..5764f9fbd4 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2573,6 +2573,7 @@ void ex_function(exarg_T *eap) fp->uf_calls = 0; fp->uf_script_ctx = current_sctx; fp->uf_script_ctx.sc_lnum += sourcing_lnum_top; + nlua_set_sctx(&fp->uf_script_ctx); goto ret_free; -- 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/userfunc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 5764f9fbd4..471c4092fe 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -516,7 +516,7 @@ static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf if (llen > 0) { fname_buf[0] = K_SPECIAL; fname_buf[1] = KS_EXTRA; - fname_buf[2] = (int)KE_SNR; + fname_buf[2] = KE_SNR; int i = 3; if (eval_fname_sid((const char *)name)) { // "" or "s:" if (current_sctx.sc_sid <= 0) { @@ -1713,7 +1713,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, // Check for hard coded : already translated function ID (from a user // command). if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA - && (*pp)[2] == (int)KE_SNR) { + && (*pp)[2] == KE_SNR) { *pp += 3; len = get_id_len((const char **)pp) + 3; return (char_u *)xmemdupz(start, len); @@ -1821,7 +1821,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, // Change "" to the byte sequence. name[0] = K_SPECIAL; name[1] = KS_EXTRA; - name[2] = (int)KE_SNR; + name[2] = KE_SNR; memmove(name + 3, name + 5, strlen((char *)name + 5) + 1); } goto theend; @@ -1888,7 +1888,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, if (!skip && lead > 0) { name[0] = K_SPECIAL; name[1] = KS_EXTRA; - name[2] = (int)KE_SNR; + name[2] = KE_SNR; if (sid_buf_len > 0) { // If it's "" memcpy(name + 3, sid_buf, sid_buf_len); } -- cgit From 534f5a419d2ef1c2ad78204a4de48388cc2d7fa2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 24 Mar 2022 12:17:21 +0100 Subject: refactor: convert function comments to doxygen format (#17710) --- src/nvim/eval/userfunc.c | 183 +++++++++++++++++++---------------------------- 1 file changed, 74 insertions(+), 109 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 471c4092fe..eb5c6e503a 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -201,7 +201,7 @@ static void register_closure(ufunc_T *fp) } -/// Get a name for a lambda. Returned in static memory. +/// @return a name for a lambda. Returned in static memory. char_u *get_lambda_name(void) { static char_u name[30]; @@ -544,7 +544,8 @@ static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf } /// Find a function by name, return pointer to it in ufuncs. -/// @return NULL for unknown function. +/// +/// @return NULL for unknown function. ufunc_T *find_func(const char_u *name) { hashitem_T *hi; @@ -556,11 +557,9 @@ ufunc_T *find_func(const char_u *name) return NULL; } -/* - * Copy the function name of "fp" to buffer "buf". - * "buf" must be able to hold the function name plus three bytes. - * Takes care of script-local function names. - */ +/// Copy the function name of "fp" to buffer "buf". +/// "buf" must be able to hold the function name plus three bytes. +/// Takes care of script-local function names. static void cat_func_name(char_u *buf, ufunc_T *fp) { if (fp->uf_name[0] == K_SPECIAL) { @@ -571,9 +570,7 @@ static void cat_func_name(char_u *buf, ufunc_T *fp) } } -/* - * Add a number variable "name" to dict "dp" with value "nr". - */ +/// Add a number variable "name" to dict "dp" with value "nr". static void add_nr_var(dict_T *dp, dictitem_T *v, char *name, varnumber_T nr) { #ifndef __clang_analyzer__ @@ -586,7 +583,7 @@ static void add_nr_var(dict_T *dp, dictitem_T *v, char *name, varnumber_T nr) v->di_tv.vval.v_number = nr; } -// Free "fc" +/// Free "fc" static void free_funccal(funccall_T *fc) { for (int i = 0; i < fc->fc_funcs.ga_len; i++) { @@ -606,9 +603,9 @@ static void free_funccal(funccall_T *fc) xfree(fc); } -// Free "fc" and what it contains. -// Can be called only when "fc" is kept beyond the period of it called, -// i.e. after cleanup_function_call(fc). +/// Free "fc" and what it contains. +/// Can be called only when "fc" is kept beyond the period of it called, +/// i.e. after cleanup_function_call(fc). static void free_funccal_contents(funccall_T *fc) { // Free all l: variables. @@ -757,7 +754,7 @@ static void func_clear_items(ufunc_T *fp) /// Free all things that a function contains. Does not free the function /// itself, use func_free() for that. /// -/// param[in] force When true, we are exiting. +/// @param[in] force When true, we are exiting. static void func_clear(ufunc_T *fp, bool force) { if (fp->uf_cleared) { @@ -773,7 +770,7 @@ static void func_clear(ufunc_T *fp, bool force) /// Free a function and remove it from the list of functions. Does not free /// what a function contains, call func_clear() first. /// -/// param[in] fp The function to free. +/// @param[in] fp The function to free. static void func_free(ufunc_T *fp) { // only remove it when not done already, otherwise we would remove a newer @@ -786,7 +783,7 @@ static void func_free(ufunc_T *fp) /// Free all things that a function contains and free the function itself. /// -/// param[in] force When true, we are exiting. +/// @param[in] force When true, we are exiting. static void func_clear_free(ufunc_T *fp, bool force) { func_clear(fp, force); @@ -795,13 +792,13 @@ static void func_clear_free(ufunc_T *fp, bool force) /// Call a user function /// -/// @param fp Function to call. -/// @param[in] argcount Number of arguments. -/// @param argvars Arguments. -/// @param[out] rettv Return value. -/// @param[in] firstline First line of range. -/// @param[in] lastline Last line of range. -/// @param selfdict Dictionary for "self" for dictionary functions. +/// @param fp Function to call. +/// @param[in] argcount Number of arguments. +/// @param argvars Arguments. +/// @param[out] rettv Return value. +/// @param[in] firstline First line of range. +/// @param[in] lastline Last line of range. +/// @param selfdict Dictionary for "self" for dictionary functions. void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict) FUNC_ATTR_NONNULL_ARG(1, 3, 4) @@ -1230,8 +1227,8 @@ static bool func_name_refcount(char_u *name) static funccal_entry_T *funccal_stack = NULL; -// Save the current function call pointer, and set it to NULL. -// Used when executing autocommands and for ":source". +/// Save the current function call pointer, and set it to NULL. +/// Used when executing autocommands and for ":source". void save_funccal(funccal_entry_T *entry) { entry->top_funccal = current_funccal; @@ -1384,8 +1381,8 @@ func_call_skip_call: return r; } -// Give an error message for the result of a function. -// Nothing if "error" is FCERR_NONE. +/// Give an error message for the result of a function. +/// Nothing if "error" is FCERR_NONE. static void user_func_error(int error, const char_u *name) FUNC_ATTR_NONNULL_ALL { @@ -1902,9 +1899,7 @@ theend: return name; } -/* - * ":function" - */ +/// ":function" void ex_function(exarg_T *eap) { char_u *theline; @@ -2595,11 +2590,9 @@ ret_free: } } // NOLINT(readability/fn_size) -/* - * Return 5 if "p" starts with "" or "" (ignoring case). - * Return 2 if "p" starts with "s:". - * Return 0 otherwise. - */ +/// @return 5 if "p" starts with "" or "" (ignoring case). +/// 2 if "p" starts with "s:". +/// 0 otherwise. int eval_fname_script(const char *const p) { // Use mb_strnicmp() because in Turkish comparing the "I" may not work with @@ -2625,10 +2618,10 @@ bool translated_function_exists(const char *name) /// Check whether function with the given name exists /// -/// @param[in] name Function name. -/// @param[in] no_deref Whether to dereference a Funcref. +/// @param[in] name Function name. +/// @param[in] no_deref Whether to dereference a Funcref. /// -/// @return True if it exists, false otherwise. +/// @return true if it exists, false otherwise. bool function_exists(const char *const name, bool no_deref) { const char_u *nm = (const char_u *)name; @@ -2651,10 +2644,8 @@ bool function_exists(const char *const name, bool no_deref) return n; } -/* - * Function given to ExpandGeneric() to obtain the list of user defined - * function names. - */ +/// Function given to ExpandGeneric() to obtain the list of user defined +/// function names. char_u *get_user_func_name(expand_T *xp, int idx) { static size_t done; @@ -2771,10 +2762,8 @@ void ex_delfunction(exarg_T *eap) } } -/* - * Unreference a Function: decrement the reference count and free it when it - * becomes zero. - */ +/// Unreference a Function: decrement the reference count and free it when it +/// becomes zero. void func_unref(char_u *name) { ufunc_T *fp = NULL; @@ -2868,9 +2857,7 @@ static int can_free_funccal(funccall_T *fc, int copyID) && fc->fc_copyID != copyID; } -/* - * ":return [expr]" - */ +/// ":return [expr]" void ex_return(exarg_T *eap) { char_u *arg = eap->arg; @@ -2921,9 +2908,7 @@ void ex_return(exarg_T *eap) // TODO(ZyX-I): move to eval/ex_cmds -/* - * ":1,25call func(arg1, arg2)" function call. - */ +/// ":1,25call func(arg1, arg2)" function call. void ex_call(exarg_T *eap) { char_u *arg = eap->arg; @@ -3050,14 +3035,16 @@ end: xfree(tofree); } -/* - * Return from a function. Possibly makes the return pending. Also called - * for a pending return at the ":endtry" or after returning from an extra - * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set - * when called due to a ":return" command. "rettv" may point to a typval_T - * with the return rettv. Returns TRUE when the return can be carried out, - * FALSE when the return gets pending. - */ +/// Return from a function. Possibly makes the return pending. Also called +/// for a pending return at the ":endtry" or after returning from an extra +/// do_cmdline(). "reanimate" is used in the latter case. +/// +/// @param reanimate used after returning from an extra do_cmdline(). +/// @param is_cmd set when called due to a ":return" command. +/// @param rettv may point to a typval_T with the return rettv. +/// +/// @return TRUE when the return can be carried out, +/// FALSE when the return gets pending. int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) { int idx; @@ -3068,12 +3055,10 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) current_funccal->returned = false; } - // // Cleanup (and deactivate) conditionals, but stop when a try conditional // not in its finally clause (which then is to be executed next) is found. // In this case, make the ":return" pending for execution at the ":endtry". // Otherwise, return normally. - // idx = cleanup_conditionals(eap->cstack, 0, true); if (idx >= 0) { cstack->cs_pending[idx] = CSTP_RETURN; @@ -3126,10 +3111,8 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) return idx < 0; } -/* - * Generate a return command for producing the value of "rettv". The result - * is an allocated string. Used by report_pending() for verbose messages. - */ +/// Generate a return command for producing the value of "rettv". The result +/// is an allocated string. Used by report_pending() for verbose messages. char_u *get_return_cmd(void *rettv) { char_u *s = NULL; @@ -3151,11 +3134,10 @@ char_u *get_return_cmd(void *rettv) return vim_strsave(IObuff); } -/* - * Get next function line. - * Called by do_cmdline() to get the next line. - * Returns allocated string, or NULL for end of function. - */ +/// Get next function line. +/// Called by do_cmdline() to get the next line. +/// +/// @return allocated string, or NULL for end of function. char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) { funccall_T *fcp = (funccall_T *)cookie; @@ -3206,10 +3188,8 @@ char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) return retval; } -/* - * Return TRUE if the currently active function should be ended, because a - * return was encountered or an error occurred. Used inside a ":while". - */ +/// @return TRUE if the currently active function should be ended, because a +/// return was encountered or an error occurred. Used inside a ":while". int func_has_ended(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; @@ -3220,9 +3200,7 @@ int func_has_ended(void *cookie) || fcp->returned; } -/* - * return TRUE if cookie indicates a function which "abort"s on errors. - */ +/// @return TRUE if cookie indicates a function which "abort"s on errors. int func_has_abort(void *cookie) { return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT; @@ -3289,41 +3267,31 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) } } -/* - * Return the name of the executed function. - */ +/// @return the name of the executed function. char_u *func_name(void *cookie) { return ((funccall_T *)cookie)->func->uf_name; } -/* - * Return the address holding the next breakpoint line for a funccall cookie. - */ +/// @return the address holding the next breakpoint line for a funccall cookie. linenr_T *func_breakpoint(void *cookie) { return &((funccall_T *)cookie)->breakpoint; } -/* - * Return the address holding the debug tick for a funccall cookie. - */ +/// @return the address holding the debug tick for a funccall cookie. int *func_dbg_tick(void *cookie) { return &((funccall_T *)cookie)->dbg_tick; } -/* - * Return the nesting level for a funccall cookie. - */ +/// @return the nesting level for a funccall cookie. int func_level(void *cookie) { return ((funccall_T *)cookie)->level; } -/* - * Return TRUE when a function was ended by a ":return" command. - */ +/// @return TRUE when a function was ended by a ":return" command. int current_func_returned(void) { return current_funccal->returned; @@ -3372,8 +3340,8 @@ funccall_T *get_funccal(void) return funccal; } -/// Return the hashtable used for local variables in the current funccal. -/// Return NULL if there is no current funccal. +/// @return hashtable used for local variables in the current funccal or +/// NULL if there is no current funccal. hashtab_T *get_funccal_local_ht(void) { if (current_funccal == NULL) { @@ -3382,8 +3350,8 @@ hashtab_T *get_funccal_local_ht(void) return &get_funccal()->l_vars.dv_hashtab; } -/// Return the l: scope variable. -/// Return NULL if there is no current funccal. +/// @return the l: scope variable or +/// NULL if there is no current funccal. dictitem_T *get_funccal_local_var(void) { if (current_funccal == NULL) { @@ -3392,8 +3360,8 @@ dictitem_T *get_funccal_local_var(void) return (dictitem_T *)&get_funccal()->l_vars_var; } -/// Return the hashtable used for argument in the current funccal. -/// Return NULL if there is no current funccal. +/// @return the hashtable used for argument in the current funccal or +/// NULL if there is no current funccal. hashtab_T *get_funccal_args_ht(void) { if (current_funccal == NULL) { @@ -3402,8 +3370,8 @@ hashtab_T *get_funccal_args_ht(void) return &get_funccal()->l_avars.dv_hashtab; } -/// Return the a: scope variable. -/// Return NULL if there is no current funccal. +/// @return the a: scope variable or +/// NULL if there is no current funccal. dictitem_T *get_funccal_args_var(void) { if (current_funccal == NULL) { @@ -3412,9 +3380,7 @@ dictitem_T *get_funccal_args_var(void) return (dictitem_T *)¤t_funccal->l_avars_var; } -/* - * List function variables, if there is a function. - */ +/// List function variables, if there is a function. void list_func_vars(int *first) { if (current_funccal != NULL) { @@ -3423,9 +3389,8 @@ void list_func_vars(int *first) } } -/// If "ht" is the hashtable for local variables in the current funccal, return -/// the dict that contains it. -/// Otherwise return NULL. +/// @return if "ht" is the hashtable for local variables in the current +/// funccal, return the dict that contains it. Otherwise return NULL. dict_T *get_current_funccal_dict(hashtab_T *ht) { if (current_funccal != NULL && ht == ¤t_funccal->l_vars.dv_hashtab) { @@ -3589,7 +3554,7 @@ bool set_ref_in_func_args(int copyID) /// "list_stack" is used to add lists to be marked. Can be NULL. /// "ht_stack" is used to add hashtabs to be marked. Can be NULL. /// -/// @return true if setting references failed somehow. +/// @return true if setting references failed somehow. bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) { ufunc_T *fp = fp_in; -- cgit From b6026337f25cc708e932b21a9e4e64a174a1d9da Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 9 Oct 2021 01:25:11 +0100 Subject: vim-patch:8.2.3416: second error is reported while exception is being thrown Problem: Second error is reported while exception is being thrown. Solution: Do not check for trailing characters when already aborting. (closes vim/vim#8842) https://github.com/vim/vim/commit/36f691f5f1d0676f080cc97d697d742ed5cc8251 --- src/nvim/eval/userfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index eb5c6e503a..972bd81117 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3018,7 +3018,7 @@ void ex_call(exarg_T *eap) } // When inside :try we need to check for following "| catch". - if (!failed || eap->cstack->cs_trylevel > 0) { + if (!aborting() && (!failed || eap->cstack->cs_trylevel > 0)) { // Check for trailing illegal characters and a following command. if (!ends_excmd(*arg)) { if (!failed) { -- cgit From 93c72d866b3a41c429dd9d278cda7059ebd4afba Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 9 Oct 2021 01:34:18 +0100 Subject: vim-patch:8.2.3448: :endtry after function call that throws not found Problem: :endtry after function call that throws not found. Solution: Do check for following :endtry if an exception is being thrown. (closes vim/vim#8889) https://github.com/vim/vim/commit/1d34189ecb99fa76363c06e1aa815c1075675a1c Nvim obsoleted did_throw; check current_exception is not NULL instead. --- src/nvim/eval/userfunc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 972bd81117..0fadc0d220 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3017,11 +3017,12 @@ void ex_call(exarg_T *eap) } } - // When inside :try we need to check for following "| catch". - if (!aborting() && (!failed || eap->cstack->cs_trylevel > 0)) { + // When inside :try we need to check for following "| catch" or "| endtry". + // Not when there was an error, but do check if an exception was thrown. + if ((!aborting() || current_exception != NULL) && (!failed || eap->cstack->cs_trylevel > 0)) { // Check for trailing illegal characters and a following command. if (!ends_excmd(*arg)) { - if (!failed) { + if (!failed && !aborting()) { emsg_severe = true; emsg(_(e_trailing)); } -- 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/userfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 0fadc0d220..340b731312 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2503,7 +2503,7 @@ void ex_function(exarg_T *eap) p = vim_strchr(scriptname, '/'); plen = (int)STRLEN(p); slen = (int)STRLEN(sourcing_name); - if (slen > plen && fnamecmp(p, + if (slen > plen && FNAMECMP(p, sourcing_name + slen - plen) == 0) { j = OK; } -- cgit From 909dbbbd4ba6ab1ddeb201f23db16d1062e50ca7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Mon, 25 Apr 2022 19:06:47 +0200 Subject: refactor: enable -Wconversion warning for funcs.c and userfuncs.c Work on https://github.com/neovim/neovim/issues/567 --- src/nvim/eval/userfunc.c | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 340b731312..11ca93cff9 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -70,7 +70,7 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, i bool mustend = false; char_u *arg = *argp; char_u *p = arg; - int c; + char_u c; int i; if (newargs != NULL) { @@ -265,7 +265,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) (*arg)++; if (evaluate) { - int len, flags = 0; + int flags = 0; char_u *p; garray_T newlines; @@ -278,7 +278,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) ga_grow(&newlines, 1); // Add "return " before the expression. - len = 7 + e - s + 1; + size_t len = (size_t)(7 + e - s + 1); p = (char_u *)xmalloc(len); ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p; STRCPY(p, "return "); @@ -522,16 +522,16 @@ static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf if (current_sctx.sc_sid <= 0) { *error = ERROR_SCRIPT; } else { - snprintf((char *)fname_buf + i, FLEN_FIXED + 1 - i, "%" PRId64 "_", + snprintf((char *)fname_buf + i, (size_t)(FLEN_FIXED + 1 - i), "%" PRId64 "_", (int64_t)current_sctx.sc_sid); i = (int)STRLEN(fname_buf); } } - if (i + STRLEN(name + llen) < FLEN_FIXED) { + if ((size_t)i + STRLEN(name + llen) < FLEN_FIXED) { STRCPY(fname_buf + i, name + llen); fname = fname_buf; } else { - fname = xmalloc(i + STRLEN(name + llen) + 1); + fname = xmalloc((size_t)i + STRLEN(name + llen) + 1); *tofree = fname; memmove(fname, fname_buf, (size_t)i); STRCPY(fname + i, name + llen); @@ -1422,7 +1422,7 @@ static void argv_add_base(typval_T *const basetv, typval_T **const argvars, int { if (basetv != NULL) { // Method call: base->Method() - memmove(&new_argvars[1], *argvars, sizeof(typval_T) * (*argcount)); + memmove(&new_argvars[1], *argvars, sizeof(typval_T) * (size_t)(*argcount)); new_argvars[0] = *basetv; (*argcount)++; *argvars = new_argvars; @@ -1475,7 +1475,7 @@ int call_func(const char_u *funcname, int len, typval_T *rettv, int argcount_in, if (fp == NULL) { // Make a copy of the name, if it comes from a funcref variable it could // be changed or deleted in the called function. - name = vim_strnsave(funcname, len); + name = vim_strnsave(funcname, (size_t)len); fname = fname_trans_sid(name, fname_buf, &tofree, &error); } @@ -1522,7 +1522,7 @@ int call_func(const char_u *funcname, int len, typval_T *rettv, int argcount_in, if (len > 0) { error = ERROR_NONE; argv_add_base(funcexe->basetv, &argvars, &argcount, argv, &argv_base); - nlua_typval_call((const char *)funcname, len, argvars, argcount, rettv); + nlua_typval_call((const char *)funcname, (size_t)len, argvars, argcount, rettv); } else { // v:lua was called directly; show its name in the emsg XFREE_CLEAR(name); @@ -1713,7 +1713,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, && (*pp)[2] == KE_SNR) { *pp += 3; len = get_id_len((const char **)pp) + 3; - return (char_u *)xmemdupz(start, len); + return (char_u *)xmemdupz(start, (size_t)len); } // A name starting with "" or "" is local to a script. But @@ -1766,8 +1766,8 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, semsg(e_invexpr2, "v:lua"); goto theend; } - name = xmallocz(len); - memcpy(name, end+1, len); + name = xmallocz((size_t)len); + memcpy(name, end+1, (size_t)len); *pp = (char_u *)end+1+len; } else { name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial)); @@ -1861,12 +1861,11 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, emsg(_(e_usingsid)); goto theend; } - sid_buf_len = snprintf(sid_buf, sizeof(sid_buf), - "%" PRIdSCID "_", current_sctx.sc_sid); - lead += sid_buf_len; + sid_buf_len = + (size_t)snprintf(sid_buf, sizeof(sid_buf), "%" PRIdSCID "_", current_sctx.sc_sid); + lead += (int)sid_buf_len; } - } else if (!(flags & TFN_INT) - && builtin_function(lv.ll_name, lv.ll_name_len)) { + } else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, (int)lv.ll_name_len)) { semsg(_("E128: Function name must start with a capital or \"s:\": %s"), start); goto theend; @@ -1881,7 +1880,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, } } - name = xmalloc(len + lead + 1); + name = xmalloc((size_t)len + (size_t)lead + 1); if (!skip && lead > 0) { name[0] = K_SPECIAL; name[1] = KS_EXTRA; @@ -1890,7 +1889,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, memcpy(name + 3, sid_buf, sid_buf_len); } } - memmove(name + lead, lv.ll_name, len); + memmove(name + lead, lv.ll_name, (size_t)len); name[lead + len] = NUL; *pp = (char_u *)end; @@ -1904,7 +1903,7 @@ void ex_function(exarg_T *eap) { char_u *theline; char_u *line_to_free = NULL; - int c; + char_u c; int saved_did_emsg; bool saved_wait_return = need_wait_return; char_u *name = NULL; @@ -2387,9 +2386,9 @@ void ex_function(exarg_T *eap) // Ignore leading white space. p = skipwhite(p + 4); heredoc_trimmed = - vim_strnsave(theline, skipwhite(theline) - theline); + vim_strnsave(theline, (size_t)(skipwhite(theline) - theline)); } - skip_until = vim_strnsave(p, skiptowhite(p) - p); + skip_until = vim_strnsave(p, (size_t)(skiptowhite(p) - p)); do_concat = false; is_heredoc = true; } @@ -2397,7 +2396,7 @@ void ex_function(exarg_T *eap) } // Add the line to the function. - ga_grow(&newlines, 1 + sourcing_lnum_off); + ga_grow(&newlines, 1 + (int)sourcing_lnum_off); // Copy the line to newly allocated memory. get_one_sourceline() // allocates 250 bytes per line, this saves 80% on average. The cost @@ -3254,7 +3253,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) func_ptr_ref(pt->pt_func); } if (ret_pt->pt_argc > 0) { - size_t arg_size = sizeof(typval_T) * ret_pt->pt_argc; + size_t arg_size = sizeof(typval_T) * (size_t)ret_pt->pt_argc; pt->pt_argv = (typval_T *)xmalloc(arg_size); pt->pt_argc = ret_pt->pt_argc; for (i = 0; i < pt->pt_argc; i++) { @@ -3417,7 +3416,7 @@ hashitem_T *find_hi_in_scoped_ht(const char *name, hashtab_T **pht) while (current_funccal != NULL) { hashtab_T *ht = find_var_ht(name, namelen, &varname); if (ht != NULL && *varname != NUL) { - hi = hash_find_len(ht, varname, namelen - (varname - name)); + hi = hash_find_len(ht, varname, namelen - (size_t)(varname - name)); if (!HASHITEM_EMPTY(hi)) { *pht = ht; break; -- 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/userfunc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 11ca93cff9..5a63bbf631 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1761,14 +1761,14 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, } else if (lv.ll_tv->v_type == VAR_PARTIAL && lv.ll_tv->vval.v_partial != NULL) { if (is_luafunc(lv.ll_tv->vval.v_partial) && *end == '.') { - len = check_luafunc_name((const char *)end+1, true); + len = check_luafunc_name((const char *)end + 1, true); if (len == 0) { semsg(e_invexpr2, "v:lua"); goto theend; } name = xmallocz((size_t)len); - memcpy(name, end+1, (size_t)len); - *pp = (char_u *)end+1+len; + memcpy(name, end + 1, (size_t)len); + *pp = (char_u *)end + 1 + len; } else { name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial)); *pp = (char_u *)end; @@ -2269,8 +2269,7 @@ void ex_function(exarg_T *eap) } } else { // skip ':' and blanks - for (p = theline; ascii_iswhite(*p) || *p == ':'; p++) { - } + for (p = theline; ascii_iswhite(*p) || *p == ':'; p++) {} // Check for "endfunction". if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { -- 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/userfunc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 5a63bbf631..8b47468aad 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2272,7 +2272,7 @@ void ex_function(exarg_T *eap) for (p = theline; ascii_iswhite(*p) || *p == ':'; p++) {} // Check for "endfunction". - if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { + if (checkforcmd((char **)&p, "endfunction", 4) && nesting-- == 0) { if (*p == '!') { p++; } @@ -2311,7 +2311,7 @@ void ex_function(exarg_T *eap) } // Check for defining a function inside this function. - if (checkforcmd(&p, "function", 2)) { + if (checkforcmd((char **)&p, "function", 2)) { if (*p == '!') { p = skipwhite(p + 1); } @@ -2324,7 +2324,7 @@ void ex_function(exarg_T *eap) } // Check for ":append", ":change", ":insert". - p = skip_range(p, NULL); + p = (char_u *)skip_range((char *)p, NULL); if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'c' && (!ASCII_ISALPHA(p[1]) -- 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/userfunc.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 8b47468aad..0a35e6655f 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -132,7 +132,7 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, i p = skipwhite(p) + 1; p = skipwhite(p); char_u *expr = p; - if (eval1(&p, &rettv, false) != FAIL) { + if (eval1((char **)&p, &rettv, false) != FAIL) { ga_grow(default_args, 1); // trim trailing whitespace @@ -253,7 +253,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) // Get the start and the end of the expression. *arg = skipwhite(*arg + 1); s = *arg; - ret = skip_expr(arg); + ret = skip_expr((char **)arg); if (ret == FAIL) { goto errret; } @@ -372,7 +372,7 @@ char_u *deref_func_name(const char *name, int *lenp, partial_T **const partialp, if (partialp != NULL) { *partialp = pt; } - char_u *s = partial_name(pt); + char_u *s = (char_u *)partial_name(pt); *lenp = (int)STRLEN(s); return s; } @@ -426,7 +426,7 @@ int get_func_tv(const char_u *name, int len, typval_T *rettv, char_u **arg, func if (*argp == ')' || *argp == ',' || *argp == NUL) { break; } - if (eval1(&argp, &argvars[argcount], funcexe->evaluate) == FAIL) { + if (eval1((char **)&argp, &argvars[argcount], funcexe->evaluate) == FAIL) { ret = FAIL; break; } @@ -941,7 +941,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett default_expr = ((char_u **)(fp->uf_def_args.ga_data)) [ai + fp->uf_def_args.ga_len]; - if (eval1(&default_expr, &def_rettv, true) == FAIL) { + if (eval1((char **)&default_expr, &def_rettv, true) == FAIL) { default_arg_err = true; break; } @@ -1103,7 +1103,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett // A Lambda always has the command "return {expr}". It is much faster // to evaluate {expr} directly. ex_nesting_level++; - (void)eval1(&p, rettv, true); + (void)eval1((char **)&p, rettv, true); ex_nesting_level--; } else { // call do_cmdline() to execute the lines @@ -1150,18 +1150,18 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett smsg(_("%s returning #%" PRId64 ""), sourcing_name, (int64_t)fc->rettv->vval.v_number); } else { - char_u buf[MSG_BUF_LEN]; + char buf[MSG_BUF_LEN]; // The value may be very long. Skip the middle part, so that we // have some idea how it starts and ends. smsg() would always // truncate it at the end. Don't want errors such as E724 here. emsg_off++; - char_u *s = (char_u *)encode_tv2string(fc->rettv, NULL); - char_u *tofree = s; + char *s = encode_tv2string(fc->rettv, NULL); + char *tofree = s; emsg_off--; if (s != NULL) { - if (vim_strsize(s) > MSG_BUF_CLEN) { - trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); + if (vim_strsize((char_u *)s) > MSG_BUF_CLEN) { + trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, MSG_BUF_LEN); s = buf; } smsg(_("%s returning %s"), sourcing_name, s); @@ -1724,8 +1724,8 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, } // Note that TFN_ flags use the same values as GLV_ flags. - end = get_lval((char_u *)start, NULL, &lv, false, skip, flags | GLV_READ_ONLY, - lead > 2 ? 0 : FNE_CHECK_START); + end = (char_u *)get_lval((char *)start, NULL, &lv, false, skip, flags | GLV_READ_ONLY, + lead > 2 ? 0 : FNE_CHECK_START); if (end == start) { if (!skip) { emsg(_("E129: Function name required")); @@ -1743,7 +1743,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, semsg(_(e_invarg2), start); } } else { - *pp = (char_u *)find_name_end(start, NULL, NULL, FNE_INCL_BR); + *pp = (char_u *)find_name_end((char *)start, NULL, NULL, FNE_INCL_BR); } goto theend; } @@ -1751,7 +1751,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, if (lv.ll_tv != NULL) { if (fdp != NULL) { fdp->fd_dict = lv.ll_dict; - fdp->fd_newkey = lv.ll_newkey; + fdp->fd_newkey = (char_u *)lv.ll_newkey; lv.ll_newkey = NULL; fdp->fd_di = lv.ll_di; } @@ -1770,7 +1770,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, memcpy(name, end + 1, (size_t)len); *pp = (char_u *)end + 1 + len; } else { - name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial)); + name = vim_strsave((char_u *)partial_name(lv.ll_tv->vval.v_partial)); *pp = (char_u *)end; } if (partial != NULL) { @@ -2873,7 +2873,7 @@ void ex_return(exarg_T *eap) eap->nextcmd = NULL; if ((*arg != NUL && *arg != '|' && *arg != '\n') - && eval0(arg, &rettv, &eap->nextcmd, !eap->skip) != FAIL) { + && eval0((char *)arg, &rettv, (char **)&eap->nextcmd, !eap->skip) != FAIL) { if (!eap->skip) { returning = do_return(eap, false, true, &rettv); } else { @@ -2926,7 +2926,7 @@ void ex_call(exarg_T *eap) // instead to skip to any following command, e.g. for: // :if 0 | call dict.foo().bar() | endif. emsg_skip++; - if (eval0(eap->arg, &rettv, &eap->nextcmd, false) != FAIL) { + if (eval0((char *)eap->arg, &rettv, (char **)&eap->nextcmd, false) != FAIL) { tv_clear(&rettv); } emsg_skip--; @@ -2995,7 +2995,7 @@ void ex_call(exarg_T *eap) // Handle a function returning a Funcref, Dictionary or List. if (handle_subscript((const char **)&arg, &rettv, true, true, - (const char_u *)name, (const char_u **)&name) + (const char *)name, (const char **)&name) == FAIL) { failed = true; break; -- 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/userfunc.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 0a35e6655f..fe8325760c 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1953,7 +1953,7 @@ void ex_function(exarg_T *eap) } } } - eap->nextcmd = check_nextcmd(eap->arg); + eap->nextcmd = (char *)check_nextcmd((char_u *)eap->arg); return; } @@ -1961,13 +1961,13 @@ void ex_function(exarg_T *eap) * ":function /pat": list functions matching pattern. */ if (*eap->arg == '/') { - p = skip_regexp(eap->arg + 1, '/', TRUE, NULL); + p = skip_regexp((char_u *)eap->arg + 1, '/', true, NULL); if (!eap->skip) { regmatch_T regmatch; c = *p; *p = NUL; - regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC); + regmatch.regprog = vim_regcomp((char_u *)eap->arg + 1, RE_MAGIC); *p = c; if (regmatch.regprog != NULL) { regmatch.rm_ic = p_ic; @@ -1989,7 +1989,7 @@ void ex_function(exarg_T *eap) if (*p == '/') { ++p; } - eap->nextcmd = check_nextcmd(p); + eap->nextcmd = (char *)check_nextcmd(p); return; } @@ -2007,7 +2007,7 @@ void ex_function(exarg_T *eap) // "fudi.fd_di" set, "fudi.fd_newkey" == NULL // s:func script-local function name // g:func global function name, same as "func" - p = eap->arg; + p = (char_u *)eap->arg; name = trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL); paren = (vim_strchr(p, '(') != NULL); if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) { @@ -2043,7 +2043,7 @@ void ex_function(exarg_T *eap) emsg(_(e_trailing)); goto ret_free; } - eap->nextcmd = check_nextcmd(p); + eap->nextcmd = (char *)check_nextcmd(p); if (eap->nextcmd != NULL) { *p = NUL; } @@ -2289,10 +2289,10 @@ void ex_function(exarg_T *eap) // Another command follows. If the line came from "eap" we // can simply point into it, otherwise we need to change // "eap->cmdlinep". - eap->nextcmd = nextcmd; + eap->nextcmd = (char *)nextcmd; if (line_to_free != NULL) { xfree(*eap->cmdlinep); - *eap->cmdlinep = line_to_free; + *eap->cmdlinep = (char *)line_to_free; line_to_free = NULL; } } @@ -2693,7 +2693,7 @@ void ex_delfunction(exarg_T *eap) char_u *name; funcdict_T fudi; - p = eap->arg; + p = (char_u *)eap->arg; name = trans_function_name(&p, eap->skip, 0, &fudi, NULL); xfree(fudi.fd_newkey); if (name == NULL) { @@ -2707,7 +2707,7 @@ void ex_delfunction(exarg_T *eap) emsg(_(e_trailing)); return; } - eap->nextcmd = check_nextcmd(p); + eap->nextcmd = (char *)check_nextcmd(p); if (eap->nextcmd != NULL) { *p = NUL; } @@ -2858,7 +2858,7 @@ static int can_free_funccal(funccall_T *fc, int copyID) /// ":return [expr]" void ex_return(exarg_T *eap) { - char_u *arg = eap->arg; + char_u *arg = (char_u *)eap->arg; typval_T rettv; int returning = FALSE; @@ -2873,7 +2873,7 @@ void ex_return(exarg_T *eap) eap->nextcmd = NULL; if ((*arg != NUL && *arg != '|' && *arg != '\n') - && eval0((char *)arg, &rettv, (char **)&eap->nextcmd, !eap->skip) != FAIL) { + && eval0((char *)arg, &rettv, &eap->nextcmd, !eap->skip) != FAIL) { if (!eap->skip) { returning = do_return(eap, false, true, &rettv); } else { @@ -2896,7 +2896,7 @@ void ex_return(exarg_T *eap) if (returning) { eap->nextcmd = NULL; } else if (eap->nextcmd == NULL) { // no argument - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = (char *)check_nextcmd(arg); } if (eap->skip) { @@ -2909,7 +2909,7 @@ void ex_return(exarg_T *eap) /// ":1,25call func(arg1, arg2)" function call. void ex_call(exarg_T *eap) { - char_u *arg = eap->arg; + char_u *arg = (char_u *)eap->arg; char_u *startarg; char_u *name; char_u *tofree; @@ -2926,7 +2926,7 @@ void ex_call(exarg_T *eap) // instead to skip to any following command, e.g. for: // :if 0 | call dict.foo().bar() | endif. emsg_skip++; - if (eval0((char *)eap->arg, &rettv, (char **)&eap->nextcmd, false) != FAIL) { + if (eval0(eap->arg, &rettv, &eap->nextcmd, false) != FAIL) { tv_clear(&rettv); } emsg_skip--; @@ -3025,7 +3025,7 @@ void ex_call(exarg_T *eap) emsg(_(e_trailing)); } } else { - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = (char *)check_nextcmd(arg); } } -- 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/userfunc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index fe8325760c..2dd022630a 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -359,7 +359,7 @@ char_u *deref_func_name(const char *name, int *lenp, partial_T **const partialp, return (char_u *)""; } *lenp = (int)STRLEN(v->di_tv.vval.v_string); - return v->di_tv.vval.v_string; + return (char_u *)v->di_tv.vval.v_string; } if (v != NULL && v->di_tv.v_type == VAR_PARTIAL) { @@ -1756,7 +1756,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, fdp->fd_di = lv.ll_di; } if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL) { - name = vim_strsave(lv.ll_tv->vval.v_string); + name = vim_strsave((char_u *)lv.ll_tv->vval.v_string); *pp = (char_u *)end; } else if (lv.ll_tv->v_type == VAR_PARTIAL && lv.ll_tv->vval.v_partial != NULL) { @@ -2530,7 +2530,7 @@ void ex_function(exarg_T *eap) tv_clear(&fudi.fd_di->di_tv); } fudi.fd_di->di_tv.v_type = VAR_FUNC; - fudi.fd_di->di_tv.vval.v_string = vim_strsave(name); + fudi.fd_di->di_tv.vval.v_string = (char *)vim_strsave(name); // behave like "dict" was used flags |= FC_DICT; @@ -3219,7 +3219,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) fp = rettv->vval.v_partial->pt_func; } else { fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING - ? rettv->vval.v_string + ? (char_u *)rettv->vval.v_string : rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. fname = fname_trans_sid(fname, fname_buf, &tofree, &error); @@ -3236,7 +3236,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) pt->pt_auto = true; if (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING) { // Just a function: Take over the function name and use selfdict. - pt->pt_name = rettv->vval.v_string; + pt->pt_name = (char_u *)rettv->vval.v_string; } else { partial_T *ret_pt = rettv->vval.v_partial; int i; -- cgit From d0897243f6a6bb802fc9622486afd69eb65fa6d5 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 6 May 2022 17:40:52 +0200 Subject: build(clint): remove "function size is too large" warning This warning is essentially only triggered for ported vim functions. It's unlikely that we'll refactor vim functions solely based on their size since it'd mean we'd greatly deviate from vim, which is a high cost when it comes to importing the vim patches. Thus, this warning only serves as an annoyance and should be removed. --- src/nvim/eval/userfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 2dd022630a..c518b11a65 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2586,7 +2586,7 @@ ret_free: if (show_block) { ui_ext_cmdline_block_leave(); } -} // NOLINT(readability/fn_size) +} /// @return 5 if "p" starts with "" or "" (ignoring case). /// 2 if "p" starts with "s:". -- 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/userfunc.c | 74 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index c518b11a65..d6a63993c6 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -125,12 +125,12 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, i *p = c; } - if (*skipwhite(p) == '=' && default_args != NULL) { + if (*skipwhite((char *)p) == '=' && default_args != NULL) { typval_T rettv; any_default = true; - p = skipwhite(p) + 1; - p = skipwhite(p); + p = (char_u *)skipwhite((char *)p) + 1; + p = (char_u *)skipwhite((char *)p); char_u *expr = p; if (eval1((char **)&p, &rettv, false) != FAIL) { ga_grow(default_args, 1); @@ -159,7 +159,7 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, i mustend = true; } } - p = skipwhite(p); + p = (char_u *)skipwhite((char *)p); if (mustend && *p != endchar) { if (!skip) { semsg(_(e_invarg2), *argp); @@ -222,7 +222,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) partial_T *pt = NULL; int varargs; int ret; - char_u *start = skipwhite(*arg + 1); + char_u *start = (char_u *)skipwhite((char *)(*arg) + 1); char_u *s, *e; bool *old_eval_lavars = eval_lavars_used; bool eval_lavars = false; @@ -239,7 +239,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) } else { pnewargs = NULL; } - *arg = skipwhite(*arg + 1); + *arg = (char_u *)skipwhite((char *)(*arg) + 1); ret = get_function_args(arg, '-', pnewargs, &varargs, NULL, false); if (ret == FAIL || **arg != '>') { goto errret; @@ -251,14 +251,14 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) } // Get the start and the end of the expression. - *arg = skipwhite(*arg + 1); + *arg = (char_u *)skipwhite((char *)(*arg) + 1); s = *arg; ret = skip_expr((char **)arg); if (ret == FAIL) { goto errret; } e = *arg; - *arg = skipwhite(*arg); + *arg = (char_u *)skipwhite((char *)(*arg)); if (**arg != '}') { goto errret; } @@ -422,7 +422,7 @@ int get_func_tv(const char_u *name, int len, typval_T *rettv, char_u **arg, func argp = *arg; while (argcount < MAX_FUNC_ARGS - (funcexe->partial == NULL ? 0 : funcexe->partial->pt_argc)) { - argp = skipwhite(argp + 1); // skip the '(' or ',' + argp = (char_u *)skipwhite((char *)argp + 1); // skip the '(' or ',' if (*argp == ')' || *argp == ',' || *argp == NUL) { break; } @@ -455,7 +455,7 @@ int get_func_tv(const char_u *name, int len, typval_T *rettv, char_u **arg, func ((typval_T **)funcargs.ga_data)[funcargs.ga_len++] = &argvars[i]; } } - ret = call_func(name, len, rettv, argcount, argvars, funcexe); + ret = call_func((char *)name, len, rettv, argcount, argvars, funcexe); funcargs.ga_len -= i; } else if (!aborting()) { @@ -470,7 +470,7 @@ int get_func_tv(const char_u *name, int len, typval_T *rettv, char_u **arg, func tv_clear(&argvars[argcount]); } - *arg = skipwhite(argp); + *arg = (char_u *)skipwhite((char *)argp); return ret; } @@ -1370,7 +1370,7 @@ int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict funcexe.evaluate = true; funcexe.partial = partial; funcexe.selfdict = selfdict; - r = call_func(name, -1, rettv, argc, argv, &funcexe); + r = call_func((char *)name, -1, rettv, argc, argv, &funcexe); func_call_skip_call: // Free the arguments. @@ -1442,8 +1442,8 @@ static void argv_add_base(typval_T *const basetv, typval_T **const argvars, int /// @return FAIL if function cannot be called, else OK (even if an error /// occurred while executing the function! Set `msg_list` to capture /// the error, see do_cmdline()). -int call_func(const char_u *funcname, int len, typval_T *rettv, int argcount_in, - typval_T *argvars_in, funcexe_T *funcexe) +int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, typval_T *argvars_in, + funcexe_T *funcexe) FUNC_ATTR_NONNULL_ARG(1, 3, 5, 6) { int ret = FAIL; @@ -1475,7 +1475,7 @@ int call_func(const char_u *funcname, int len, typval_T *rettv, int argcount_in, if (fp == NULL) { // Make a copy of the name, if it comes from a funcref variable it could // be changed or deleted in the called function. - name = vim_strnsave(funcname, (size_t)len); + name = vim_strnsave((char_u *)funcname, (size_t)len); fname = fname_trans_sid(name, fname_buf, &tofree, &error); } @@ -1522,11 +1522,11 @@ int call_func(const char_u *funcname, int len, typval_T *rettv, int argcount_in, if (len > 0) { error = ERROR_NONE; argv_add_base(funcexe->basetv, &argvars, &argcount, argv, &argv_base); - nlua_typval_call((const char *)funcname, (size_t)len, argvars, argcount, rettv); + nlua_typval_call(funcname, (size_t)len, argvars, argcount, rettv); } else { // v:lua was called directly; show its name in the emsg XFREE_CLEAR(name); - funcname = (const char_u *)"v:lua"; + funcname = "v:lua"; } } else if (fp != NULL || !builtin_function((const char *)rfname, -1)) { // User defined function. @@ -1608,7 +1608,7 @@ theend: // Report an error unless the argument evaluation or function call has been // cancelled due to an aborting error, an interrupt, or an exception. if (!aborting()) { - user_func_error(error, (name != NULL) ? name : funcname); + user_func_error(error, (name != NULL) ? name : (char_u *)funcname); } // clear the copies made from the partial @@ -2039,7 +2039,7 @@ void ex_function(exarg_T *eap) // - exclude line numbers from function body // if (!paren) { - if (!ends_excmd(*skipwhite(p))) { + if (!ends_excmd(*skipwhite((char *)p))) { emsg(_(e_trailing)); goto ret_free; } @@ -2083,7 +2083,7 @@ void ex_function(exarg_T *eap) /* * ":function name(arg1, arg2)" Define function. */ - p = skipwhite(p); + p = (char_u *)skipwhite((char *)p); if (*p != '(') { if (!eap->skip) { semsg(_("E124: Missing '(': %s"), eap->arg); @@ -2094,7 +2094,7 @@ void ex_function(exarg_T *eap) p = vim_strchr(p, '('); } } - p = skipwhite(p + 1); + p = (char_u *)skipwhite((char *)p + 1); ga_init(&newargs, (int)sizeof(char_u *), 3); ga_init(&newlines, (int)sizeof(char_u *), 3); @@ -2135,7 +2135,7 @@ void ex_function(exarg_T *eap) // find extra arguments "range", "dict", "abort" and "closure" for (;;) { - p = skipwhite(p); + p = (char_u *)skipwhite((char *)p); if (STRNCMP(p, "range", 5) == 0) { flags |= FC_RANGE; p += 5; @@ -2249,13 +2249,13 @@ void ex_function(exarg_T *eap) // * ":python < 0) { give_warning2((char_u *)_("W22: Text found after :endfunction: %s"), @@ -2313,11 +2313,11 @@ void ex_function(exarg_T *eap) // Check for defining a function inside this function. if (checkforcmd((char **)&p, "function", 2)) { if (*p == '!') { - p = skipwhite(p + 1); + p = (char_u *)skipwhite((char *)p + 1); } p += eval_fname_script((const char *)p); xfree(trans_function_name(&p, true, 0, NULL, NULL)); - if (*skipwhite(p) == '(') { + if (*skipwhite((char *)p) == '(') { nesting++; indent += 2; } @@ -2340,7 +2340,7 @@ void ex_function(exarg_T *eap) } // heredoc: Check for ":python < 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/userfunc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index d6a63993c6..c6b6a8ead9 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -994,7 +994,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett // Don't redraw while executing the function. RedrawingDisabled++; - save_sourcing_name = sourcing_name; + save_sourcing_name = (char_u *)sourcing_name; save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 1; @@ -1014,7 +1014,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett { if (save_sourcing_name != NULL && STRNCMP(save_sourcing_name, "function ", 9) == 0) { - vim_snprintf((char *)sourcing_name, + vim_snprintf(sourcing_name, len, "%s[%" PRId64 "]..", save_sourcing_name, @@ -1022,7 +1022,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett } else { STRCPY(sourcing_name, "function "); } - cat_func_name(sourcing_name + STRLEN(sourcing_name), fp); + cat_func_name((char_u *)sourcing_name + STRLEN(sourcing_name), fp); if (p_verbose >= 12) { ++no_wait_return; @@ -1175,7 +1175,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett } xfree(sourcing_name); - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; sourcing_lnum = save_sourcing_lnum; current_sctx = save_current_sctx; if (do_profiling_yes) { @@ -2219,7 +2219,7 @@ void ex_function(exarg_T *eap) if (eap->getline == NULL) { theline = getcmdline(':', 0L, indent, do_concat); } else { - theline = eap->getline(':', eap->cookie, indent, do_concat); + theline = (char_u *)eap->getline(':', eap->cookie, indent, do_concat); } line_to_free = theline; } @@ -2644,7 +2644,7 @@ bool function_exists(const char *const name, bool no_deref) /// Function given to ExpandGeneric() to obtain the list of user defined /// function names. -char_u *get_user_func_name(expand_T *xp, int idx) +char *get_user_func_name(expand_T *xp, int idx) { static size_t done; static hashitem_T *hi; @@ -2666,11 +2666,11 @@ char_u *get_user_func_name(expand_T *xp, int idx) if ((fp->uf_flags & FC_DICT) || STRNCMP(fp->uf_name, "", 8) == 0) { - return (char_u *)""; // don't show dict and lambda functions + return ""; // don't show dict and lambda functions } if (STRLEN(fp->uf_name) + 4 >= IOSIZE) { - return fp->uf_name; // Prevent overflow. + return (char *)fp->uf_name; // Prevent overflow. } cat_func_name(IObuff, fp); @@ -2680,7 +2680,7 @@ char_u *get_user_func_name(expand_T *xp, int idx) STRCAT(IObuff, ")"); } } - return IObuff; + return (char *)IObuff; } return NULL; } @@ -3137,7 +3137,7 @@ char_u *get_return_cmd(void *rettv) /// Called by do_cmdline() to get the next line. /// /// @return allocated string, or NULL for end of function. -char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) +char *get_func_line(int c, void *cookie, int indent, bool do_concat) { funccall_T *fcp = (funccall_T *)cookie; ufunc_T *fp = fcp->func; @@ -3184,7 +3184,7 @@ char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) fcp->dbg_tick = debug_tick; } - return retval; + return (char *)retval; } /// @return TRUE if the currently active function should be ended, because a -- 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/userfunc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index c6b6a8ead9..e5f48501f7 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1536,7 +1536,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t // Trigger FuncUndefined event, may load the function. if (fp == NULL - && apply_autocmds(EVENT_FUNCUNDEFINED, rfname, rfname, true, NULL) + && apply_autocmds(EVENT_FUNCUNDEFINED, (char *)rfname, (char *)rfname, true, NULL) && !aborting()) { // executed an autocommand, search for the function again fp = find_func(rfname); @@ -1967,7 +1967,7 @@ void ex_function(exarg_T *eap) c = *p; *p = NUL; - regmatch.regprog = vim_regcomp((char_u *)eap->arg + 1, RE_MAGIC); + regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC); *p = c; if (regmatch.regprog != NULL) { regmatch.rm_ic = p_ic; @@ -2009,7 +2009,7 @@ void ex_function(exarg_T *eap) // g:func global function name, same as "func" p = (char_u *)eap->arg; name = trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL); - paren = (vim_strchr(p, '(') != NULL); + paren = (vim_strchr((char *)p, '(') != NULL); if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) { /* * Return on an invalid expression in braces, unless the expression @@ -2090,8 +2090,8 @@ void ex_function(exarg_T *eap) goto ret_free; } // attempt to continue by skipping some text - if (vim_strchr(p, '(') != NULL) { - p = vim_strchr(p, '('); + if (vim_strchr((char *)p, '(') != NULL) { + p = (char_u *)vim_strchr((char *)p, '('); } } p = (char_u *)skipwhite((char *)p + 1); @@ -2207,7 +2207,7 @@ void ex_function(exarg_T *eap) if (line_arg != NULL) { // Use eap->arg, split up in parts by line breaks. theline = line_arg; - p = vim_strchr(theline, '\n'); + p = (char_u *)vim_strchr((char *)theline, '\n'); if (p == NULL) { line_arg += STRLEN(line_arg); } else { @@ -2369,7 +2369,7 @@ void ex_function(exarg_T *eap) // and ":let [a, b] =<< [trim] EOF" arg = (char_u *)skipwhite((char *)skiptowhite(p)); if (*arg == '[') { - arg = vim_strchr(arg, ']'); + arg = (char_u *)vim_strchr((char *)arg, ']'); } if (arg != NULL) { arg = (char_u *)skipwhite((char *)skiptowhite(arg)); @@ -2490,7 +2490,7 @@ void ex_function(exarg_T *eap) } if (fp == NULL) { - if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL) { + if (fudi.fd_dict == NULL && vim_strchr((char *)name, AUTOLOAD_CHAR) != NULL) { int slen, plen; char_u *scriptname; @@ -2498,7 +2498,7 @@ void ex_function(exarg_T *eap) int j = FAIL; if (sourcing_name != NULL) { scriptname = (char_u *)autoload_name((const char *)name, STRLEN(name)); - p = vim_strchr(scriptname, '/'); + p = (char_u *)vim_strchr((char *)scriptname, '/'); plen = (int)STRLEN(p); slen = (int)STRLEN(sourcing_name); if (slen > plen && FNAMECMP(p, -- cgit From 6954c0ba0dd6dfeed7067c7a06c163bd958e3d10 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 19 May 2022 22:08:20 -0400 Subject: ci(coverity): annotate register_cfunc as leaking memory register_cfunc allocates a ufunc_T, but doesn't store the pointer anywhere before returning. The uf_name member variable is stored in a hashtable and used to lookup the ufunc_T later, but that's too much for Coverity to track. Adding the annotation ensures that any new callers to register_cfunc don't pop up as new "leaks" in the Coverity scans. --- src/nvim/eval/userfunc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index e5f48501f7..2059d423d5 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3598,5 +3598,6 @@ char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state) STRCPY(fp->uf_name, name); hash_add(&func_hashtab, UF2HIKEY(fp)); + // coverity[leaked_storage] return fp->uf_name; } -- 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/userfunc.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 2059d423d5..9938dc5012 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -200,7 +200,6 @@ static void register_closure(ufunc_T *fp) [current_funccal->fc_funcs.ga_len++] = fp; } - /// @return a name for a lambda. Returned in static memory. char_u *get_lambda_name(void) { -- cgit From 014a88799a1d175ad121c520c9cc5bd0bb2d8813 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:31:54 +0200 Subject: refactor: replace char_u #18429 Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval/userfunc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 9938dc5012..8646520ec3 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1044,9 +1044,8 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett if (tofree != NULL) { char *s = tofree; char buf[MSG_BUF_LEN]; - if (vim_strsize((char_u *)s) > MSG_BUF_CLEN) { - trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, - sizeof(buf)); + if (vim_strsize(s) > MSG_BUF_CLEN) { + trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, sizeof(buf)); s = buf; } msg_puts(s); @@ -1159,7 +1158,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett char *tofree = s; emsg_off--; if (s != NULL) { - if (vim_strsize((char_u *)s) > MSG_BUF_CLEN) { + if (vim_strsize(s) > MSG_BUF_CLEN) { trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, MSG_BUF_LEN); s = buf; } -- cgit From 3b8804571c565a91c9ce729bb487c7ba21b659e0 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 28 Jun 2022 13:03:09 +0200 Subject: refactor: replace char_u Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/eval/userfunc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/nvim/eval/userfunc.c') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 8646520ec3..c2579944e4 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -547,9 +547,7 @@ static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf /// @return NULL for unknown function. ufunc_T *find_func(const char_u *name) { - hashitem_T *hi; - - hi = hash_find(&func_hashtab, name); + hashitem_T *hi = hash_find(&func_hashtab, (char *)name); if (!HASHITEM_EMPTY(hi)) { return HI2UF(hi); } @@ -724,7 +722,7 @@ static void funccal_unref(funccall_T *fc, ufunc_T *fp, bool force) /// @return true if the entry was deleted, false if it wasn't found. static bool func_remove(ufunc_T *fp) { - hashitem_T *hi = hash_find(&func_hashtab, UF2HIKEY(fp)); + hashitem_T *hi = hash_find(&func_hashtab, (char *)UF2HIKEY(fp)); if (!HASHITEM_EMPTY(hi)) { hash_remove(&func_hashtab, hi); @@ -1045,7 +1043,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett char *s = tofree; char buf[MSG_BUF_LEN]; if (vim_strsize(s) > MSG_BUF_CLEN) { - trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, sizeof(buf)); + trunc_string(s, buf, MSG_BUF_CLEN, sizeof(buf)); s = buf; } msg_puts(s); @@ -1159,7 +1157,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett emsg_off--; if (s != NULL) { if (vim_strsize(s) > MSG_BUF_CLEN) { - trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, MSG_BUF_LEN); + trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); s = buf; } smsg(_("%s returning %s"), sourcing_name, s); @@ -1976,7 +1974,7 @@ void ex_function(exarg_T *eap) --todo; fp = HI2UF(hi); if (!isdigit(*fp->uf_name) - && vim_regexec(®match, fp->uf_name, 0)) { + && vim_regexec(®match, (char *)fp->uf_name, 0)) { list_func_head(fp, false, false); } } @@ -2537,7 +2535,7 @@ void ex_function(exarg_T *eap) // insert the new function in the function list STRCPY(fp->uf_name, name); if (overwrite) { - hi = hash_find(&func_hashtab, name); + hi = hash_find(&func_hashtab, (char *)name); hi->hi_key = UF2HIKEY(fp); } else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL) { xfree(fp); -- cgit