From df49986fab4fbae49c44d9c1ea69dadaf4dff74c Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Thu, 12 Sep 2019 20:27:03 -0700 Subject: [PATCH] Add a FALL_THROUGH macro to compiler.h Older gcc's don't support `__attribute__ ((fallthrough))` (see https://sourceforge.net/u/begasus/tuxpaint/ci/e5c3cdfcf5e16a9b0fc3e7766bfea1d9c326b3ae/ "Haiku Fixes" by Luc), so adding a new macro to compiler.h that is defined as "((void)0)" on older compilers. --- src/compiler.h | 14 ++++++++++++-- src/im.c | 19 +++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/compiler.h b/src/compiler.h index 5afeec307..82efd7a9c 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -5,7 +5,7 @@ for Tux Paint Mostly by Albert Cahalan - Copyright (c) 2002-2006 + Copyright (c) 2002-2019 http://www.newbreedsoftware.com/tuxpaint/ @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - December 30, 2017 + June 14, 2002 - September 12, 2019 $Id$ */ @@ -127,3 +127,13 @@ #undef CLOCK_ASM #define CLOCK_ASM(x) x=42 #endif + +/* h/t https://tutel.me/c/programming/questions/45349079/how+to+use+__attribute__fallthrough+correctly+in+gcc */ +#ifndef FALLTHROUGH +#if defined(__GNUC__) && __GNUC__ >= 7 + #define FALL_THROUGH __attribute__ ((fallthrough)) +#else + #define FALL_THROUGH ((void)0) +#endif /* __GNUC__ >= 7 */ +#endif + diff --git a/src/im.c b/src/im.c index 138cfad4f..ac7d5862b 100644 --- a/src/im.c +++ b/src/im.c @@ -45,7 +45,6 @@ #include "im.h" - /* *************************************************************************** * I18N GETTEXT */ @@ -905,12 +904,12 @@ static int im_event_zh_tw(IM_DATA * im, SDL_keysym ks) case IM_REQ_FREE: /* Free allocated resources */ charmap_free(&cm); - // // __attribute__ ((fallthrough)); /* go onto full reset */ + FALL_THROUGH; /* go onto full reset */ case IM_REQ_RESET_FULL: /* Full reset */ cm.section = SEC_ENGLISH; im->tip_text = im_tip_text[IM_TIP_ENGLISH]; - // __attribute__ ((fallthrough)); /* go onto soft reset */ + FALL_THROUGH; /* go onto soft reset */ case IM_REQ_RESET_SOFT: /* Soft reset */ im->s[0] = L'\0'; @@ -1124,12 +1123,12 @@ static int im_event_th(IM_DATA * im, SDL_keysym ks) case IM_REQ_FREE: /* Free allocated resources */ charmap_free(&cm); - // __attribute__ ((fallthrough)); /* go onto full reset */ + FALL_THROUGH; /* go onto full reset */ case IM_REQ_RESET_FULL: /* Full reset */ cm.section = SEC_ENGLISH; im->tip_text = im_tip_text[IM_TIP_ENGLISH]; - // __attribute__ ((fallthrough)); /* go onto soft reset */ + FALL_THROUGH; /* go onto soft reset */ case IM_REQ_RESET_SOFT: /* Soft reset */ im->s[0] = L'\0'; @@ -1343,12 +1342,12 @@ static int im_event_ja(IM_DATA * im, SDL_keysym ks) case IM_REQ_FREE: /* Free allocated resources */ charmap_free(&cm); - // __attribute__ ((fallthrough)); /* go onto full reset */ + FALL_THROUGH; /* go onto full reset */ case IM_REQ_RESET_FULL: /* Full reset */ cm.section = SEC_ENGLISH; im->tip_text = im_tip_text[IM_TIP_ENGLISH]; - // __attribute__ ((fallthrough)); /* go onto soft reset */ + FALL_THROUGH; /* go onto soft reset */ case IM_REQ_RESET_SOFT: /* Soft reset */ im->s[0] = L'\0'; @@ -1590,12 +1589,12 @@ static int im_event_ko(IM_DATA * im, SDL_keysym ks) case IM_REQ_FREE: /* Free allocated resources */ charmap_free(&cm); - // __attribute__ ((fallthrough)); /* go onto full reset */ + FALL_THROUGH; /* go onto full reset */ case IM_REQ_RESET_FULL: /* Full reset */ cm.section = SEC_ENGLISH; im->tip_text = im_tip_text[IM_TIP_ENGLISH]; - // __attribute__ ((fallthrough)); /* go onto soft reset */ + FALL_THROUGH; /* go onto soft reset */ case IM_REQ_RESET_SOFT: /* Soft reset */ im->s[0] = L'\0'; @@ -1681,7 +1680,7 @@ static int im_event_ko(IM_DATA * im, SDL_keysym ks) im->redraw--; ks.unicode = L'\0'; } - // __attribute__ ((fallthrough)); /* continue processing: */ + FALL_THROUGH; /* continue processing: */ /* Actual character processing */ default: