mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 15:21:47 +00:00
eval: improve ex_execute (#12445)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user