aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/userfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/eval/userfunc.c')
-rw-r--r--src/nvim/eval/userfunc.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 41dc7d5e61..1d27826e7a 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -84,7 +84,7 @@ hashtab_T *func_tbl_get(void)
}
/// Get function arguments.
-static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int *varargs,
+static int get_function_args(char **argp, char endchar, garray_T *newargs, int *varargs,
garray_T *default_args, bool skip)
{
bool mustend = false;
@@ -106,7 +106,7 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int
// Isolate the arguments: "arg1, arg2, ...)"
bool any_default = false;
- while (*p != (char)endchar) {
+ while (*p != endchar) {
if (p[0] == '.' && p[1] == '.' && p[2] == '.') {
if (varargs != NULL) {
*varargs = true;
@@ -188,14 +188,14 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int
}
}
p = skipwhite(p);
- if (mustend && *p != (char)endchar) {
+ if (mustend && *p != endchar) {
if (!skip) {
semsg(_(e_invarg2), *argp);
}
break;
}
}
- if (*p != (char)endchar) {
+ if (*p != endchar) {
goto err_ret;
}
p++; // skip "endchar"
@@ -229,12 +229,12 @@ static void register_closure(ufunc_T *fp)
}
/// @return a name for a lambda. Returned in static memory.
-char_u *get_lambda_name(void)
+char *get_lambda_name(void)
{
- static char_u name[30];
+ static char name[30];
static int lambda_no = 0;
- snprintf((char *)name, sizeof(name), "<lambda>%d", ++lambda_no);
+ snprintf(name, sizeof(name), "<lambda>%d", ++lambda_no);
return name;
}
@@ -308,7 +308,7 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate)
char *p;
garray_T newlines;
- char *name = (char *)get_lambda_name();
+ char *name = get_lambda_name();
fp = xcalloc(1, offsetof(ufunc_T, uf_name) + strlen(name) + 1);
pt = xcalloc(1, sizeof(partial_T));
@@ -1226,7 +1226,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett
/// For the first we only count the name stored in func_hashtab as a reference,
/// using function() does not count as a reference, because the function is
/// looked up by name.
-static bool func_name_refcount(const char_u *name)
+static bool func_name_refcount(const char *name)
{
return isdigit((uint8_t)(*name)) || *name == '<';
}
@@ -1319,7 +1319,7 @@ void free_all_functions(void)
// Only free functions that are not refcounted, those are
// supposed to be freed when no longer referenced.
fp = HI2UF(hi);
- if (func_name_refcount((char_u *)fp->uf_name)) {
+ if (func_name_refcount(fp->uf_name)) {
skipped++;
} else {
changed = func_hashtab.ht_changed;
@@ -1345,7 +1345,7 @@ void free_all_functions(void)
// Only free functions that are not refcounted, those are
// supposed to be freed when no longer referenced.
fp = HI2UF(hi);
- if (func_name_refcount((char_u *)fp->uf_name)) {
+ if (func_name_refcount(fp->uf_name)) {
skipped++;
} else {
func_free(fp);
@@ -1382,7 +1382,7 @@ static bool builtin_function(const char *name, int len)
return p == NULL;
}
-int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv)
+int func_call(char *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv)
{
typval_T argv[MAX_FUNC_ARGS + 1];
int argc = 0;
@@ -1404,7 +1404,7 @@ int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict
funcexe.fe_evaluate = true;
funcexe.fe_partial = partial;
funcexe.fe_selfdict = selfdict;
- r = call_func((char *)name, -1, rettv, argc, argv, &funcexe);
+ r = call_func(name, -1, rettv, argc, argv, &funcexe);
func_call_skip_call:
// Free the arguments.
@@ -1435,30 +1435,30 @@ varnumber_T callback_call_retnr(Callback *callback, int argcount, typval_T *argv
/// 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)
+static void user_func_error(int error, const char *name)
FUNC_ATTR_NONNULL_ALL
{
switch (error) {
case FCERR_UNKNOWN:
- emsg_funcname(N_("E117: Unknown function: %s"), (char *)name);
+ emsg_funcname(N_("E117: Unknown function: %s"), name);
break;
case FCERR_NOTMETHOD:
- emsg_funcname(N_("E276: Cannot use function as a method: %s"), (char *)name);
+ emsg_funcname(N_("E276: Cannot use function as a method: %s"), name);
break;
case FCERR_DELETED:
- emsg_funcname(N_("E933: Function was deleted: %s"), (char *)name);
+ emsg_funcname(N_("E933: Function was deleted: %s"), name);
break;
case FCERR_TOOMANY:
- emsg_funcname(_(e_toomanyarg), (char *)name);
+ emsg_funcname(_(e_toomanyarg), name);
break;
case FCERR_TOOFEW:
- emsg_funcname(N_("E119: Not enough arguments for function: %s"), (char *)name);
+ emsg_funcname(N_("E119: Not enough arguments for function: %s"), name);
break;
case FCERR_SCRIPT:
- emsg_funcname(N_("E120: Using <SID> not in a script context: %s"), (char *)name);
+ emsg_funcname(N_("E120: Using <SID> not in a script context: %s"), name);
break;
case FCERR_DICT:
- emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"), (char *)name);
+ emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"), name);
break;
}
}
@@ -1612,7 +1612,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t
} else if (funcexe->fe_basetv != NULL) {
// expr->method(): Find the method name in the table, call its
// implementation with the base as one of the arguments.
- error = call_internal_method((char_u *)fname, argcount, argvars, rettv,
+ error = call_internal_method(fname, argcount, argvars, rettv,
funcexe->fe_basetv);
} else {
// Find the function name in the table, call its implementation.
@@ -1636,7 +1636,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) ? (char_u *)name : (char_u *)funcname);
+ user_func_error(error, (name != NULL) ? name : funcname);
}
// clear the copies made from the partial
@@ -1724,7 +1724,7 @@ static void list_func_head(ufunc_T *fp, int indent, bool force)
/// @param partial return: partial of a FuncRef
///
/// @return the function name in allocated memory, or NULL for failure.
-char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial)
+char *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial)
FUNC_ATTR_NONNULL_ARG(1)
{
char *name = NULL;
@@ -1745,7 +1745,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
&& (*pp)[2] == KE_SNR) {
*pp += 3;
len = get_id_len((const char **)pp) + 3;
- return (char_u *)xmemdupz(start, (size_t)len);
+ return xmemdupz(start, (size_t)len);
}
// A name starting with "<SID>" or "<SNR>" is local to a script. But
@@ -1924,7 +1924,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
theend:
clear_lval(&lv);
- return (char_u *)name;
+ return name;
}
/// If the "funcname" starts with "s:" or "<SID>", then expands it to the
@@ -1976,7 +1976,7 @@ char *save_function_name(char **name, bool skip, int flags, funcdict_T *fudi)
CLEAR_POINTER(fudi);
}
} else {
- saved = (char *)trans_function_name(&p, skip, flags, fudi, NULL);
+ saved = trans_function_name(&p, skip, flags, fudi, NULL);
}
*name = p;
return saved;
@@ -2001,7 +2001,7 @@ static void list_functions(regmatch_T *regmatch)
if ((fp->uf_flags & FC_DEAD) == 0
&& (regmatch == NULL
? (!message_filtered((char *)fp->uf_name)
- && !func_name_refcount((char_u *)fp->uf_name))
+ && !func_name_refcount(fp->uf_name))
: (!isdigit((uint8_t)(*fp->uf_name))
&& vim_regexec(regmatch, (char *)fp->uf_name, 0)))) {
list_func_head(fp, false, false);
@@ -2708,7 +2708,7 @@ bool function_exists(const char *const name, bool no_deref)
if (no_deref) {
flag |= TFN_NO_DEREF;
}
- char *const p = (char *)trans_function_name((char **)&nm, false, flag, NULL, NULL);
+ char *const p = trans_function_name((char **)&nm, false, flag, NULL, NULL);
nm = skipwhite(nm);
// Only accept "funcname", "funcname ", "funcname (..." and
@@ -2770,7 +2770,7 @@ void ex_delfunction(exarg_T *eap)
{
ufunc_T *fp = NULL;
char *p;
- char_u *name;
+ char *name;
funcdict_T fudi;
p = eap->arg;
@@ -2800,7 +2800,7 @@ void ex_delfunction(exarg_T *eap)
return;
}
if (!eap->skip) {
- fp = find_func(name);
+ fp = find_func((char_u *)name);
}
xfree(name);
@@ -2833,7 +2833,7 @@ void ex_delfunction(exarg_T *eap)
// it and the refcount is more than one, it should be kept.
// A numbered function or lambda should be kept if the refcount is
// one or more.
- if (fp->uf_refcount > (func_name_refcount((char_u *)fp->uf_name) ? 0 : 1)) {
+ if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1)) {
// Function is still referenced somewhere. Don't free it but
// do remove it from the hashtable.
if (func_remove(fp)) {
@@ -2849,7 +2849,7 @@ void ex_delfunction(exarg_T *eap)
/// Unreference a Function: decrement the reference count and free it when it
/// becomes zero.
-void func_unref(char_u *name)
+void func_unref(char *name)
{
ufunc_T *fp = NULL;
@@ -2857,7 +2857,7 @@ void func_unref(char_u *name)
return;
}
- fp = find_func(name);
+ fp = find_func((char_u *)name);
if (fp == NULL && isdigit((uint8_t)(*name))) {
#ifdef EXITFREE
if (!entered_free_all_mem) {
@@ -2891,14 +2891,14 @@ void func_ptr_unref(ufunc_T *fp)
}
/// Count a reference to a Function.
-void func_ref(char_u *name)
+void func_ref(char *name)
{
ufunc_T *fp;
if (name == NULL || !func_name_refcount(name)) {
return;
}
- fp = find_func(name);
+ fp = find_func((char_u *)name);
if (fp != NULL) {
(fp->uf_refcount)++;
} else if (isdigit((uint8_t)(*name))) {
@@ -3018,7 +3018,7 @@ void ex_call(exarg_T *eap)
return;
}
- tofree = (char *)trans_function_name(&arg, false, TFN_INT, &fudi, &partial);
+ tofree = trans_function_name(&arg, false, TFN_INT, &fudi, &partial);
if (fudi.fd_newkey != NULL) {
// Still need to give an error message for missing key.
semsg(_(e_dictkey), fudi.fd_newkey);
@@ -3328,7 +3328,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv)
// be referenced elsewhere.
if (ret_pt->pt_name != NULL) {
pt->pt_name = xstrdup(ret_pt->pt_name);
- func_ref((char_u *)pt->pt_name);
+ func_ref(pt->pt_name);
} else {
pt->pt_func = ret_pt->pt_func;
func_ptr_ref(pt->pt_func);
@@ -3349,9 +3349,9 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv)
}
/// @return the name of the executed function.
-char_u *func_name(void *cookie)
+char *func_name(void *cookie)
{
- return (char_u *)((funccall_T *)cookie)->func->uf_name;
+ return ((funccall_T *)cookie)->func->uf_name;
}
/// @return the address holding the next breakpoint line for a funccall cookie.
@@ -3610,7 +3610,7 @@ bool set_ref_in_functions(int copyID)
if (!HASHITEM_EMPTY(hi)) {
todo--;
fp = HI2UF(hi);
- if (!func_name_refcount((char_u *)fp->uf_name)
+ if (!func_name_refcount(fp->uf_name)
&& set_ref_in_func(NULL, fp, copyID)) {
return true;
}
@@ -3636,7 +3636,7 @@ bool set_ref_in_func_args(int copyID)
/// "ht_stack" is used to add hashtabs to be marked. Can be NULL.
///
/// @return true if setting references failed somehow.
-bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
+bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID)
{
ufunc_T *fp = fp_in;
funccall_T *fc;
@@ -3650,7 +3650,7 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
}
if (fp_in == NULL) {
- fname = fname_trans_sid((char *)name, fname_buf, &tofree, &error);
+ fname = fname_trans_sid(name, fname_buf, &tofree, &error);
fp = find_func((char_u *)fname);
}
if (fp != NULL) {
@@ -3663,9 +3663,9 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
}
/// Registers a luaref as a lambda.
-char_u *register_luafunc(LuaRef ref)
+char *register_luafunc(LuaRef ref)
{
- char *name = (char *)get_lambda_name();
+ char *name = get_lambda_name();
ufunc_T *fp = xcalloc(1, offsetof(ufunc_T, uf_name) + strlen(name) + 1);
fp->uf_refcount = 1;
@@ -3679,5 +3679,5 @@ char_u *register_luafunc(LuaRef ref)
hash_add(&func_hashtab, UF2HIKEY(fp));
// coverity[leaked_storage]
- return (char_u *)fp->uf_name;
+ return fp->uf_name;
}