Macros | Functions | Variables
typval.c File Reference
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include "nvim/lib/queue.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/gc.h"
#include "nvim/eval/executor.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/typval_encode.h"
#include "nvim/eval.h"
#include "nvim/types.h"
#include "nvim/memory.h"
#include "nvim/globals.h"
#include "nvim/hashtab.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/pos.h"
#include "nvim/charset.h"
#include "nvim/garray.h"
#include "nvim/gettext.h"
#include "nvim/macros.h"
#include "nvim/mbyte.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/os/fileio.h"
#include "nvim/eval/typval_encode.c.h"

Macros

#define DICT_MAXNEST   100
 
#define SL_SIZE   ARRAY_SIZE(sl->sl_items)
 
#define FREE_JOIN_TOFREE(join)   xfree((join)->tofree)
 
#define SWAP(a, b)
 
#define TYPVAL_ENCODE_ALLOW_SPECIALS   false
 
#define TYPVAL_ENCODE_CONV_NIL(tv)
 
#define TYPVAL_ENCODE_CONV_BOOL(tv, num)   TYPVAL_ENCODE_CONV_NIL(tv)
 
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num)
 
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num)
 
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt)
 
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type)
 
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_END(tv)   _nothing_conv_func_end(tv, copyID)
 
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv)
 
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict)
 
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len)
 
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
 
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv)
 
#define TYPVAL_ENCODE_CONV_LIST_END(tv)   _nothing_conv_list_end(tv)
 
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len)
 
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv)
 
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(tv, dict)
 
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(tv, dict)
 
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)
 
#define TYPVAL_ENCODE_CONV_DICT_END(tv, dict)
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)
 
#define TYPVAL_ENCODE_SCOPE   static
 
#define TYPVAL_ENCODE_NAME   nothing
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   const void *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   ignored
 
#define TYPVAL_ENCODE_TRANSLATE_OBJECT_NAME
 
#define CHANGE_LOCK(lock, var)
 
#define FUNC_ERROR   "E703: Using a Funcref as a Number"
 
#define FUNC_ERROR   "E729: using Funcref as a String"
 

Functions

listitem_Ttv_list_item_remove (list_T *const l, listitem_T *const item) FUNC_ATTR_NONNULL_ALL
 
void tv_list_watch_add (list_T *const l, listwatch_T *const lw) FUNC_ATTR_NONNULL_ALL
 
void tv_list_watch_remove (list_T *const l, listwatch_T *const lwrem) FUNC_ATTR_NONNULL_ALL
 
void tv_list_watch_fix (list_T *const l, const listitem_T *const item) FUNC_ATTR_NONNULL_ALL
 
list_Ttv_list_alloc (const ptrdiff_t len) FUNC_ATTR_NONNULL_RET
 
void tv_list_init_static10 (staticList10_T *const sl) FUNC_ATTR_NONNULL_ALL
 
void tv_list_init_static (list_T *const l) FUNC_ATTR_NONNULL_ALL
 
void tv_list_free_contents (list_T *const l) FUNC_ATTR_NONNULL_ALL
 
void tv_list_free_list (list_T *const l) FUNC_ATTR_NONNULL_ALL
 
void tv_list_free (list_T *const l) FUNC_ATTR_NONNULL_ALL
 
void tv_list_unref (list_T *const l)
 
void tv_list_drop_items (list_T *const l, listitem_T *const item, listitem_T *const item2) FUNC_ATTR_NONNULL_ALL
 
void tv_list_remove_items (list_T *const l, listitem_T *const item, listitem_T *const item2) FUNC_ATTR_NONNULL_ALL
 Like tv_list_drop_items, but also frees all removed items. More...
 
void tv_list_move_items (list_T *const l, listitem_T *const item, listitem_T *const item2, list_T *const tgt_l, const int cnt) FUNC_ATTR_NONNULL_ALL
 
