Skip to content

Commit

Permalink
patch 8.0.1688: some macros are used without a semicolon
Browse files Browse the repository at this point in the history
Problem:    Some macros are used without a semicolon, causing auto-indent to be
            wrong.
Solution:   Use the do-while(0) trick. (Ozaki Kiichi, closes #2729)
  • Loading branch information
brammool committed Apr 10, 2018
1 parent d6b4f2d commit 6f47002
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/buffer.c
Expand Up @@ -1764,7 +1764,7 @@ enter_buffer(buf_T *buf)
#endif #endif


/* Change directories when the 'acd' option is set. */ /* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR DO_AUTOCHDIR;


#ifdef FEAT_KEYMAP #ifdef FEAT_KEYMAP
if (curbuf->b_kmap_state & KEYMAP_INIT) if (curbuf->b_kmap_state & KEYMAP_INIT)
Expand Down
9 changes: 8 additions & 1 deletion src/dosinst.c
Expand Up @@ -23,7 +23,14 @@
#define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll"


/* Macro to do an error check I was typing over and over */ /* Macro to do an error check I was typing over and over */
#define CHECK_REG_ERROR(code) if (code != ERROR_SUCCESS) { printf("%ld error number: %ld\n", (long)__LINE__, (long)code); return 1; } #define CHECK_REG_ERROR(code) \
do { \
if (code != ERROR_SUCCESS) \
{ \
printf("%ld error number: %ld\n", (long)__LINE__, (long)code); \
return 1; \
} \
} while (0)


int has_vim = 0; /* installable vim.exe exists */ int has_vim = 0; /* installable vim.exe exists */
int has_gvim = 0; /* installable gvim.exe exists */ int has_gvim = 0; /* installable gvim.exe exists */
Expand Down
6 changes: 3 additions & 3 deletions src/ex_cmds.c
Expand Up @@ -2996,7 +2996,7 @@ rename_buffer(char_u *new_fname)
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);


/* Change directories when the 'acd' option is set. */ /* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR DO_AUTOCHDIR;
return OK; return OK;
} }


Expand Down Expand Up @@ -3254,7 +3254,7 @@ do_write(exarg_T *eap)
* got changed or set. */ * got changed or set. */
if (eap->cmdidx == CMD_saveas || name_was_missing) if (eap->cmdidx == CMD_saveas || name_was_missing)
{ {
DO_AUTOCHDIR DO_AUTOCHDIR;
} }
} }


Expand Down Expand Up @@ -4147,7 +4147,7 @@ do_ecmd(
#endif #endif


/* Change directories when the 'acd' option is set. */ /* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR DO_AUTOCHDIR;


/* /*
* Careful: open_buffer() and apply_autocmds() may change the current * Careful: open_buffer() and apply_autocmds() may change the current
Expand Down
6 changes: 5 additions & 1 deletion src/gui_at_sb.c
Expand Up @@ -645,7 +645,11 @@ Redisplay(Widget w, XEvent *event, Region region)
static Boolean static Boolean
CompareEvents(XEvent *oldEvent, XEvent *newEvent) CompareEvents(XEvent *oldEvent, XEvent *newEvent)
{ {
#define Check(field) if (newEvent->field != oldEvent->field) return False; #define Check(field) \
do { \
if (newEvent->field != oldEvent->field) \
return False; \
} while (0)


Check(xany.display); Check(xany.display);
Check(xany.type); Check(xany.type);
Expand Down
8 changes: 4 additions & 4 deletions src/macros.h
Expand Up @@ -230,9 +230,9 @@
#endif #endif


#ifdef STARTUPTIME #ifdef STARTUPTIME
# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); } # define TIME_MSG(s) do { if (time_fd != NULL) time_msg(s, NULL); } while (0)
#else #else
# define TIME_MSG(s) # define TIME_MSG(s) do { /**/ } while (0)
#endif #endif


#ifdef FEAT_VREPLACE #ifdef FEAT_VREPLACE
Expand Down Expand Up @@ -289,9 +289,9 @@
#endif #endif


