summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-01-04 14:32:48 +0100
committerBram Moolenaar <Bram@vim.org>2020-01-04 14:32:48 +0100
commit0892832bb6c7e322fcae8560eaad5a8140ee4a06 (patch)
treed45503cc14259ea6c44cb63f26b69a6bfb4bfc3c /src/dict.c
parent5cb0b93d52fa5c12ca50a18509947ee6459bb7a8 (diff)
patch 8.2.0084: complete item "user_data" can only be a stringv8.2.0084
Problem: Complete item "user_data" can only be a string. Solution: Accept any type of variable. (closes #5412)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/dict.c b/src/dict.c
index 5022a5fd01..f170937b61 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -448,6 +448,27 @@ dict_add_list(dict_T *d, char *key, list_T *list)
}
/*
+ * Add a typval_T entry to dictionary "d".
+ * Returns FAIL when out of memory and when key already exists.
+ */
+ int
+dict_add_tv(dict_T *d, char *key, typval_T *tv)
+{
+ dictitem_T *item;
+
+ item = dictitem_alloc((char_u *)key);
+ if (item == NULL)
+ return FAIL;
+ copy_tv(tv, &item->di_tv);
+ if (dict_add(d, item) == FAIL)
+ {
+ dictitem_free(item);
+ return FAIL;
+ }
+ return OK;
+}
+
+/*
* Add a callback to dictionary "d".
* Returns FAIL when out of memory and when key already exists.
*/
@@ -590,6 +611,23 @@ dict_find(dict_T *d, char_u *key, int len)
}
/*
+ * Get a typval_T item from a dictionary and copy it into "rettv".
+ * Returns FAIL if the entry doesn't exist or out of memory.
+ */
+ int
+dict_get_tv(dict_T *d, char_u *key, typval_T *rettv)
+{
+ dictitem_T *di;
+ char_u *s;
+
+ di = dict_find(d, key, -1);
+ if (di == NULL)
+ return FAIL;
+ copy_tv(&di->di_tv, rettv);
+ return OK;
+}
+
+/*
* Get a string item from a dictionary.
* When "save" is TRUE allocate memory for it.
* When FALSE a shared buffer is used, can only be used once!
@@ -745,7 +783,7 @@ get_literal_key(char_u **arg, typval_T *tv)
* Return OK or FAIL. Returns NOTDONE for {expr}.
*/
int
-dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal)
+eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
{
dict_T *d = NULL;
typval_T tvkey;