void tv_list_insert (list_T *const l, listitem_T *const ni, listitem_T *const item) FUNC_ATTR_NONNULL_ARG(1
 
int tv_list_join (garray_T *const gap, list_T *const l, const char *const sep) FUNC_ATTR_NONNULL_ARG(1)
 
bool tv_list_equal (list_T *const l1, list_T *const l2, const bool ic, const bool recursive) FUNC_ATTR_WARN_UNUSED_RESULT
 
void tv_list_reverse (list_T *const l)
 
void tv_list_item_sort (list_T *const l, ListSortItem *const ptrs, const ListSorter item_compare_func, bool *errp) FUNC_ATTR_NONNULL_ARG(3
 
void if (len<=1)
 
 list_log (l, NULL, NULL,"sort")
 
 TV_LIST_ITER (l, li,{ptrs[i].item=li;ptrs[i].idx=i;i++;})
 
 qsort (ptrs,(size_t) len, sizeof(ListSortItem), item_compare_func)
 
 if (!(*errp))
 
listitem_Ttv_list_find (list_T *const l, int n) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
varnumber_T tv_list_find_nr (list_T *const l, const int n, bool *const ret_error) FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_list_find_str (list_T *const l, const int n) FUNC_ATTR_WARN_UNUSED_RESULT
 
long tv_list_idx_of_item (const list_T *const l, const listitem_T *const item) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
 
void tv_dict_watcher_add (dict_T *const dict, const char *const key_pattern, const size_t key_pattern_len, Callback callback) FUNC_ATTR_NONNULL_ARG(2)
 
bool tv_callback_equal (const Callback *cb1, const Callback *cb2) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
void callback_free (Callback *callback) FUNC_ATTR_NONNULL_ALL
 Unref/free callback. More...
 
bool tv_dict_watcher_remove (dict_T *const dict, const char *const key_pattern, const size_t key_pattern_len, Callback callback) FUNC_ATTR_NONNULL_ARG(2)
 
void tv_dict_watcher_notify (dict_T *const dict, const char *const key, typval_T *const newtv, typval_T *const oldtv) FUNC_ATTR_NONNULL_ARG(1
 
 if (newtv)
 
 if (oldtv)
 
 QUEUE_FOREACH (w,&dict->watchers)
 
 for (size_t i=1;i< ARRAY_SIZE(argv);i++)
 
dictitem_Ttv_dict_item_alloc_len (const char *const key, const size_t key_len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
 
dictitem_Ttv_dict_item_alloc (const char *const key) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
 
void tv_dict_item_free (dictitem_T *const item) FUNC_ATTR_NONNULL_ALL
 
dictitem_Ttv_dict_item_copy (dictitem_T *const di) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
void tv_dict_item_remove (dict_T *const dict, dictitem_T *const item) FUNC_ATTR_NONNULL_ALL
 
dict_Ttv_dict_alloc (void)
 
void tv_dict_free_contents (dict_T *const d) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_free_dict (dict_T *const d) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_free (dict_T *const d) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_unref (dict_T *const d)
 
dictitem_Ttv_dict_find (const dict_T *const d, const char *const key, const ptrdiff_t len) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
varnumber_T tv_dict_get_number (const dict_T *const d, const char *const key) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
char * tv_dict_get_string (const dict_T *const d, const char *const key, const bool save) FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_dict_get_string_buf (const dict_T *const d, const char *const key, char *const numbuf) FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_dict_get_string_buf_chk (const dict_T *const d, const char *const key, const ptrdiff_t key_len, char *const numbuf, const char *const def) FUNC_ATTR_WARN_UNUSED_RESULT
 
bool tv_dict_get_callback (dict_T *const d, const char *const key, const ptrdiff_t key_len, Callback *const result) FUNC_ATTR_NONNULL_ARG(2
 
 if (di==NULL)
 
 if (!tv_is_func(di->di_tv)&&di->di_tv.v_type!=VAR_STRING)
 
int tv_dict_add (dict_T *const d, dictitem_T *const item) FUNC_ATTR_NONNULL_ALL
 
int tv_dict_add_list (dict_T *const d, const char *const key, const size_t key_len, list_T *const list) FUNC_ATTR_NONNULL_ALL
 
int tv_dict_add_dict (dict_T *const d, const char *const key, const size_t key_len, dict_T *const dict) FUNC_ATTR_NONNULL_ALL
 
int tv_dict_add_nr (dict_T *const d, const char *const key, const size_t key_len, const varnumber_T nr)
 
int tv_dict_add_special (dict_T *const d, const char *const key, const size_t key_len, SpecialVarValue val)
 
int tv_dict_add_str (dict_T *const d, const char *const key, const size_t key_len, const char *const val) FUNC_ATTR_NONNULL_ALL
 
int tv_dict_add_str_len (dict_T *const d, const char *const key, const size_t key_len, char *const val, int len) FUNC_ATTR_NONNULL_ARG(1
 
int if (val!=NULL)
 
return tv_dict_add_allocated_str (d, key, key_len, s)
 
int tv_dict_add_allocated_str (dict_T *const d, const char *const key, const size_t key_len, char *const val) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_clear (dict_T *const d) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_extend (dict_T *const d1, dict_T *const d2, const char *const action) FUNC_ATTR_NONNULL_ALL
 
bool tv_dict_equal (dict_T *const d1, dict_T *const d2, const bool ic, const bool recursive) FUNC_ATTR_WARN_UNUSED_RESULT
 
dict_Ttv_dict_copy (const vimconv_T *const conv, dict_T *const orig, const bool deep, const int copyID)
 
void tv_dict_set_keys_readonly (dict_T *const dict) FUNC_ATTR_NONNULL_ALL
 
list_Ttv_list_alloc_ret (typval_T *const ret_tv, const ptrdiff_t len) FUNC_ATTR_NONNULL_ALL
 
void tv_dict_alloc_ret (typval_T *const ret_tv) FUNC_ATTR_NONNULL_ALL
 
void tv_clear (typval_T *const tv)
 
void tv_free (typval_T *tv)
 
void tv_copy (const typval_T *const from, typval_T *const to)
 
void tv_item_lock (typval_T *const tv, const int deep, const bool lock) FUNC_ATTR_NONNULL_ALL
 
bool tv_islocked (const typval_T *const tv) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
 
bool tv_check_lock (const VarLockStatus lock, const char *name, size_t name_len) FUNC_ATTR_WARN_UNUSED_RESULT
 
bool tv_equal (typval_T *const tv1, typval_T *const tv2, const bool ic, const bool recursive) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
 
bool tv_check_str_or_nr (const typval_T *const tv) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
 
bool tv_check_num (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
bool tv_check_str (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
varnumber_T tv_get_number (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
varnumber_T tv_get_number_chk (const typval_T *const tv, bool *const ret_error) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
 
linenr_T tv_get_lnum (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
float_T tv_get_float (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_get_string_buf_chk (const typval_T *const tv, char *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_get_string_chk (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_get_string (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
 
const char * tv_get_string_buf (const typval_T *const tv, char *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
 

Variables

bool tv_in_free_unref_items = false
 Specifies that free_unref_items() function has (not) been entered. More...
 
const char *const tv_empty_string = ""
 
int i = 0
 
void argv[0] v_type = VAR_DICT
 
argv[0] v_lock = VAR_UNLOCKED
 
argv[0] vval v_dict = dict
 
argv[1] vval v_string = (char_u *)xstrdup(key)
 
argv[2] vval v_dict dv_refcount
 
typval_T rettv = rettv
 
QUEUEw
 
bool FUNC_ATTR_WARN_UNUSED_RESULT
 
dictitem_T *const di = tv_dict_find(d, key, key_len)
 
typval_T tv
 
const bool res = callback_from_typval(result, &tv)
 

Macro Definition Documentation

#define CHANGE_LOCK (   lock,
  var 
)
Value:
do { \
var = ((VarLockStatus[]) { \
})[var]; \
} while (0)
User lock, can be unlocked.
Definition: typval.h:104
Not locked.
Definition: typval.h:103
void char_u * var
Definition: env.c:416
VarLockStatus
Variable lock status for typval_T.v_lock.
Definition: typval.h:102
Locked forever.
Definition: typval.h:105
#define DICT_MAXNEST   100
#define FREE_JOIN_TOFREE (   join)    xfree((join)->tofree)
#define FUNC_ERROR   "E703: Using a Funcref as a Number"
#define FUNC_ERROR   "E729: using Funcref as a String"
#define SL_SIZE   ARRAY_SIZE(sl->sl_items)
#define SWAP (   a,
 
)
Value:
do { \
tmp = a; \
a = b; \
b = tmp; \
} while (0)
#define TYPVAL_ENCODE_ALLOW_SPECIALS   false
#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    TYPVAL_ENCODE_CONV_NIL(tv)
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)
#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)
Value:
_nothing_conv_dict_end(tv, (dict_T **)&dict, \
typval_T tv
Definition: typval.c:1542
const dict_T *const TYPVAL_ENCODE_NODICT_VAR
Definition: typval_encode.c.h:250
Definition: coverity-model.c:40
#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)
#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)
Value:
do { \
assert((void *)&dict != (void *)&TYPVAL_ENCODE_NODICT_VAR); \
_nothing_conv_empty_dict(tv, ((dict_T **)&dict)); \
} while (0)
typval_T tv
Definition: typval.c:1542
const dict_T *const TYPVAL_ENCODE_NODICT_VAR
Definition: typval_encode.c.h:250
assert(len >=0)
Definition: coverity-model.c:40
#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)
Value:
do { \
} while (0)
typval_T tv
Definition: typval.c:1542
Not locked.
Definition: typval.h:103
return NULL
Definition: eval.c:23643
list_T * v_list
List for VAR_LIST, can be NULL.
Definition: typval.h:131
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:125
union typval_T::typval_vval_union vval
Actual value.
void tv_list_unref(list_T *const l)
Definition: typval.c:326
#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)
#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)
Value:
do { \
} while (0)
typval_T tv
Definition: typval.c:1542
Not locked.
Definition: typval.h:103
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:125
union typval_T::typval_vval_union vval
Actual value.
float_T v_float
Floating-point number, for VAR_FLOAT.
Definition: typval.h:129
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)
#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)    _nothing_conv_func_end(tv, copyID)
#define TYPVAL_ENCODE_CONV_FUNC_START (   tv,
  fun 
)
Value:
do { \
if (_nothing_conv_func_start(tv, fun) != NOTDONE) { \
} \
} while (0)
typval_T tv
Definition: typval.c:1542
return OK
Definition: eval.c:1050
void if(len<=1)
Definition: typval.c:864
return
Definition: eval.c:15624
#define NOTDONE
Definition: vim.h:94
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)
#define TYPVAL_ENCODE_CONV_LIST_END (   tv)    _nothing_conv_list_end(tv)
#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)
#define TYPVAL_ENCODE_CONV_NIL (   tv)
Value:
do { \
} while (0)
typval_T tv
Definition: typval.c:1542
Not locked.
Definition: typval.h:103
v:false
Definition: typval.h:96
SpecialVarValue v_special
Special value, for VAR_SPECIAL.
Definition: typval.h:128
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:125
union typval_T::typval_vval_union vval
Actual value.
#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)
Value:
do { \
(void)num; \
} while (0)
typval_T tv
Definition: typval.c:1542
Not locked.
Definition: typval.h:103
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:125
union typval_T::typval_vval_union vval
Actual value.
varnumber_T v_number
Number, for VAR_NUMBER.
Definition: typval.h:127
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)
Value:
do { \
if (_nothing_conv_real_dict_after_start( \
tv, (dict_T **)&dict, (void *)&TYPVAL_ENCODE_NODICT_VAR, \
&mpsv) != NOTDONE) { \
goto typval_encode_stop_converting_one_item; \
} \
} while (0)
typval_T tv
Definition: typval.c:1542
const dict_T *const TYPVAL_ENCODE_NODICT_VAR
Definition: typval_encode.c.h:250
Definition: coverity-model.c:40
void if(len<=1)
Definition: typval.c:864
#define NOTDONE
Definition: vim.h:94
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)
Value:
do { \
if (_nothing_conv_real_list_after_start(tv, &mpsv) != NOTDONE) { \
goto typval_encode_stop_converting_one_item; \
} \
} while (0)
typval_T tv
Definition: typval.c:1542
void if(len<=1)
Definition: typval.c:864
#define NOTDONE
Definition: vim.h:94
#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
#define TYPVAL_ENCODE_CONV_STR_STRING (   tv,
  buf,
  len 
)
#define TYPVAL_ENCODE_CONV_STRING (   tv,
  buf,
  len 
)
Value:
do { \
} while (0)
typval_T tv
Definition: typval.c:1542
xfree(tofree)
Not locked.
Definition: typval.h:103
return NULL
Definition: eval.c:23643
char *const buf
Definition: encode.c:231
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:125
char_u * v_string
String, for VAR_STRING and VAR_FUNC, can be NULL.
Definition: typval.h:130
union typval_T::typval_vval_union vval
Actual value.
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)
#define TYPVAL_ENCODE_FIRST_ARG_NAME   ignored
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   const void *const
#define TYPVAL_ENCODE_NAME   nothing
#define TYPVAL_ENCODE_SCOPE   static
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   tv,
  dict 
)
#define TYPVAL_ENCODE_TRANSLATE_OBJECT_NAME

Function Documentation

void callback_free ( Callback callback)

Unref/free callback.

for ( )
void if ( len<=  1)
if ( !*  errp)
if ( newtv  )
if ( oldtv  )
if ( di  = NULL)
if ( !tv_is_func(di->di_tv)&&di->di_tv.v_type!  = VAR_STRING)
int if ( val!  = NULL)
list_log ( l  ,
NULL  ,
NULL  ,
"sort"   
)
qsort ( ptrs  ,
(size_t)  len,
sizeof(ListSortItem ,
item_compare_func   
)
QUEUE_FOREACH ( w  ,
&dict->  watchers 
)
bool tv_callback_equal ( const Callback cb1,
const Callback cb2 
)

Check whether two callbacks are equal

Parameters
[in]cb1First callback to check.
[in]cb2Second callback to check.
Returns
True if they are equal, false otherwise.
bool tv_check_lock ( const VarLockStatus  lock,
const char *  name,
size_t  name_len 
)

Return true if typval is locked

Also gives an error message when typval is locked.

Parameters
[in]lockLock status.
[in]nameVariable name, used in the error message.
[in]name_lenVariable name length. Use TV_TRANSLATE to translate variable name and compute the length. Use TV_CSTRING to compute the length with strlen() without translating.

Both #TV_… values are used for optimization purposes: variable name with its length is needed only in case of error, when no error occurs computing them is a waste of CPU resources. This especially applies to gettext.

Returns
true if variable is locked, false otherwise.
bool tv_check_num ( const typval_T *const  tv)

Check that given value is a number or can be converted to it

Error messages are compatible with tv_get_number_chk() previously used for the same purpose.

Parameters
[in]tvValue to check.
Returns
true if everything is OK, false otherwise.
bool tv_check_str ( const typval_T *const  tv)

Check that given value is a VimL String or can be "cast" to it.

Error messages are compatible with tv_get_string_chk() previously used for the same purpose.

Parameters
[in]tvValue to check.
Returns
true if everything is OK, false otherwise.
bool tv_check_str_or_nr ( const typval_T *const  tv)

Check that given value is a number or string

Error messages are compatible with tv_get_number() previously used for the same purpose in buf*() functions. Special values are not accepted (previous behaviour: silently fail to find buffer).

Parameters
[in]tvValue to check.
Returns
true if everything is OK, false otherwise.
void tv_clear ( typval_T *const  tv)

Free memory for a variable value and set the value to NULL or 0

Parameters
[in,out]tvValue to free.
void tv_copy ( const typval_T *const  from,
typval_T *const  to 
)

Copy typval from one location to another

When needed allocates string or increases reference count. Does not make a copy of a container, but copies its reference!

It is OK for from and to to point to the same location; this is used to make a copy later.

Parameters
[in]fromLocation to copy from.
[out]toLocation to copy to.
int tv_dict_add ( dict_T *const  d,
dictitem_T *const  item 
)

Add item to dictionary

Parameters
[out]dDictionary to add to.
[in]itemItem to add.
Returns
FAIL if key already exists.
return tv_dict_add_allocated_str ( d  ,
key  ,
key_len  ,
s   
)
int tv_dict_add_allocated_str ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
char *const  val 
)

Add a string entry to dictionary

Unlike tv_dict_add_str() saves val to the new dictionary item in place of creating a new copy.

Warning
String will be freed even in case addition fails.
Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
[in]valString to add.
Returns
OK in case of success, FAIL when key already exists.
int tv_dict_add_dict ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
dict_T *const  dict 
)

Add a dictionary entry to dictionary

Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
dictDictionary to add. Will have reference count incremented.
Returns
OK in case of success, FAIL when key already exists.
int tv_dict_add_list ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
list_T *const  list 
)

Add a list entry to dictionary

Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
listList to add. Will have reference count incremented.
Returns
OK in case of success, FAIL when key already exists.
int tv_dict_add_nr ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
const varnumber_T  nr 
)

Add a number entry to dictionary

Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
[in]nrNumber to add.
Returns
OK in case of success, FAIL when key already exists.
int tv_dict_add_special ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
SpecialVarValue  val 
)

