changeset 32118:04d9dff67d99 v9.0.1390

patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file Commit: https://github.com/vim/vim/commit/14113fdf9cb3d588c0d1c3a210246b981cf5aad3 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Mar 7 17:13:51 2023 +0000 patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file Problem: FOR_ALL_ macros are defined in an unexpected file. Solution: Move FOR_ALL_ macros to macros.h. Add FOR_ALL_HASHTAB_ITEMS. (Yegappan Lakshmanan, closes #12109)
author Bram Moolenaar <Bram@vim.org>
date Tue, 07 Mar 2023 18:15:04 +0100
parents 0741cc777264
children 241396c61b36
files src/dict.c src/diff.c src/eval.c src/evalfunc.c src/evalvars.c src/globals.h src/hashtab.c src/if_mzsch.c src/if_ruby.c src/job.c src/macros.h src/mbyte.c src/os_unix.c src/os_win32.c src/popupwin.c src/profiler.c src/scriptfile.c src/session.c src/sign.c src/spellfile.c src/spellsuggest.c src/syntax.c src/testing.c src/textprop.c src/userfunc.c src/version.c src/vim9execute.c src/vim9script.c src/vim9type.c src/viminfo.c src/window.c
diffstat 31 files changed, 126 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/src/dict.c
+++ b/src/dict.c
@@ -128,7 +128,7 @@ hashtab_free_contents(hashtab_T *ht)
     // Lock the hashtab, we don't want it to resize while freeing items.
     hash_lock(ht);
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -781,7 +781,7 @@ dict2string(typval_T *tv, int copyID, in
     ga_append(&ga, '{');
 
     todo = (int)d->dv_hashtab.ht_used;
-    for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -1114,7 +1114,8 @@ dict_extend(dict_T *d1, dict_T *d2, char
 	type = NULL;
 
     todo = (int)d2->dv_hashtab.ht_used;
-    for (hashitem_T *hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2)
+    hashitem_T *hi2;
+    FOR_ALL_HASHTAB_ITEMS(&d2->dv_hashtab, hi2, todo)
     {
 	if (!HASHITEM_EMPTY(hi2))
 	{
@@ -1203,7 +1204,7 @@ dict_equal(
 	return FALSE;
 
     todo = (int)d1->dv_hashtab.ht_used;
-    for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&d1->dv_hashtab, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -1233,7 +1234,7 @@ dict_count(dict_T *d, typval_T *needle, 
 	return 0;
 
     todo = (int)d->dv_hashtab.ht_used;
-    for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -1369,7 +1370,7 @@ dict_filter_map(
     ht = &d->dv_hashtab;
     hash_lock(ht);
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -1502,7 +1503,7 @@ dict2list(typval_T *argvars, typval_T *r
 	return;
 
     todo = (int)d->dv_hashtab.ht_used;
-    for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -1587,7 +1588,7 @@ dict_set_items_ro(dict_T *di)
     hashitem_T	*hi;
 
     // Set readonly
-    for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&di->dv_hashtab, hi, todo)
     {
 	if (HASHITEM_EMPTY(hi))
 	    continue;
--- a/src/diff.c
+++ b/src/diff.c
@@ -2650,7 +2650,7 @@ valid_diff(diff_T *diff)
 {
     diff_T	*dp;
 
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
 	if (dp == diff)
 	    return TRUE;
     return FALSE;
--- a/src/eval.c
+++ b/src/eval.c
@@ -5415,7 +5415,7 @@ set_ref_in_ht(hashtab_T *ht, int copyID,
 	    // it is added to ht_stack, if it contains a list it is added to
 	    // list_stack.
 	    todo = (int)cur_ht->ht_used;
-	    for (hi = cur_ht->ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(cur_ht, hi, todo)
 		if (!HASHITEM_EMPTY(hi))
 		{
 		    --todo;
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -7825,7 +7825,7 @@ max_min(typval_T *argvars, typval_T *ret
 	if (d != NULL)
 	{
 	    todo = (int)d->dv_hashtab.ht_used;
-	    for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
 	    {
 		if (!HASHITEM_EMPTY(hi))
 		{
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2317,7 +2317,7 @@ item_lock(typval_T *tv, int deep, int lo
 		{
 		    // recursive: lock/unlock the items the List contains
 		    todo = (int)d->dv_hashtab.ht_used;
-		    for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+		    FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
 		    {
 			if (!HASHITEM_EMPTY(hi))
 			{
@@ -3571,7 +3571,7 @@ vars_clear_ext(hashtab_T *ht, int free_v
 
     hash_lock(ht);
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/globals.h
+++ b/src/globals.h
@@ -873,10 +873,6 @@ EXTERN vimmenu_T	*root_menu INIT(= NULL)
  * overruling of menus that the user already defined.
  */
 EXTERN int	sys_menu INIT(= FALSE);
-
-#define FOR_ALL_MENUS(m) for ((m) = root_menu; (m) != NULL; (m) = (m)->next)
-#define FOR_ALL_CHILD_MENUS(p, c) \
-    for ((c) = (p)->children; (c) != NULL; (c) = (c)->next)
 #endif
 
 #ifdef FEAT_GUI
@@ -968,27 +964,6 @@ EXTERN win_T	*lastwin;		// last window
 EXTERN win_T	*prevwin INIT(= NULL);	// previous window
 #define ONE_WINDOW (firstwin == lastwin)
 #define W_NEXT(wp) ((wp)->w_next)
-#define FOR_ALL_WINDOWS(wp) for ((wp) = firstwin; (wp) != NULL; (wp) = (wp)->w_next)
-#define FOR_ALL_FRAMES(frp, first_frame) \
-    for ((frp) = first_frame; (frp) != NULL; (frp) = (frp)->fr_next)
-#define FOR_ALL_TABPAGES(tp) for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next)
-#define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \
-    for ((wp) = ((tp) == NULL || (tp) == curtab) \
-	    ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
-/*
- * When using this macro "break" only breaks out of the inner loop. Use "goto"
- * to break out of the tabpage loop.
- */
-#define FOR_ALL_TAB_WINDOWS(tp, wp) \
-    for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next) \
-	for ((wp) = ((tp) == curtab) \
-		? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
-
-#define FOR_ALL_POPUPWINS(wp) \
-    for ((wp) = first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
-#define FOR_ALL_POPUPWINS_IN_TAB(tp, wp) \
-    for ((wp) = (tp)->tp_first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
-
 
 EXTERN win_T	*curwin;	// currently active window
 
@@ -1050,16 +1025,6 @@ EXTERN buf_T	*firstbuf INIT(= NULL);	// 
 EXTERN buf_T	*lastbuf INIT(= NULL);	// last buffer
 EXTERN buf_T	*curbuf INIT(= NULL);	// currently active buffer
 
-#define FOR_ALL_BUFFERS(buf) \
-    for ((buf) = firstbuf; (buf) != NULL; (buf) = (buf)->b_next)
-
-#define FOR_ALL_BUF_WININFO(buf, wip) \
-    for ((wip) = (buf)->b_wininfo; (wip) != NULL; (wip) = (wip)->wi_next)
-
-// Iterate through all the signs placed in a buffer
-#define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
-	for ((sign) = (buf)->b_signlist; (sign) != NULL; (sign) = (sign)->se_next)
-
 // Flag that is set when switching off 'swapfile'.  It means that all blocks
 // are to be loaded into memory.  Shouldn't be global...
 EXTERN int	mf_dont_release INIT(= FALSE);	// don't release blocks
@@ -1874,9 +1839,6 @@ EXTERN disptick_T	display_tick INIT(= 0)
 // Line in which spell checking wasn't highlighted because it touched the
 // cursor position in Insert mode.
 EXTERN linenr_T		spell_redraw_lnum INIT(= 0);
-
-#define FOR_ALL_SPELL_LANGS(slang) \
-    for ((slang) = first_lang; (slang) != NULL; (slang) = (slang)->sl_next)
 #endif
 
 #ifdef FEAT_CONCEAL
@@ -2015,11 +1977,6 @@ EXTERN char *ch_part_names[]
 
 // Whether a redraw is needed for appending a line to a buffer.
 EXTERN int channel_need_redraw INIT(= FALSE);
-
-# define FOR_ALL_CHANNELS(ch) \
-    for ((ch) = first_channel; (ch) != NULL; (ch) = (ch)->ch_next)
-# define FOR_ALL_JOBS(job) \
-    for ((job) = first_job; (job) != NULL; (job) = (job)->jv_next)
 #endif
 
 #ifdef FEAT_EVAL
@@ -2032,14 +1989,6 @@ EXTERN int did_repeated_msg INIT(= 0);
 # define REPEATED_MSG_SAFESTATE	    2
 #endif
 
-#if defined(FEAT_DIFF)
-#define FOR_ALL_DIFFBLOCKS_IN_TAB(tp, dp) \
-    for ((dp) = (tp)->tp_first_diff; (dp) != NULL; (dp) = (dp)->df_next)
-#endif
-
-#define FOR_ALL_LIST_ITEMS(l, li) \
-    for ((li) = (l) == NULL ? NULL : (l)->lv_first; (li) != NULL; (li) = (li)->li_next)
-
 // While executing a regexp and set to OPTION_MAGIC_ON or OPTION_MAGIC_OFF this
 // overrules p_magic.  Otherwise set to OPTION_MAGIC_NOT_SET.
 EXTERN optmagic_T magic_overruled INIT(= OPTION_MAGIC_NOT_SET);
--- a/src/hashtab.c
+++ b/src/hashtab.c
@@ -108,7 +108,7 @@ hash_clear_all(hashtab_T *ht, int off)
     hashitem_T	*hi;
 
     todo = (long)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -3067,7 +3067,7 @@ vim_to_mzscheme_impl(typval_T *vim_value
 	    hashitem_T	*hi;
 	    dictitem_T	*di;
 
-	    for (hi = ht->ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
 	    {
 		if (!HASHITEM_EMPTY(hi))
 		{
--- a/src/if_ruby.c
+++ b/src/if_ruby.c
@@ -1147,7 +1147,7 @@ vim_to_ruby(typval_T *tv)
 	    hashitem_T  *hi;
 	    dictitem_T  *di;
 
-	    for (hi = ht->ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
 	    {
 		if (!HASHITEM_EMPTY(hi))
 		{
--- a/src/job.c
+++ b/src/job.c
@@ -140,7 +140,7 @@ get_job_options(typval_T *tv, jobopt_T *
 	return OK;
 
     todo = (int)dict->dv_hashtab.ht_used;
-    for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&dict->dv_hashtab, hi, todo)
 	if (!HASHITEM_EMPTY(hi))
 	{
 	    item = &dict_lookup(hi)->di_tv;
--- a/src/macros.h
+++ b/src/macros.h
@@ -396,3 +396,56 @@
 
 // Length of the array.
 #define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
+
+#ifdef FEAT_MENU
+#define FOR_ALL_MENUS(m) \
+    for ((m) = root_menu; (m) != NULL; (m) = (m)->next)
+#define FOR_ALL_CHILD_MENUS(p, c) \
+    for ((c) = (p)->children; (c) != NULL; (c) = (c)->next)
+#endif
+
+#define FOR_ALL_WINDOWS(wp) \
+    for ((wp) = firstwin; (wp) != NULL; (wp) = (wp)->w_next)
+#define FOR_ALL_FRAMES(frp, first_frame) \
+    for ((frp) = first_frame; (frp) != NULL; (frp) = (frp)->fr_next)
+#define FOR_ALL_TABPAGES(tp) \
+    for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next)
+#define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \
+    for ((wp) = ((tp) == NULL || (tp) == curtab) \
+	    ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
+/*
+ * When using this macro "break" only breaks out of the inner loop. Use "goto"
+ * to break out of the tabpage loop.
+ */
+#define FOR_ALL_TAB_WINDOWS(tp, wp) \
+    for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next) \
+	for ((wp) = ((tp) == curtab) \
+		? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
+
+#define FOR_ALL_POPUPWINS(wp) \
+    for ((wp) = first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
+#define FOR_ALL_POPUPWINS_IN_TAB(tp, wp) \
+    for ((wp) = (tp)->tp_first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
+
+#define FOR_ALL_BUFFERS(buf) \
+    for ((buf) = firstbuf; (buf) != NULL; (buf) = (buf)->b_next)
+
+#define FOR_ALL_BUF_WININFO(buf, wip) \
+    for ((wip) = (buf)->b_wininfo; (wip) != NULL; (wip) = (wip)->wi_next)
+
+// Iterate through all the signs placed in a buffer
+#define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
+    for ((sign) = (buf)->b_signlist; (sign) != NULL; (sign) = (sign)->se_next)
+
+#ifdef FEAT_SPELL
+#define FOR_ALL_SPELL_LANGS(slang) \
+    for ((slang) = first_lang; (slang) != NULL; (slang) = (slang)->sl_next)
+#endif
+
+// Iterate over all the items in a List
+#define FOR_ALL_LIST_ITEMS(l, li) \
+    for ((li) = (l) == NULL ? NULL : (l)->lv_first; (li) != NULL; (li) = (li)->li_next)
+
+// Iterate over all the items in a hash table
+#define FOR_ALL_HASHTAB_ITEMS(ht, hi, todo) \
+    for ((hi) = (ht)->ht_array; (todo) > 0; ++(hi))
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -1579,7 +1579,7 @@ utf_char2cells(int c)
 	// values of them.
 	//
 	// Note that these symbols are of varying widths, as they are symbols
-	// representing differents things ranging from a simple gear icon to an
+	// representing different things ranging from a simple gear icon to an
 	// airplane. Some of them are in fact wider than double-width, but Vim
 	// doesn't support non-fixed-width font, and tagging them as
 	// double-width is the best way to handle them.
@@ -5647,7 +5647,7 @@ f_setcellwidths(typval_T *argvars, typva
     // Check that all entries are a list with three numbers, the range is
     // valid and the cell width is valid.
     item = 0;
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
 	listitem_T *lili;
 	varnumber_T n1;
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2335,10 +2335,20 @@ mch_restore_title(int which)
 {
     int	do_push_pop = unix_did_set_title || did_set_icon;
 
-    // only restore the title or icon when it has been set
-    mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ?
-			(oldtitle ? oldtitle : p_titleold) : NULL,
+    // Only restore the title or icon when it has been set.
+    // When using "oldtitle" make a copy, it might be freed halfway.
+    char_u *title = ((which & SAVE_RESTORE_TITLE) && unix_did_set_title)
+			? (oldtitle ? oldtitle : p_titleold) : NULL;
+    char_u *tofree = NULL;
+    if (title == oldtitle && oldtitle != NULL)
+    {
+	tofree = vim_strsave(title);
+	if (tofree != NULL)
+	    title = tofree;
+    }
+    mch_settitle(title,
 	       ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL);
+    vim_free(tofree);
 
     if (do_push_pop)
     {
@@ -5654,7 +5664,7 @@ mch_job_start(char **argv, job_T *job, j
 	    hashitem_T	*hi;
 	    int		todo = (int)dict->dv_hashtab.ht_used;
 
-	    for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&dict->dv_hashtab, hi, todo)
 		if (!HASHITEM_EMPTY(hi))
 		{
 		    typval_T *item = &dict_lookup(hi)->di_tv;
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -1308,9 +1308,9 @@ encode_key_event(dict_T *args, INPUT_REC
 	if (mods)
 	{
 	    // If "modifiers" is explicitly set in the args, then we reset any
-	    // remembered modifer key state that may have been set from earlier
-	    // mod-key-down events, even if they are not yet unset by earlier
-	    // mod-key-up events.
+	    // remembered modifier key state that may have been set from
+	    // earlier mod-key-down events, even if they are not yet unset by
+	    // earlier mod-key-up events.
 	    s_dwMods = 0;
 	    if (mods & MOD_MASK_SHIFT)
 		ker.dwControlKeyState |= SHIFT_PRESSED;
@@ -2017,7 +2017,7 @@ test_mswin_event(char_u *event, dict_T *
     }
 
     // Ideally, WriteConsoleInput would be used to inject these low-level
-    // events.  But, this doesnt work well in the CI test environment.  So
+    // events.  But, this doesn't work well in the CI test environment.  So
     // implementing an input_record_buffer instead.
     if (input_encoded)
 	lpEventsWritten = write_input_record_buffer(&ir, 1);
@@ -5737,7 +5737,7 @@ win32_build_env(dict_T *env, garray_T *g
 
     if (env != NULL)
     {
-	for (hi = env->dv_hashtab.ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(&env->dv_hashtab, hi, todo)
 	{
 	    if (!HASHITEM_EMPTY(hi))
 	    {
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -2413,8 +2413,7 @@ popup_close_and_callback(win_T *wp, typv
 	    win_enter(owp, FALSE);
 	else
 	{
-	    for (owp = curtab->tp_first_popupwin; owp != NULL;
-							     owp = owp->w_next)
+	    FOR_ALL_POPUPWINS_IN_TAB(curtab, owp)
 		if (owp != curwin && owp->w_buffer->b_term != NULL)
 		    break;
 	    if (owp != NULL)
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -335,7 +335,7 @@ profile_reset(void)
     functbl = func_tbl_get();
     todo = (int)functbl->ht_used;
 
-    for (hi = functbl->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
     {
 	ufunc_T *fp;
 	int	i;
@@ -825,7 +825,7 @@ func_dump_profile(FILE *fd)
 
     sorttab = ALLOC_MULT(ufunc_T *, todo);
 
-    for (hi = functbl->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1672,7 +1672,7 @@ do_source_ext(
 		// is encountered without the "noclear" argument.
 		ht = &SCRIPT_VARS(sid);
 		todo = (int)ht->ht_used;
-		for (hi = ht->ht_array; todo > 0; ++hi)
+		FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
 		    if (!HASHITEM_EMPTY(hi))
 		    {
 			--todo;
@@ -2063,7 +2063,7 @@ get_script_local_funcs(scid_T sid)
     // looking for functions with script ID 'sid'.
     functbl = func_tbl_get();
     todo = functbl->ht_used;
-    for (hi = functbl->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
     {
 	ufunc_T	*fp;
 
--- a/src/session.c
+++ b/src/session.c
@@ -543,7 +543,7 @@ store_session_globals(FILE *fd)
     char_u	*p, *t;
 
     todo = (int)gvht->ht_used;
-    for (hi = gvht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(gvht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/sign.c
+++ b/src/sign.c
@@ -2058,7 +2058,7 @@ get_nth_sign_group_name(int idx)
     // Complete with name of sign groups already defined
     current_idx = 0;
     todo = (int)sg_table.ht_used;
-    for (hi = sg_table.ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(&sg_table, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/spellfile.c
+++ b/src/spellfile.c
@@ -3466,7 +3466,7 @@ spell_free_aff(afffile_T *aff)
     for (ht = &aff->af_pref; ; ht = &aff->af_suff)
     {
 	todo = (int)ht->ht_used;
-	for (hi = ht->ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
 	{
 	    if (!HASHITEM_EMPTY(hi))
 	    {
@@ -5117,7 +5117,7 @@ write_vim_spell(spellinfo_T *spin, char_
 	    hashitem_T	*hi;
 
 	    todo = (int)spin->si_commonwords.ht_used;
-	    for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&spin->si_commonwords, hi, todo)
 		if (!HASHITEM_EMPTY(hi))
 		{
 		    l = (int)STRLEN(hi->hi_key) + 1;
--- a/src/spellsuggest.c
+++ b/src/spellsuggest.c
@@ -3176,7 +3176,7 @@ suggest_try_soundalike_finish(void)
 	{
 	    // Free the info about handled words.
 	    todo = (int)slang->sl_sounddone.ht_used;
-	    for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&slang->sl_sounddone, hi, todo)
 		if (!HASHITEM_EMPTY(hi))
 		{
 		    vim_free(HI2SFT(hi));
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -4323,7 +4323,7 @@ syn_clear_keyword(int id, hashtab_T *ht)
 
     hash_lock(ht);
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -4371,7 +4371,7 @@ clear_keywtab(hashtab_T *ht)
     keyentry_T	*kp_next;
 
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/testing.c
+++ b/src/testing.c
@@ -181,7 +181,7 @@ fill_assert_error(
 		return;
 
 	    todo = (int)exp_d->dv_hashtab.ht_used;
-	    for (hi = exp_d->dv_hashtab.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&exp_d->dv_hashtab, hi, todo)
 	    {
 		if (!HASHITEM_EMPTY(hi))
 		{
@@ -204,7 +204,7 @@ fill_assert_error(
 
 	    // Add items only present in got_d.
 	    todo = (int)got_d->dv_hashtab.ht_used;
-	    for (hi = got_d->dv_hashtab.ht_array; todo > 0; ++hi)
+	    FOR_ALL_HASHTAB_ITEMS(&got_d->dv_hashtab, hi, todo)
 	    {
 		if (!HASHITEM_EMPTY(hi))
 		{
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -723,7 +723,8 @@ count_props(linenr_T lnum, int only_star
 static textprop_T	*text_prop_compare_props;
 static buf_T		*text_prop_compare_buf;
 
-/* Score for sorting on position of the text property: 0: above,
+/*
+ * Score for sorting on position of the text property: 0: above,
  * 1: after (default), 2: right, 3: below (comes last)
  */
     static int
@@ -933,7 +934,7 @@ find_type_by_id(hashtab_T *ht, proptype_
 	if (*array == NULL)
 	    return NULL;
 	todo = (long)ht->ht_used;
-	for (hi = ht->ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
 	{
 	    if (!HASHITEM_EMPTY(hi))
 	    {
@@ -1958,7 +1959,7 @@ f_prop_type_delete(typval_T *argvars, ty
     hash_remove(ht, hi, "prop type delete");
     vim_free(prop);
 
-    // currently visibile text properties will disappear
+    // currently visible text properties will disappear
     redraw_all_later(UPD_CLEAR);
     changed_window_setting_buf(buf == NULL ? curbuf : buf);
 }
@@ -2021,7 +2022,7 @@ list_types(hashtab_T *ht, list_T *l)
     hashitem_T	*hi;
 
     todo = (long)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
@@ -2074,7 +2075,7 @@ clear_ht_prop_types(hashtab_T *ht)
 	return;
 
     todo = (long)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2313,7 +2313,7 @@ cleanup_function_call(funccall_T *fc)
 
 	// Make a copy of the a: variables, since we didn't do that above.
 	todo = (int)fc->fc_l_avars.dv_hashtab.ht_used;
-	for (hi = fc->fc_l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(&fc->fc_l_avars.dv_hashtab, hi, todo)
 	{
 	    if (!HASHITEM_EMPTY(hi))
 	    {
@@ -3296,7 +3296,7 @@ delete_script_functions(int sid)
     while (todo > 0)
     {
 	todo = func_hashtab.ht_used;
-	for (hi = func_hashtab.ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(&func_hashtab, hi, todo)
 	    if (!HASHITEM_EMPTY(hi))
 	    {
 		fp = HI2UF(hi);
@@ -3353,7 +3353,7 @@ free_all_functions(void)
     while (todo > 0)
     {
 	todo = func_hashtab.ht_used;
-	for (hi = func_hashtab.ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(&func_hashtab, hi, todo)
 	    if (!HASHITEM_EMPTY(hi))
 	    {
 		// clear the def function index now
@@ -3385,7 +3385,7 @@ free_all_functions(void)
     while (func_hashtab.ht_used > skipped)
     {
 	todo = func_hashtab.ht_used;
-	for (hi = func_hashtab.ht_array; todo > 0; ++hi)
+	FOR_ALL_HASHTAB_ITEMS(&func_hashtab, hi, todo)
 	    if (!HASHITEM_EMPTY(hi))
 	    {
 		--todo;
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1390,
+/**/
     1389,
 /**/
     1388,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1052,7 +1052,7 @@ invoke_defer_funcs(ectx_T *ectx)
 
     if (defer_tv->v_type != VAR_LIST)
 	return;	 // no function added
-    for (li = defer_tv->vval.v_list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(defer_tv->vval.v_list, li)
     {
 	list_T	    *l = li->li_tv.vval.v_list;
 	typval_T    rettv;
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -281,7 +281,7 @@ free_all_script_vars(scriptitem_T *si)
 
     hash_lock(ht);
     todo = (int)ht->ht_used;
-    for (hi = ht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -213,7 +213,7 @@ set_tv_type(typval_T *tv, type_T *type)
 		hashitem_T	*hi;
 		dictitem_T	*di;
 
-		for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+		FOR_ALL_HASHTAB_ITEMS(&d->dv_hashtab, hi, todo)
 		{
 		    if (!HASHITEM_EMPTY(hi))
 		    {
--- a/src/viminfo.c
+++ b/src/viminfo.c
@@ -1319,7 +1319,7 @@ write_viminfo_varlist(FILE *fp)
     fputs(_("\n# global variables:\n"), fp);
 
     todo = (int)gvht->ht_used;
-    for (hi = gvht->ht_array; todo > 0; ++hi)
+    FOR_ALL_HASHTAB_ITEMS(gvht, hi, todo)
     {
 	if (!HASHITEM_EMPTY(hi))
 	{
--- a/src/window.c
+++ b/src/window.c
@@ -5622,7 +5622,7 @@ win_free(
 		// If there already is an entry with "wi_win" set to NULL it
 		// must be removed, it would never be used.
 		// Skip "wip" itself, otherwise Coverity complains.
-		for (wip2 = buf->b_wininfo; wip2 != NULL; wip2 = wip2->wi_next)
+		FOR_ALL_BUF_WININFO(buf, wip2)
 		    if (wip2 != wip && wip2->wi_win == NULL)
 		    {
 			if (wip2->wi_next != NULL)
@@ -7378,7 +7378,7 @@ reset_lnums(void)
 
 /*
  * A snapshot of the window sizes, to restore them after closing the help
- * window.
+ * or other window.
  * Only these fields are used:
  * fr_layout
  * fr_width
@@ -7390,6 +7390,7 @@ reset_lnums(void)
 
 /*
  * Create a snapshot of the current frame sizes.
+ * "idx" is SNAP_HELP_IDX or SNAP_AUCMD_IDX.
  */
     void
 make_snapshot(int idx)
@@ -7473,6 +7474,7 @@ get_snapshot_curwin(int idx)
  * Restore a previously created snapshot, if there is any.
  * This is only done if the screen size didn't change and the window layout is
  * still the same.
+ * "idx" is SNAP_HELP_IDX or SNAP_AUCMD_IDX.
  */
     void
 restore_snapshot(