diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-04-05 22:49:05 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2016-04-08 17:34:10 +0000 |
commit | 57b2a84f3d900eb0b98157095c6aac07cec54fd9 (patch) | |
tree | ec069513b90f83bbb31843a17204ffb0fb97fa69 | |
parent | 434bbd67a06803ce6bb9a8e0adc6d596246bc458 (diff) | |
download | wireshark-57b2a84f3d900eb0b98157095c6aac07cec54fd9.tar.gz |
Use a single WS_NORETURN macro
Having to define two macros for marking a function as never returning
seems a bit redundant. Merge the MSVC and GCC-like attributes into a
single WS_NORETURN.
Tested with Clang 3.7.1, GCC 4.4.7 and even GCC 4.1.2 using this small
program (-Wall -Wextra, the first two generate warnings for
uninitialized variables, the last one compiles without warnings):
#include <stdlib.h>
__attribute__((noreturn)) void foo() { exit(1); }
__attribute__((noreturn)) void bar();
void bar() { exit(1); }
int main() {
int j, i;
if (i) { bar(); return j; }
foo();
return j;
}
Change-Id: I7d19c15e61b8f8fa4936864407199c4109f8cc82
Reviewed-on: https://code.wireshark.org/review/14822
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | cmakeconfig.h.in | 12 | ||||
-rw-r--r-- | config.h.win32 | 14 | ||||
-rw-r--r-- | configure.ac | 13 | ||||
-rw-r--r-- | dumpcap.c | 2 | ||||
-rw-r--r-- | epan/except.c | 10 | ||||
-rw-r--r-- | epan/except.h | 10 | ||||
-rw-r--r-- | epan/proto.h | 2 |
8 files changed, 27 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1722044a7a..8b864fc4ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -587,9 +587,14 @@ if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC") endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set (C_UNUSED "__attribute__((unused))" ) + set (C_UNUSED "__attribute__((unused))" ) + set (WS_NORETURN "__attribute__((noreturn))") +elseif(MSVC) + set (C_UNUSED "") + set (WS_NORETURN "__declspec(noreturn)") else() - set (C_UNUSED "" ) + set (C_UNUSED "") + set (WS_NORETURN "") endif() set(WIRESHARK_LD_FLAGS @@ -1143,14 +1148,10 @@ gmx_test_large_files(GMX_LARGEFILES) add_definitions( -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\" ) if(WIN32) - set(WS_MSVC_NORETURN "__declspec(noreturn)") - # Disable deprecation if(MSVC80 OR MSVC90) add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) endif() -else() - set(WS_MSVC_NORETURN " ") endif() if (${GIT_EXECUTABLE}) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 75d9433582..bb62fb6737 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -415,15 +415,6 @@ #cmakedefine _LARGE_FILES #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ -/* Define WS_MSVC_NORETURN appropriately for declarations of routines that - never return (just like Charlie on the MTA). - - Note that MSVC++ expects __declspec(noreturn) to precede the function - name and GCC, as far as I know, expects __attribute__((noreturn)) to - follow the function name, so we need two different flavors of - noreturn tag. */ -#define WS_MSVC_NORETURN @WS_MSVC_NORETURN@ - /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a `char[]'. */ /* Note: not use in the code */ @@ -433,6 +424,9 @@ However, we do need it for some headers that are shared between C and C++. */ #define _U_ ${C_UNUSED} +/* Hint to the compiler that a function never returns */ +#define WS_NORETURN @WS_NORETURN@ + #if defined(_WIN32) /* WpdPack/INclude/pcap/pcap.h checks for "#if defined(WIN32)" */ diff --git a/config.h.win32 b/config.h.win32 index f1be3dfaa4..3273f7b8ed 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -79,17 +79,6 @@ @PCAP_NG_DEFAULT@ @WANT_PACKET_EDITOR@ -/* - * Define WS_MSVC_NORETURN appropriately for declarations of routines that - * never return (just like Charlie on the MTA). - * - * Note that MSVC++ expects __declspec(noreturn) to precede the function - * name and GCC, as far as I know, expects __attribute__((noreturn)) to - * follow the function name, so we need two different flavors of - * noreturn tag. - */ -#define WS_MSVC_NORETURN __declspec(noreturn) - /* Define if you have the floorl function. */ #define HAVE_FLOORL 1 @@ -212,6 +201,9 @@ */ #define _U_ +/* Hint to the compiler that a function never returns */ +#define WS_NORETURN __declspec(noreturn) + /* Visual C 9 (2008), Visual C 10 (2010) and Visual C 11 (2012) and Visual C 12 (2013) need these prototypes */ #if _MSC_VER >= 1500 #define NTDDI_VERSION NTDDI_WINXPSP3 diff --git a/configure.ac b/configure.ac index 272af90a7b..50f6c85ff8 100644 --- a/configure.ac +++ b/configure.ac @@ -1221,8 +1221,10 @@ AC_SUBST(CFLAGS_SSE42) # if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then AC_DEFINE(_U_, __attribute__((unused)), [Hint to the compiler that a function parameters is not used]) + AC_DEFINE(WS_NORETURN, __attribute((noreturn)), [Hint to the compiler that a function never returns]) else AC_DEFINE(_U_, , [Hint to the compiler that a function parameters is not used]) + AC_DEFINE(WS_NORETURN, , [Hint to the compiler that a function never returns]) fi # If we're running GCC or CLang, use FORTIFY_SOURCE=2 @@ -2651,17 +2653,6 @@ else fi AC_SUBST(LIBSSH_LIBS) -# -# Define WS_MSVC_NORETURN appropriately for declarations of routines that -# never return (just like Charlie on the MTA). -# -# Note that MSVC++ expects __declspec(noreturn) to precede the function -# name and GCC, as far as I know, expects __attribute__((noreturn)) to -# follow the function name, so we need two different flavors of -# noreturn tag. -# -AC_DEFINE(WS_MSVC_NORETURN,, [Define as the string to precede declarations of routines that never return]) - dnl Checks for typedefs, structures, and compiler characteristics. # AC_C_CONST @@ -394,7 +394,7 @@ static void capture_loop_queue_packet_cb(u_char *pcap_opts_p, const struct pcap_ static void capture_loop_get_errmsg(char *errmsg, int errmsglen, const char *fname, int err, gboolean is_close); -static void WS_MSVC_NORETURN exit_main(int err) G_GNUC_NORETURN; +static void WS_NORETURN exit_main(int err); static void report_new_capture_file(const char *filename); static void report_packet_count(unsigned int packet_count); diff --git a/epan/except.c b/epan/except.c index de6021c362..881796ebd8 100644 --- a/epan/except.c +++ b/epan/except.c @@ -180,7 +180,7 @@ static int match(const volatile except_id_t *thrown, const except_id_t *caught) return group_match && code_match; } -G_GNUC_NORETURN WS_MSVC_NORETURN static void do_throw(except_t *except) +WS_NORETURN static void do_throw(except_t *except) { struct except_stacknode *top; @@ -261,7 +261,7 @@ struct except_stacknode *except_pop(void) return top; } -G_GNUC_NORETURN WS_MSVC_NORETURN void except_rethrow(except_t *except) +WS_NORETURN void except_rethrow(except_t *except) { struct except_stacknode *top = get_top(); assert (top != 0); @@ -271,7 +271,7 @@ G_GNUC_NORETURN WS_MSVC_NORETURN void except_rethrow(except_t *except) do_throw(except); } -G_GNUC_NORETURN WS_MSVC_NORETURN void except_throw(long group, long code, const char *msg) +WS_NORETURN void except_throw(long group, long code, const char *msg) { except_t except; @@ -289,7 +289,7 @@ G_GNUC_NORETURN WS_MSVC_NORETURN void except_throw(long group, long code, const do_throw(&except); } -G_GNUC_NORETURN WS_MSVC_NORETURN void except_throwd(long group, long code, const char *msg, void *data) +WS_NORETURN void except_throwd(long group, long code, const char *msg, void *data) { except_t except; @@ -306,7 +306,7 @@ G_GNUC_NORETURN WS_MSVC_NORETURN void except_throwd(long group, long code, const * XCEPT_BUFFER_SIZE? We could then just use this to generate formatted * messages. */ -G_GNUC_NORETURN WS_MSVC_NORETURN void except_throwf(long group, long code, const char *fmt, ...) +WS_NORETURN void except_throwf(long group, long code, const char *fmt, ...) { char *buf = (char *)except_alloc(XCEPT_BUFFER_SIZE); va_list vl; diff --git a/epan/except.h b/epan/except.h index 063218274a..0f979637e9 100644 --- a/epan/except.h +++ b/epan/except.h @@ -92,11 +92,11 @@ WS_DLL_PUBLIC struct except_stacknode *except_pop(void); /* public interface functions */ WS_DLL_PUBLIC int except_init(void); WS_DLL_PUBLIC void except_deinit(void); -WS_DLL_PUBLIC WS_MSVC_NORETURN void except_rethrow(except_t *) G_GNUC_NORETURN; -WS_DLL_PUBLIC WS_MSVC_NORETURN void except_throw(long, long, const char *) G_GNUC_NORETURN; -WS_DLL_PUBLIC WS_MSVC_NORETURN void except_throwd(long, long, const char *, void *) G_GNUC_NORETURN; -WS_DLL_PUBLIC WS_MSVC_NORETURN void except_throwf(long, long, const char *, ...) - G_GNUC_NORETURN G_GNUC_PRINTF(3, 4); +WS_DLL_PUBLIC WS_NORETURN void except_rethrow(except_t *); +WS_DLL_PUBLIC WS_NORETURN void except_throw(long, long, const char *); +WS_DLL_PUBLIC WS_NORETURN void except_throwd(long, long, const char *, void *); +WS_DLL_PUBLIC WS_NORETURN void except_throwf(long, long, const char *, ...) + G_GNUC_PRINTF(3, 4); WS_DLL_PUBLIC void (*except_unhandled_catcher(void (*)(except_t *)))(except_t *); extern unsigned long except_code(except_t *); extern unsigned long except_group(except_t *); diff --git a/epan/proto.h b/epan/proto.h index 7d6ce083c2..9119038dcf 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -120,7 +120,7 @@ typedef struct _protocol protocol_t; * * @param message string to use as the message */ -WS_DLL_PUBLIC WS_MSVC_NORETURN void proto_report_dissector_bug(const char *message) G_GNUC_NORETURN; +WS_DLL_PUBLIC WS_NORETURN void proto_report_dissector_bug(const char *message); #define REPORT_DISSECTOR_BUG(message) \ proto_report_dissector_bug(message) |