Add a special entry to dictionary

Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
[in]valSpecialVarValue to add.
Returns
OK in case of success, FAIL when key already exists.
int tv_dict_add_str ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
const char *const  val 
)

Add a string entry to dictionary

See also
tv_dict_add_allocated_str
int tv_dict_add_str_len ( dict_T *const  d,
const char *const  key,
const size_t  key_len,
char *const  val,
int  len 
)

Add a string entry to dictionary

Parameters
[out]dDictionary to add entry to.
[in]keyKey to add.
[in]key_lenKey length.
[in]valString to add. NULL adds empty string.
[in]lenUse this many bytes from val, or -1 for whole string.
Returns
OK in case of success, FAIL when key already exists.
dict_T* tv_dict_alloc ( void  )

Allocate an empty dictionary

Returns
[allocated] new dictionary.
void tv_dict_alloc_ret ( typval_T *const  ret_tv)

Allocate an empty dictionary for a return value

Also sets reference count.

Parameters
[out]ret_tvStructure where dictionary is saved.
void tv_dict_clear ( dict_T *const  d)

Clear all the keys of a Dictionary. "d" remains a valid empty Dictionary.

Parameters
dThe Dictionary to clear
dict_T* tv_dict_copy ( const vimconv_T *const  conv,
dict_T *const  orig,
const bool  deep,
const int  copyID 
)

