comparison src/dict.c @ 29986:0ad8b72af148 v9.0.0331

patch 9.0.0331: cannot use items() on a string Commit: https://github.com/vim/vim/commit/3e518a8ec74065aedd67d352c93d6ae6be550316 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 30 17:45:33 2022 +0100 patch 9.0.0331: cannot use items() on a string Problem: Cannot use items() on a string. Solution: Make items() work on a string. (closes https://github.com/vim/vim/issues/11016)
author Bram Moolenaar <Bram@vim.org>
date Tue, 30 Aug 2022 19:00:03 +0200
parents 34151eb6ae25
children 86eb4aba16c3
comparison
equal deleted inserted replaced
29985:2860987502c1 29986:0ad8b72af148
1454 { 1454 {
1455 list_T *l2; 1455 list_T *l2;
1456 dictitem_T *di; 1456 dictitem_T *di;
1457 hashitem_T *hi; 1457 hashitem_T *hi;
1458 listitem_T *li; 1458 listitem_T *li;
1459 listitem_T *li2;
1460 dict_T *d; 1459 dict_T *d;
1461 int todo; 1460 int todo;
1462 1461
1463 if (rettv_list_alloc(rettv) == FAIL) 1462 if (rettv_list_alloc(rettv) == FAIL)
1464 return; 1463 return;
1465 1464
1466 if ((what == DICT2LIST_ITEMS 1465 if ((what == DICT2LIST_ITEMS
1467 ? check_for_list_or_dict_arg(argvars, 0) 1466 ? check_for_string_or_list_or_dict_arg(argvars, 0)
1468 : check_for_dict_arg(argvars, 0)) == FAIL) 1467 : check_for_dict_arg(argvars, 0)) == FAIL)
1469 return; 1468 return;
1470 1469
1471 d = argvars[0].vval.v_dict; 1470 d = argvars[0].vval.v_dict;
1472 if (d == NULL) 1471 if (d == NULL)
1507 li->li_tv.vval.v_list = l2; 1506 li->li_tv.vval.v_list = l2;
1508 if (l2 == NULL) 1507 if (l2 == NULL)
1509 break; 1508 break;
1510 ++l2->lv_refcount; 1509 ++l2->lv_refcount;
1511 1510
1512 li2 = listitem_alloc(); 1511 if (list_append_string(l2, di->di_key, -1) == FAIL
1513 if (li2 == NULL) 1512 || list_append_tv(l2, &di->di_tv) == FAIL)
1514 break; 1513 break;
1515 list_append(l2, li2);
1516 li2->li_tv.v_type = VAR_STRING;
1517 li2->li_tv.v_lock = 0;
1518 li2->li_tv.vval.v_string = vim_strsave(di->di_key);
1519
1520 li2 = listitem_alloc();
1521 if (li2 == NULL)
1522 break;
1523 list_append(l2, li2);
1524 copy_tv(&di->di_tv, &li2->li_tv);
1525 } 1514 }
1526 } 1515 }
1527 } 1516 }
1528 } 1517 }
1529 1518
1531 * "items(dict)" function 1520 * "items(dict)" function
1532 */ 1521 */
1533 void 1522 void
1534 f_items(typval_T *argvars, typval_T *rettv) 1523 f_items(typval_T *argvars, typval_T *rettv)
1535 { 1524 {
1536 if (argvars[0].v_type == VAR_LIST) 1525 if (argvars[0].v_type == VAR_STRING)
1526 string2items(argvars, rettv);
1527 else if (argvars[0].v_type == VAR_LIST)
1537 list2items(argvars, rettv); 1528 list2items(argvars, rettv);
1538 else 1529 else
1539 dict2list(argvars, rettv, DICT2LIST_ITEMS); 1530 dict2list(argvars, rettv, DICT2LIST_ITEMS);
1540 } 1531 }
1541 1532