#ifdef FEAT_AUTOCHDIR #ifdef FEAT_AUTOCHDIR
# define DO_AUTOCHDIR if (p_acd) do_autochdir(); # define DO_AUTOCHDIR do { if (p_acd) do_autochdir(); } while (0)
#else #else
# define DO_AUTOCHDIR # define DO_AUTOCHDIR do { /**/ } while (0)
#endif #endif


#define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE #define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -824,7 +824,7 @@ vim_main2(void)
no_wait_return = FALSE; no_wait_return = FALSE;


/* 'autochdir' has been postponed */ /* 'autochdir' has been postponed */
DO_AUTOCHDIR DO_AUTOCHDIR;


#ifdef FEAT_TERMRESPONSE #ifdef FEAT_TERMRESPONSE
/* Requesting the termresponse is postponed until here, so that a "-c q" /* Requesting the termresponse is postponed until here, so that a "-c q"
Expand Down
4 changes: 2 additions & 2 deletions src/memline.c
Expand Up @@ -8,8 +8,8 @@
*/ */


/* for debugging */ /* for debugging */
/* #define CHECK(c, s) if (c) EMSG(s) */ /* #define CHECK(c, s) do { if (c) EMSG(s); } while (0) */
#define CHECK(c, s) #define CHECK(c, s) do { /**/ } while (0)


/* /*
* memline.c: Contains the functions for appending, deleting and changing the * memline.c: Contains the functions for appending, deleting and changing the
Expand Down
2 changes: 1 addition & 1 deletion src/option.c
Expand Up @@ -8456,7 +8456,7 @@ set_bool_option(
else if ((int *)varp == &p_acd) else if ((int *)varp == &p_acd)
{ {
/* Change directories when the 'acd' option is set now. */ /* Change directories when the 'acd' option is set now. */
DO_AUTOCHDIR DO_AUTOCHDIR;
} }
#endif #endif


Expand Down
2 changes: 1 addition & 1 deletion src/os_vms.c
Expand Up @@ -83,7 +83,7 @@ static void set_tty(int row, int col);
#define EXPL_ALLOC_INC 64 #define EXPL_ALLOC_INC 64


#define EQN(S1,S2,LN) (strncmp(S1,S2,LN) == 0) #define EQN(S1,S2,LN) (strncmp(S1,S2,LN) == 0)
#define SKIP_FOLLOWING_SLASHES(Str) while (Str[1] == '/') ++Str #define SKIP_FOLLOWING_SLASHES(Str) do { while (Str[1] == '/') ++Str; } while (0)