Make a copy of dictionary

Parameters
[in]convIf non-NULL, then all internal strings will be converted.
[in]origOriginal dictionary to copy.
[in]deepIf false, then shallow copy will be done.
[in]copyIDSee var_item_copy().
Returns
Copied dictionary. May be NULL in case original dictionary is NULL or some failure happens. The refcount of the new dictionary is set to 1.
bool tv_dict_equal ( dict_T *const  d1,
dict_T *const  d2,
const bool  ic,
const bool  recursive 
)

Compare two dictionaries

Parameters
[in]d1First dictionary.
[in]d2Second dictionary.
[in]icTrue if case is to be ignored.
[in]recursiveTrue when used recursively.
void tv_dict_extend ( dict_T *const  d1,
dict_T *const  d2,
const char *const  action 
)

Extend dictionary with items from another dictionary

Parameters
d1Dictionary to extend.
[in]d2Dictionary to extend with.
[in]action"error", "force", "keep":
                e*, including "error": duplicate key gives an error.
                f*, including "force": duplicate d2 keys override d1.
                other, including "keep": duplicate d2 keys ignored.  
dictitem_T* tv_dict_find ( const dict_T *const  d,
const char *const  key,
const ptrdiff_t  len 
)

Find item in dictionary

Parameters
[in]dDictionary to check.
[in]keyDictionary key.
[in]lenKey length. If negative, then strlen(key) is used.
Returns
found item or NULL if nothing was found.
void tv_dict_free ( dict_T *const  d)

