aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c31
-rw-r--r--test/functional/ex_cmds/echo_spec.lua24
2 files changed, 19 insertions, 36 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 0a83c3a586..0cad5fd6c1 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -8539,27 +8539,6 @@ void set_selfdict(typval_T *const rettv, dict_T *const selfdict)
make_partial(selfdict, rettv);
}
-// Turn a typeval into a string. Similar to tv_get_string_buf() but uses
-// string() on Dict, List, etc.
-static const char *tv_stringify(typval_T *varp, char *buf)
- FUNC_ATTR_NONNULL_ALL
-{
- if (varp->v_type == VAR_LIST
- || varp->v_type == VAR_DICT
- || varp->v_type == VAR_FUNC
- || varp->v_type == VAR_PARTIAL
- || varp->v_type == VAR_FLOAT) {
- typval_T tmp;
-
- f_string(varp, &tmp, NULL);
- const char *const res = tv_get_string_buf(&tmp, buf);
- tv_clear(varp);
- *varp = tmp;
- return res;
- }
- return tv_get_string_buf(varp, buf);
-}
-
// 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.
@@ -9406,16 +9385,20 @@ void ex_execute(exarg_T *eap)
}
if (!eap->skip) {
- char buf[NUMBUFLEN];
const char *const argstr = eap->cmdidx == CMD_execute
- ? tv_get_string_buf(&rettv, buf)
- : tv_stringify(&rettv, buf);
+ ? tv_get_string(&rettv)
+ : rettv.v_type == VAR_STRING
+ ? encode_tv2echo(&rettv, NULL)
+ : encode_tv2string(&rettv, NULL);
const size_t len = strlen(argstr);
ga_grow(&ga, len + 2);
if (!GA_EMPTY(&ga)) {
((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
}
memcpy((char_u *)(ga.ga_data) + ga.ga_len, argstr, len + 1);
+ if (eap->cmdidx != CMD_execute) {
+ xfree((void *)argstr);
+ }
ga.ga_len += len;
}
diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua
index 408ce52b8c..404dc39ad2 100644
--- a/test/functional/ex_cmds/echo_spec.lua
+++ b/test/functional/ex_cmds/echo_spec.lua
@@ -71,18 +71,18 @@ describe(':echo :echon :echomsg :echoerr', function()
eq('v:true', funcs.String(true))
eq('v:false', funcs.String(false))
eq('v:null', funcs.String(NIL))
- eq('true', eval('StringMsg(v:true)'))
- eq('false', eval('StringMsg(v:false)'))
- eq('null', eval('StringMsg(v:null)'))
- eq('true', funcs.StringMsg(true))
- eq('false', funcs.StringMsg(false))
- eq('null', funcs.StringMsg(NIL))
- eq('true', eval('StringErr(v:true)'))
- eq('false', eval('StringErr(v:false)'))
- eq('null', eval('StringErr(v:null)'))
- eq('true', funcs.StringErr(true))
- eq('false', funcs.StringErr(false))
- eq('null', funcs.StringErr(NIL))
+ eq('v:true', eval('StringMsg(v:true)'))
+ eq('v:false', eval('StringMsg(v:false)'))
+ eq('v:null', eval('StringMsg(v:null)'))
+ eq('v:true', funcs.StringMsg(true))
+ eq('v:false', funcs.StringMsg(false))
+ eq('v:null', funcs.StringMsg(NIL))
+ eq('v:true', eval('StringErr(v:true)'))
+ eq('v:false', eval('StringErr(v:false)'))
+ eq('v:null', eval('StringErr(v:null)'))
+ eq('v:true', funcs.StringErr(true))
+ eq('v:false', funcs.StringErr(false))
+ eq('v:null', funcs.StringErr(NIL))
end)
it('dumps values with at most six digits after the decimal point',