aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c33
-rw-r--r--src/nvim/eval/vars.c2
2 files changed, 24 insertions, 11 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 16db4e791b..a79a464860 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -703,10 +703,15 @@ int eval_to_bool(char *arg, bool *error, exarg_T *eap, int skip)
typval_T tv;
bool retval = false;
+ evalarg_T evalarg = {
+ .eval_flags = skip ? 0 : EVAL_EVALUATE,
+ .eval_cookie = eap != NULL && eap->getline == getsourceline ? eap->cookie : NULL,
+ };
+
if (skip) {
emsg_skip++;
}
- if (eval0(arg, &tv, eap, skip ? NULL : &EVALARG_EVALUATE) == FAIL) {
+ if (eval0(arg, &tv, eap, &evalarg) == FAIL) {
*error = true;
} else {
*error = false;
@@ -718,6 +723,7 @@ int eval_to_bool(char *arg, bool *error, exarg_T *eap, int skip)
if (skip) {
emsg_skip--;
}
+ clear_evalarg(&evalarg, eap);
return retval;
}
@@ -2228,6 +2234,20 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ
return ret;
}
+/// After using "evalarg" filled from "eap" free the memory.
+void clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
+{
+ if (evalarg != NULL && eap != NULL && evalarg->eval_tofree != NULL) {
+ // We may need to keep the original command line, e.g. for
+ // ":let" it has the variable names. But we may also need the
+ // new one, "nextcmd" points into it. Keep both.
+ xfree(eap->cmdline_tofree);
+ eap->cmdline_tofree = *eap->cmdlinep;
+ *eap->cmdlinep = evalarg->eval_tofree;
+ evalarg->eval_tofree = NULL;
+ }
+}
+
/// The "evaluate" argument: When false, the argument is only parsed but not
/// executed. The function may return OK, but the rettv will be of type
/// VAR_UNKNOWN. The function still returns FAIL for a syntax error.
@@ -2278,15 +2298,7 @@ int eval0(char *arg, typval_T *rettv, exarg_T *eap, evalarg_T *const evalarg)
eap->nextcmd = check_nextcmd(p);
}
- if (evalarg != NULL && eap != NULL && evalarg->eval_tofree != NULL) {
- // We may need to keep the original command line, e.g. for
- // ":let" it has the variable names. But we may also need the
- // new one, "nextcmd" points into it. Keep both.
- xfree(eap->cmdline_tofree);
- eap->cmdline_tofree = *eap->cmdlinep;
- *eap->cmdlinep = evalarg->eval_tofree;
- evalarg->eval_tofree = NULL;
- }
+ clear_evalarg(evalarg, eap);
return ret;
}
@@ -7502,6 +7514,7 @@ void ex_echo(exarg_T *eap)
arg = skipwhite(arg);
}
eap->nextcmd = check_nextcmd(arg);
+ clear_evalarg(&evalarg, eap);
if (eap->skip) {
emsg_skip--;
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index c566129202..868d03a115 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -267,7 +267,7 @@ void ex_let(exarg_T *eap)
if (eap->skip) {
emsg_skip--;
}
- xfree(evalarg.eval_tofree);
+ clear_evalarg(&evalarg, eap);
if (!eap->skip && eval_res != FAIL) {
(void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, is_const, op);