Free a dictionary, including all items it contains

Ignores the reference count.

Parameters
dDictionary to free.
void tv_dict_free_contents ( dict_T *const  d)

Free items contained in a dictionary

Parameters
[in,out]dDictionary to clear.
void tv_dict_free_dict ( dict_T *const  d)

Free a dictionary itself, ignoring items it contains

Ignores the reference count.

Parameters
[in,out]dDictionary to free.
bool tv_dict_get_callback ( dict_T *const  d,
const char *const  key,
const ptrdiff_t  key_len,
Callback *const  result 
)

Get a function from a dictionary

Parameters
[in]dDictionary to get callback from.
[in]keyDictionary key.
[in]key_lenKey length, may be -1 to use strlen().
[out]resultThe address where a pointer to the wanted callback will be left.
Returns
true/false on success/failure.
varnumber_T tv_dict_get_number ( const dict_T *const  d,
const char *const  key 
)

Get a number item from a dictionary

Returns 0 if the entry does not exist.

Parameters
[in]dDictionary to get item from.
[in]keyKey to find in dictionary.
Returns
Dictionary item.
char* tv_dict_get_string ( const dict_T *const  d,
const char *const  key,
const bool  save 
)

Get a string item from a dictionary

Parameters
[in]dDictionary to get item from.
[in]keyDictionary key.
[in]saveIf true, returned string will be placed in the allocated memory.
Returns
NULL if key does not exist, empty string in case of type error, string item value otherwise. If returned value is not NULL, it may be allocated depending on save argument.
const char* tv_dict_get_string_buf ( const dict_T *const  d,
const char *const  key,
char *const  numbuf 
)

