eval,*: Move get_tv_string to typval.c

Function was renamed and changed to return `const char *`.
This commit is contained in:
ZyX
2016-08-21 08:16:47 +03:00
parent 5cdf7177ec
commit 28dafe3ff0
28 changed files with 1072 additions and 992 deletions

View File

@@ -77,10 +77,10 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2,
if (tv2->v_type == VAR_FLOAT) {
break;
}
char *s = (char *)get_tv_string(tv1);
const char *tvs = tv_get_string(tv1);
char numbuf[NUMBUFLEN];
s = (char *)concat_str((char_u *)s,
get_tv_string_buf(tv2, (char_u *)numbuf));
char *const s = (char *)concat_str(
(const char_u *)tvs, get_tv_string_buf(tv2, (char_u *)numbuf));
tv_clear(tv1);
tv1->v_type = VAR_STRING;
tv1->vval.v_string = (char_u *)s;

View File

@@ -733,7 +733,7 @@ varnumber_T tv_list_find_nr(list_T *const l, const int n, bool *ret_error)
/// @param[in] n Index in a list.
///
/// @return [allocated] Copy of the list item string value.
char *tv_list_find_str(list_T *l, int n)
const char *tv_list_find_str(list_T *l, int n)
FUNC_ATTR_MALLOC
{
const listitem_T *const li = tv_list_find(l, n - 1);
@@ -741,7 +741,7 @@ char *tv_list_find_str(list_T *l, int n)
EMSGN(_(e_listidx), n);
return NULL;
}
return (char *)get_tv_string(&li->li_tv);
return tv_get_string(&li->li_tv);
}
/// Locate item in a list and return its index
@@ -2014,3 +2014,27 @@ bool tv_check_str_or_nr(const typval_T *const tv)
assert(false);
return false;
}
//{{{2 Get
/// Get the string value of a variable
///
/// @warning For number and special values it uses a single, static buffer. It
/// may be used only once, next call to get_tv_string may reuse it. Use
/// get_tv_string_buf() if you need to use tv_get_string() output after
/// calling it again.
///
/// @note get_tv_string_chk() and get_tv_string_buf_chk() are similar, but
/// return NULL on error.
///
/// @param[in] varp Varible to get value of.
///
/// @return Variable value if it is VAR_STRING variable, number converted to
/// a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or empty
/// string.
const char *tv_get_string(const typval_T *const varp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
{
static char_u mybuf[NUMBUFLEN];
return (const char *)get_tv_string_buf((typval_T *)varp, mybuf);
}

View File

@@ -205,6 +205,8 @@ struct dictvar_S {
/// Type used for script ID
typedef int scid_T;
/// Format argument for scid_T
#define PRIdSCID "d"
// Structure to hold info for a function that is currently being executed.
typedef struct funccall_S funccall_T;