summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-30 17:45:33 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-30 17:45:33 +0100
commit3e518a8ec74065aedd67d352c93d6ae6be550316 (patch)
tree239505fa04b1012bfccad56d6cc3f7f6517bfe78 /src/dict.c
parentf92cfb1acc3fef74eef0c83c1a35a2b6a9f93a9b (diff)
patch 9.0.0331: cannot use items() on a stringv9.0.0331
Problem: Cannot use items() on a string. Solution: Make items() work on a string. (closes #11016)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/dict.c b/src/dict.c
index 6bac4d5416..58fd68a6f3 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -1456,7 +1456,6 @@ dict2list(typval_T *argvars, typval_T *rettv, dict2list_T what)
dictitem_T *di;
hashitem_T *hi;
listitem_T *li;
- listitem_T *li2;
dict_T *d;
int todo;
@@ -1464,7 +1463,7 @@ dict2list(typval_T *argvars, typval_T *rettv, dict2list_T what)
return;
if ((what == DICT2LIST_ITEMS
- ? check_for_list_or_dict_arg(argvars, 0)
+ ? check_for_string_or_list_or_dict_arg(argvars, 0)
: check_for_dict_arg(argvars, 0)) == FAIL)
return;
@@ -1509,19 +1508,9 @@ dict2list(typval_T *argvars, typval_T *rettv, dict2list_T what)
break;
++l2->lv_refcount;
- li2 = listitem_alloc();
- if (li2 == NULL)
+ if (list_append_string(l2, di->di_key, -1) == FAIL
+ || list_append_tv(l2, &di->di_tv) == FAIL)
break;
- list_append(l2, li2);
- li2->li_tv.v_type = VAR_STRING;
- li2->li_tv.v_lock = 0;
- li2->li_tv.vval.v_string = vim_strsave(di->di_key);
-
- li2 = listitem_alloc();
- if (li2 == NULL)
- break;
- list_append(l2, li2);
- copy_tv(&di->di_tv, &li2->li_tv);
}
}
}
@@ -1533,7 +1522,9 @@ dict2list(typval_T *argvars, typval_T *rettv, dict2list_T what)
void
f_items(typval_T *argvars, typval_T *rettv)
{
- if (argvars[0].v_type == VAR_LIST)
+ if (argvars[0].v_type == VAR_STRING)
+ string2items(argvars, rettv);
+ else if (argvars[0].v_type == VAR_LIST)
list2items(argvars, rettv);
else
dict2list(argvars, rettv, DICT2LIST_ITEMS);