Get a string item from a dictionary

Parameters
[in]dDictionary to get item from.
[in]keyDictionary key.
[in]numbufBuffer for non-string items converted to strings, at least of NUMBUFLEN length.
Returns
NULL if key does not exist, empty string in case of type error, string item value otherwise.
const char* tv_dict_get_string_buf_chk ( const dict_T *const  d,
const char *const  key,
const ptrdiff_t  key_len,
char *const  numbuf,
const char *const  def 
)

Get a string item from a dictionary

Parameters
[in]dDictionary to get item from.
[in]keyDictionary key.
[in]key_lenKey length.
[in]numbufBuffer for non-string items converted to strings, at least of NUMBUFLEN length.
[in]defDefault return when key does not exist.
Returns
def when key does not exist, NULL in case of type error, string item value in case of success.
dictitem_T* tv_dict_item_alloc ( const char *const  key)

Allocate a dictionary item

Note
that the type and value of the item (->di_tv) still needs to be initialized.
Parameters
[in]keyKey, is copied to the new item.
Returns
[allocated] new dictionary item.
dictitem_T* tv_dict_item_alloc_len ( const char *const  key,
const size_t  key_len 
)

Allocate a dictionary item

Note
that the type and value of the item (->di_tv) still needs to be initialized.
Parameters
[in]keyKey, is copied to the new item.
[in]key_lenKey length.
Returns
[allocated] new dictionary item.
dictitem_T* tv_dict_item_copy ( dictitem_T *const  di)

Make a copy of a dictionary item

Parameters
[in]diItem to copy.
Returns
[allocated] new dictionary item.
void tv_dict_item_free ( dictitem_T *const  item)

Free a dictionary item, also clearing the value

Parameters
itemItem to free.
void tv_dict_item_remove ( dict_T *const  dict,
dictitem_T *const  item 
)

Remove item from dictionary and free it

Parameters
dictDictionary to remove item from.
itemItem to remove.
void tv_dict_set_keys_readonly ( dict_T *const  dict)

Set all existing keys in "dict" as read-only.

This does not protect against adding new keys to the Dictionary.

Parameters
dictThe dict whose keys should be frozen.
void tv_dict_unref ( dict_T *const  d)

Unreference a dictionary

Decrements the reference count and frees dictionary when it becomes zero.

Parameters
[in]dDictionary to operate on.
void tv_dict_watcher_add ( dict_T *const  dict,
const char *const  key_pattern,
const size_t  key_pattern_len,
Callback  callback 
)

Add watcher to a dictionary

Parameters
[in]dictDictionary to add watcher to.
[in]key_patternPattern to watch for.
[in]key_pattern_lenKey pattern length.
callbackFunction to be called on events.
void tv_dict_watcher_notify ( dict_T *const  dict,
const char *const  key,
typval_T *const  newtv,
typval_T *const  oldtv 
)

Send a change notification to all dictionary watchers that match given key

Parameters
[in]dictDictionary which was modified.
[in]keyKey which was modified.
[in]newtvNew key value.
[in]oldtvOld key value.
bool tv_dict_watcher_remove ( dict_T *const  dict,
const char *const  key_pattern,
const size_t  key_pattern_len,
Callback  callback 
)

Remove watcher from a dictionary

Parameters
dictDictionary to remove watcher from.
[in]key_patternPattern to remove watcher for.
[in]key_pattern_lenPattern length.
callbackCallback to remove watcher for.
Returns
True on success, false if relevant watcher was not found.
bool tv_equal ( typval_T *const  tv1,
typval_T *const  tv2,
const bool  ic,
const bool  recursive 
)

Compare two VimL values

Like "==", but strings and numbers are different, as well as floats and numbers.

Warning
Too nested structures may be considered equal even if they are not.
Parameters
[in]tv1First value to compare.
[in]tv2Second value to compare.
[in]icTrue if case is to be ignored.
[in]recursiveTrue when used recursively.
Returns
true if values are equal.
void tv_free ( typval_T tv)

Free allocated VimL object and value stored inside

Parameters
tvObject to free.
float_T tv_get_float ( const typval_T *const  tv)

Get the floating-point value of a VimL object

Raises an error if object is not number or floating-point.

Parameters
[in]tvObject to get value of.
Returns
Floating-point value of the variable or zero.
linenr_T tv_get_lnum ( const typval_T *const  tv)

Get the line number from VimL object

Parameters
[in]tvObject to get value from. Is expected to be a number or a special string like ".", "$", … (works with current buffer only).
Returns
Line number or -1 or 0.
varnumber_T tv_get_number ( const typval_T *const  tv)

Get the number value of a VimL object

