Skip to content

Commit

Permalink
patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
yegappan authored and brammool committed Mar 7, 2023
1 parent 663ee88 commit 14113fd
Show file tree
Hide file tree
Showing 31 changed files with 126 additions and 109 deletions.
17 changes: 9 additions & 8 deletions src/dict.c
Expand Up @@ -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))
{
Expand Down Expand Up @@ -781,7 +781,7 @@ dict2string(typval_T *tv, int copyID, int restore_copyID)
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))
{
Expand Down Expand Up @@ -1114,7 +1114,8 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name)
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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -1233,7 +1234,7 @@ dict_count(dict_T *d, typval_T *needle, int ic)
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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -1502,7 +1503,7 @@ dict2list(typval_T *argvars, typval_T *rettv, dict2list_T what)
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))
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/diff.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/eval.c
Expand Up @@ -5415,7 +5415,7 @@ set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/evalfunc.c
Expand Up @@ -7825,7 +7825,7 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
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))
{
Expand Down
4 changes: 2 additions & 2 deletions src/evalvars.c
Expand Up @@ -2317,7 +2317,7 @@ item_lock(typval_T *tv, int deep, int lock, int check_refcount)
{
// 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))
{
Expand Down Expand Up @@ -3571,7 +3571,7 @@ vars_clear_ext(hashtab_T *ht, int free_val)

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))
{
Expand Down
51 changes: 0 additions & 51 deletions src/globals.h
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1050,16 +1025,6 @@ EXTERN buf_T *firstbuf INIT(= NULL); // first buffer
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/hashtab.c
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/if_mzsch.c
Expand Up @@ -3067,7 +3067,7 @@ vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited)
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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/if_ruby.c
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/job.c
Expand Up @@ -140,7 +140,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
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;
Expand Down
53 changes: 53 additions & 0 deletions src/macros.h
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions src/mbyte.c
Expand Up @@ -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.
Expand Down Expand Up @@ -5647,7 +5647,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
// 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;
Expand Down
18 changes: 14 additions & 4 deletions src/os_unix.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -5654,7 +5664,7 @@ mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal)
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;
Expand Down
10 changes: 5 additions & 5 deletions src/os_win32.c
Expand Up @@ -1308,9 +1308,9 @@ encode_key_event(dict_T *args, INPUT_RECORD *ir)
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;
Expand Down Expand Up @@ -2017,7 +2017,7 @@ test_mswin_event(char_u *event, dict_T *args)
}

// 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);
Expand Down Expand Up @@ -5737,7 +5737,7 @@ win32_build_env(dict_T *env, garray_T *gap, int is_terminal)

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))
{
Expand Down
3 changes: 1 addition & 2 deletions src/popupwin.c
Expand Up @@ -2413,8 +2413,7 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
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)
Expand Down

0 comments on commit 14113fd

Please sign in to comment.