mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.2435: setline() gives an error for some types
Problem: setline() gives an error for some types. Solution: Allow any type, convert each item to a string.
This commit is contained in:
23
src/typval.c
23
src/typval.c
@@ -927,8 +927,13 @@ typval_compare(
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert any type to a string, never give an error.
|
||||
* When "quotes" is TRUE add quotes to a string.
|
||||
* Returns an allocated string.
|
||||
*/
|
||||
char_u *
|
||||
typval_tostring(typval_T *arg)
|
||||
typval_tostring(typval_T *arg, int quotes)
|
||||
{
|
||||
char_u *tofree;
|
||||
char_u numbuf[NUMBUFLEN];
|
||||
@@ -936,10 +941,18 @@ typval_tostring(typval_T *arg)
|
||||
|
||||
if (arg == NULL)
|
||||
return vim_strsave((char_u *)"(does not exist)");
|
||||
ret = tv2string(arg, &tofree, numbuf, 0);
|
||||
// Make a copy if we have a value but it's not in allocated memory.
|
||||
if (ret != NULL && tofree == NULL)
|
||||
ret = vim_strsave(ret);
|
||||
if (!quotes && arg->v_type == VAR_STRING)
|
||||
{
|
||||
ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)""
|
||||
: arg->vval.v_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = tv2string(arg, &tofree, numbuf, 0);
|
||||
// Make a copy if we have a value but it's not in allocated memory.
|
||||
if (ret != NULL && tofree == NULL)
|
||||
ret = vim_strsave(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user