Note
Use tv_get_number_chk() if you need to determine whether there was an error.
Parameters
[in]tvObject to get value from.
Returns
Number value: vim_str2nr() output for VAR_STRING objects, value for VAR_NUMBER objects, -1 for other types.
varnumber_T tv_get_number_chk ( const typval_T *const  tv,
bool *const  ret_error 
)

Get the number value of a VimL object

Parameters
[in]tvObject to get value from.
[out]ret_errorIf type error occurred then true will be written to this location. Otherwise it is not touched.
Note
Needs to be initialized to false to be useful.
Returns
Number value: vim_str2nr() output for VAR_STRING objects, value for VAR_NUMBER objects, -1 (ret_error == NULL) or 0 (otherwise) for other types.
const char* tv_get_string ( const typval_T *const  tv)

Get the string value of a "stringish" VimL object.

Warning
For number and special values it uses a single, static buffer. It may be used only once, next call to tv_get_string may reuse it. Use tv_get_string_buf() if you need to use tv_get_string() output after calling it again.
Note
tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return NULL on error.
Parameters
[in]tvObject to get value of.
Returns
Object value if it is VAR_STRING object, number converted to a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or empty string.
const char* tv_get_string_buf ( const typval_T *const  tv,
char *const  buf 
)

Get the string value of a "stringish" VimL object.

Note
tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return NULL on error.
Parameters
[in]tvObject to get value of.
bufBuffer used to hold numbers and special variables converted to string. When function encounters one of these stringified value will be written to buf and buf will be returned.

Buffer must have NUMBUFLEN size.

Returns
Object value if it is VAR_STRING object, number converted to a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or empty string.
const char* tv_get_string_buf_chk ( const typval_T *const  tv,
char *const  buf 
)

Get the string value of a "stringish" VimL object.

Parameters
[in]tvObject to get value of.
bufBuffer used to hold numbers and special variables converted to string. When function encounters one of these stringified value will be written to buf and buf will be returned.

Buffer must have NUMBUFLEN size.

Returns
Object value if it is VAR_STRING object, number converted to a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or NULL.
const char* tv_get_string_chk ( const typval_T *const  tv)

Get the string value of a "stringish" VimL object.

Warning
For number and special values it uses a single, static buffer. It may be used only once, next call to tv_get_string may reuse it. Use tv_get_string_buf() if you need to use tv_get_string() output after calling it again.
Parameters
[in]tvObject to get value of.
Returns
Object value if it is VAR_STRING object, number converted to a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or NULL.
bool tv_islocked ( const typval_T *const  tv)

Check whether VimL value is locked itself or refers to a locked container

Warning
Fixed container is not the same as locked.
Parameters
[in]tvValue to check.
Returns
True if value is locked, false otherwise.
void tv_item_lock ( typval_T *const  tv,
const int  deep,
const bool  lock 
)

Lock or unlock an item

Parameters
[out]tvItem to (un)lock.
[in]deepLevels to (un)lock, -1 to (un)lock everything.
[in]lockTrue if it is needed to lock an item, false to unlock.
list_T* tv_list_alloc ( const ptrdiff_t  len)

Allocate an empty list

Caller should take care of the reference count.

Parameters
[in]lenExpected number of items to be populated before list becomes accessible from VimL. It is still valid to underpopulate a list, value only controls how many elements will be allocated in advance. Currently does nothing.
See also
ListLenSpecials.
Returns
[allocated] new list.
list_T* tv_list_alloc_ret ( typval_T *const  ret_tv,
const ptrdiff_t  len 
)

Allocate an empty list for a return value

Also sets reference count.

Parameters
[out]ret_tvStructure where list is saved.
[in]lenExpected number of items to be populated before list becomes accessible from VimL. It is still valid to underpopulate a list, value only controls how many elements will be allocated in advance.
See also
ListLenSpecials.
Returns
[allocated] pointer to the created list.
void tv_list_drop_items ( list_T *const  l,
listitem_T *const  item,
listitem_T *const  item2 
)

Remove items "item" to "item2" from list "l"

Warning
Does not free the listitem or the value!
Parameters
[out]lList to remove from.
[in]itemFirst item to remove.
[in]item2Last item to remove.
bool tv_list_equal ( list_T *const  l1,
list_T *const  l2,
const bool  ic,
const bool  recursive 
)

Chech whether two lists are equal

Parameters
[in]l1First list to compare.
[in]l2Second list to compare.
[in]icTrue if case is to be ignored.
[in]recursiveTrue when used recursively.
Returns
True if lists are equal, false otherwise.
listitem_T* tv_list_find ( list_T *const  l,
int  n 
)

Locate item with a given index in a list and return it

Parameters
[in]lList to index.
[in]nIndex. Negative index is counted from the end, -1 is the last item.
Returns
Item at the given index or NULL if n is out of range.
varnumber_T tv_list_find_nr ( list_T *const  l,
const int  n,
bool *const  ret_error 
)

Get list item l[n] as a number

Parameters
[in]lList to index.
[in]nIndex in a list.
[out]ret_errorLocation where 1 will be saved if index was not found. May be NULL. If everything is OK, *ret_error is not touched.
Returns
Integer value at the given index or -1.
const char* tv_list_find_str ( list_T *const  l,
const int  n 
)