/* /*
Expand Down
22 changes: 14 additions & 8 deletions src/screen.c
Expand Up @@ -2705,15 +2705,21 @@ fold_line(
} }


#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
# define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ # define RL_MEMSET(p, v, l) \
for (ri = 0; ri < l; ++ri) \ do { \
ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \ if (wp->w_p_rl) \
else \ for (ri = 0; ri < l; ++ri) \
for (ri = 0; ri < l; ++ri) \ ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \
ScreenAttrs[off + (p) + ri] = v else \
for (ri = 0; ri < l; ++ri) \
ScreenAttrs[off + (p) + ri] = v; \
} while (0)
#else #else
# define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ # define RL_MEMSET(p, v, l) \
ScreenAttrs[off + (p) + ri] = v do { \
for (ri = 0; ri < l; ++ri) \
ScreenAttrs[off + (p) + ri] = v; \
} while (0)
#endif #endif


/* Set all attributes of the 'number' or 'relativenumber' column and the /* Set all attributes of the 'number' or 'relativenumber' column and the
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -762,6 +762,8 @@ static char *(features[]) =


static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1688,
/**/ /**/
1687, 1687,
/**/ /**/
Expand Down
59 changes: 33 additions & 26 deletions src/window.c
Expand Up @@ -99,9 +99,16 @@ do_window(
Prenum1 = Prenum; Prenum1 = Prenum;


#ifdef FEAT_CMDWIN #ifdef FEAT_CMDWIN
# define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; } # define CHECK_CMDWIN \
do { \
if (cmdwin_type != 0) \
{ \
EMSG(_(e_cmdwin)); \
return; \
} \
} while (0)
#else #else
# define CHECK_CMDWIN # define CHECK_CMDWIN do { /**/ } while (0)
#endif #endif


switch (nchar) switch (nchar)
Expand All @@ -110,7 +117,7 @@ do_window(
case 'S': case 'S':
case Ctrl_S: case Ctrl_S:
case 's': case 's':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
/* When splitting the quickfix window open a new buffer in it, /* When splitting the quickfix window open a new buffer in it,
Expand All @@ -127,7 +134,7 @@ do_window(
/* split current window in two parts, vertically */ /* split current window in two parts, vertically */
case Ctrl_V: case Ctrl_V:
case 'v': case 'v':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
/* When splitting the quickfix window open a new buffer in it, /* When splitting the quickfix window open a new buffer in it,
Expand All @@ -144,7 +151,7 @@ do_window(
/* split current window and edit alternate file */ /* split current window and edit alternate file */
case Ctrl_HAT: case Ctrl_HAT:
case '^': case '^':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
cmd_with_count("split #", cbuf, sizeof(cbuf), Prenum); cmd_with_count("split #", cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf); do_cmdline_cmd(cbuf);
Expand All @@ -153,7 +160,7 @@ do_window(
/* open new window */ /* open new window */
case Ctrl_N: case Ctrl_N:
case 'n': case 'n':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
newwindow: newwindow:
Expand Down Expand Up @@ -191,7 +198,7 @@ do_window(
/* close preview window */ /* close preview window */
case Ctrl_Z: case Ctrl_Z:
case 'z': case 'z':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
do_cmdline_cmd((char_u *)"pclose"); do_cmdline_cmd((char_u *)"pclose");
break; break;
Expand All @@ -211,7 +218,7 @@ do_window(
/* close all but current window */ /* close all but current window */
case Ctrl_O: case Ctrl_O:
case 'o': case 'o':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); cmd_with_count("only", cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf); do_cmdline_cmd(cbuf);
Expand All @@ -222,7 +229,7 @@ do_window(
case 'w': case 'w':
/* cursor to previous window with wrap around */ /* cursor to previous window with wrap around */
case 'W': case 'W':
CHECK_CMDWIN CHECK_CMDWIN;
if (ONE_WINDOW && Prenum != 1) /* just one window */ if (ONE_WINDOW && Prenum != 1) /* just one window */
beep_flush(); beep_flush();
else else
Expand Down Expand Up @@ -260,15 +267,15 @@ do_window(
case 'j': case 'j':
case K_DOWN: case K_DOWN:
case Ctrl_J: case Ctrl_J:
CHECK_CMDWIN CHECK_CMDWIN;
win_goto_ver(FALSE, Prenum1); win_goto_ver(FALSE, Prenum1);
break; break;


/* cursor to window above */ /* cursor to window above */
case 'k': case 'k':
case K_UP: case K_UP:
case Ctrl_K: case Ctrl_K:
CHECK_CMDWIN CHECK_CMDWIN;
win_goto_ver(TRUE, Prenum1); win_goto_ver(TRUE, Prenum1);
break; break;


Expand All @@ -277,15 +284,15 @@ do_window(
case K_LEFT: case K_LEFT:
case Ctrl_H: case Ctrl_H:
case K_BS: case K_BS:
CHECK_CMDWIN CHECK_CMDWIN;
win_goto_hor(TRUE, Prenum1); win_goto_hor(TRUE, Prenum1);
break; break;


/* cursor to right window */ /* cursor to right window */
case 'l': case 'l':
case K_RIGHT: case K_RIGHT:
case Ctrl_L: case Ctrl_L:
CHECK_CMDWIN CHECK_CMDWIN;
win_goto_hor(FALSE, Prenum1); win_goto_hor(FALSE, Prenum1);
break; break;


Expand Down Expand Up @@ -338,21 +345,21 @@ do_window(
/* exchange current and next window */ /* exchange current and next window */
case 'x': case 'x':
case Ctrl_X: case Ctrl_X:
CHECK_CMDWIN CHECK_CMDWIN;
win_exchange(Prenum); win_exchange(Prenum);
break; break;


/* rotate windows downwards */ /* rotate windows downwards */
case Ctrl_R: case Ctrl_R:
case 'r': case 'r':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
win_rotate(FALSE, (int)Prenum1); /* downwards */ win_rotate(FALSE, (int)Prenum1); /* downwards */
break; break;


/* rotate windows upwards */ /* rotate windows upwards */
case 'R': case 'R':
CHECK_CMDWIN CHECK_CMDWIN;
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); /* stop Visual mode */
win_rotate(TRUE, (int)Prenum1); /* upwards */ win_rotate(TRUE, (int)Prenum1); /* upwards */
break; break;
Expand All @@ -362,7 +369,7 @@ do_window(
case 'J': case 'J':
case 'H': case 'H':
case 'L': case 'L':
CHECK_CMDWIN CHECK_CMDWIN;
win_totop((int)Prenum, win_totop((int)Prenum,
((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0) ((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0)
| ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT));
Expand Down Expand Up @@ -428,7 +435,7 @@ do_window(
/* jump to tag and split window if tag exists (in preview window) */ /* jump to tag and split window if tag exists (in preview window) */
#if defined(FEAT_QUICKFIX) #if defined(FEAT_QUICKFIX)
case '}': case '}':
CHECK_CMDWIN CHECK_CMDWIN;
if (Prenum) if (Prenum)
g_do_tagpreview = Prenum; g_do_tagpreview = Prenum;
else else
Expand All @@ -437,7 +444,7 @@ do_window(
/* FALLTHROUGH */ /* FALLTHROUGH */
case ']': case ']':
case Ctrl_RSB: case Ctrl_RSB:
CHECK_CMDWIN CHECK_CMDWIN;
/* keep Visual mode, can select words to use as a tag */ /* keep Visual mode, can select words to use as a tag */
if (Prenum) if (Prenum)
postponed_split = Prenum; postponed_split = Prenum;
Expand All @@ -459,7 +466,7 @@ do_window(
case 'F': case 'F':
case Ctrl_F: case Ctrl_F:
wingotofile: wingotofile:
CHECK_CMDWIN CHECK_CMDWIN;


ptr = grab_file_name(Prenum1, &lnum); ptr = grab_file_name(Prenum1, &lnum);
if (ptr != NULL) if (ptr != NULL)
Expand Down Expand Up @@ -503,7 +510,7 @@ do_window(
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'd': /* Go to definition, using 'define' */ case 'd': /* Go to definition, using 'define' */
case Ctrl_D: case Ctrl_D:
CHECK_CMDWIN CHECK_CMDWIN;
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
break; break;
find_pattern_in_path(ptr, 0, len, TRUE, find_pattern_in_path(ptr, 0, len, TRUE,
Expand Down Expand Up @@ -534,7 +541,7 @@ do_window(
/* CTRL-W g extended commands */ /* CTRL-W g extended commands */
case 'g': case 'g':
case Ctrl_G: case Ctrl_G:
CHECK_CMDWIN CHECK_CMDWIN;
#ifdef USE_ON_FLY_SCROLL #ifdef USE_ON_FLY_SCROLL
dont_scroll = TRUE; /* disallow scrolling here */ dont_scroll = TRUE; /* disallow scrolling here */
#endif #endif
Expand Down Expand Up @@ -4273,9 +4280,9 @@ win_enter_ext(
win_T *wp, win_T *wp,
int undo_sync, int undo_sync,
int curwin_invalid, int curwin_invalid,
int trigger_new_autocmds UNUSED, int trigger_new_autocmds,
int trigger_enter_autocmds UNUSED, int trigger_enter_autocmds,
int trigger_leave_autocmds UNUSED) int trigger_leave_autocmds)
{ {
int other_buffer = FALSE; int other_buffer = FALSE;


Expand Down Expand Up @@ -4385,7 +4392,7 @@ win_enter_ext(
#endif #endif


/* Change directories when the 'acd' option is set. */ /* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR DO_AUTOCHDIR;
} }




Expand Down

0 comments on commit 6f47002

Please sign in to comment.