Get list item l[n] as a string

Parameters
[in]lList to index.
[in]nIndex in a list.
Returns
List item string value or NULL in case of error.
void tv_list_free ( list_T *const  l)

Free a list, including all items it points to

Ignores the reference count. Does not do anything if tv_in_free_unref_items is true.

Parameters
[in,out]lList to free.
void tv_list_free_contents ( list_T *const  l)

Free items contained in a list

Parameters
[in,out]lList to clear.
void tv_list_free_list ( list_T *const  l)

Free a list itself, ignoring items it contains

Ignores the reference count.

Parameters
[in,out]lList to free.
long tv_list_idx_of_item ( const list_T *const  l,
const listitem_T *const  item 
)

Locate item in a list and return its index

Parameters
[in]lList to search.
[in]itemItem to search for.
Returns
Index of an item or -1 if item is not in the list.
void tv_list_init_static ( list_T *const  l)

Initialize static list with undefined number of elements

Parameters
[out]lList to initialize.
void tv_list_init_static10 ( staticList10_T *const  sl)

Initialize a static list with 10 items

Parameters
[out]slStatic list to initialize.
void tv_list_insert ( list_T *const  l,
listitem_T *const  ni,
listitem_T *const  item 
)

Insert list item

Parameters
[out]lList to insert to.
[in,out]niItem to insert.
[in]itemItem to insert before. If NULL, inserts at the end of the list.
listitem_T* tv_list_item_remove ( list_T *const  l,
listitem_T *const  item 
)

Remove a list item from a List and free it

Also clears the value.

Parameters
[out]lList to remove item from.
[in,out]itemItem to remove.
Returns
Pointer to the list item just after removed one, NULL if removed item was the last one.
void tv_list_item_sort ( list_T *const  l,
ListSortItem *const  ptrs,
const ListSorter  item_compare_func,
bool *  errp 
)

Sort list using libc qsort

Parameters
[in,out]lList to sort, will be sorted in-place.
ptrsPreallocated array of items to sort, must have at least tv_list_len(l) entries. Should not be initialized.
[in]item_compare_funcFunction used to compare list items.
errpLocation where information about whether error occurred is saved by item_compare_func. If boolean there appears to be true list will not be modified. Must be initialized to false by the caller.
TV_LIST_ITER ( l  ,
li  ,
{ptrs[i].item=li;ptrs[i].idx=i;i++;}   
)
int tv_list_join ( garray_T *const  gap,
list_T *const  l,
const char *const  sep 
)

Join list into a string using given separator

Parameters
[out]gapGarray where result will be saved.
[in]lJoined list.
[in]sepSeparator.
Returns
OK in case of success, FAIL otherwise.
void tv_list_move_items ( list_T *const  l,
listitem_T *const  item,
listitem_T *const  item2,
list_T *const  tgt_l,
const int  cnt 
)

Move items "item" to "item2" from list "l" to the end of the list "tgt_l"

Parameters
[out]lList to move from.
[in]itemFirst item to move.
[in]item2Last item to move.
[out]tgt_lList to move to.
[in]cntNumber of items moved.
void tv_list_remove_items ( list_T *const  l,
listitem_T *const  item,
listitem_T *const  item2 
)

Like tv_list_drop_items, but also frees all removed items.

void tv_list_reverse ( list_T *const  l)

Reverse list in-place

Parameters
[in,out]lList to reverse.
void tv_list_unref ( list_T *const  l)

Unreference a list

Decrements the reference count and frees when it becomes zero or less.

Parameters
[in,out]lList to unreference.
void tv_list_watch_add ( list_T *const  l,
listwatch_T *const  lw 
)

Add a watcher to a list

Parameters
[out]lList to add watcher to.
[in]lwWatcher to add.
void tv_list_watch_fix ( list_T *const  l,
const listitem_T *const  item 
)

Advance watchers to the next item

Used just before removing an item from a list.

Parameters
[out]lList from which item is removed.
[in]itemList item being removed.
void tv_list_watch_remove ( list_T *const  l,
listwatch_T *const  lwrem 
)

Remove a watcher from a list

Does not give a warning if watcher was not found.

Parameters
[out]lList to remove watcher from.
[in]lwremWatcher to remove.

Variable Documentation

tv_copy & di = tv_dict_find(d, key, key_len)
argv [2] vval v_dict dv_refcount
bool FUNC_ATTR_WARN_UNUSED_RESULT
Initial value:
{
result->type = kCallbackNone
Definition: typval.h:71
int i = 0
return res = callback_from_typval(result, &tv)
fc rettv = rettv
tv_clear & tv
const char* const tv_empty_string = ""

Empty string

Needed for hack which allows not allocating empty string and still not crashing when freeing it.

bool tv_in_free_unref_items = false

Specifies that free_unref_items() function has (not) been entered.

argv [2] vval v_dict = dict
argv [2] v_lock = VAR_UNLOCKED
argv [1] vval v_string = (char_u *)xstrdup(key)
v di_tv v_type = VAR_DICT
QUEUE* w