diff options
author | Steffan Karger | 2016-03-27 16:18:16 +0200 |
---|---|---|
committer | Gert Doering | 2016-04-04 20:28:41 +0200 |
commit | bbde0a766c69f573746461415c6f5cd289272fff (patch) | |
tree | 713e595313baa8d602d0c90d75fd837f2542d8a3 /src/openvpn/error.h | |
parent | be16d5f6b050248f503455e4a0e8f3aaaa38bdc7 (diff) | |
download | openvpn-bbde0a766c69f573746461415c6f5cd289272fff.zip openvpn-bbde0a766c69f573746461415c6f5cd289272fff.tar.gz |
Replace MSG_TEST() macro for static inline msg_test()
Using a static inline function instead of a macro has the advantages that
(1) 'flags' is not evaluated twice and (2) coverity will stop complaining
that 'Macro compares unsigned to 0 (NO_EFFECT)' each time we use flags
with loglevel 0 (e.g. M_FATAL or M_WARN).
This has a performance impact when compiler optimizations are fully
disabled ('-O0'), but should otherwise be as fast as using a macro.
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1459088296-5046-1-git-send-email-steffan@karger.me>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11368
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/error.h')
-rw-r--r-- | src/openvpn/error.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/openvpn/error.h b/src/openvpn/error.h index dd5ccf7..76515d6 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -135,26 +135,31 @@ extern int x_msg_line_num; * msg() as a macro for optimization win. */ -bool dont_mute (unsigned int flags); /* check muting filter */ +/** Check muting filter */ +bool dont_mute (unsigned int flags); -#define MSG_TEST(flags) (unlikely((((unsigned int)flags) & M_DEBUG_LEVEL) <= x_debug_level) && dont_mute (flags)) +/** Return true if flags represent an enabled, not muted log level */ +static inline bool msg_test (unsigned int flags) +{ + return ((flags & M_DEBUG_LEVEL) <= x_debug_level) && dont_mute (flags); +} /* Macro to ensure (and teach static analysis tools) we exit on fatal errors */ #define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) _exit(1); } while (false) #if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__) # define HAVE_VARARG_MACROS -# define msg(flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false) +# define msg(flags, ...) do { if (msg_test(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false) # ifdef ENABLE_DEBUG -# define dmsg(flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false) +# define dmsg(flags, ...) do { if (msg_test(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false) # else # define dmsg(flags, ...) # endif #elif defined(HAVE_CPP_VARARG_MACRO_GCC) && !defined(__LCLINT__) # define HAVE_VARARG_MACROS -# define msg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false) +# define msg(flags, args...) do { if (msg_test(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false) # ifdef ENABLE_DEBUG -# define dmsg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false) +# define dmsg(flags, args...) do { if (msg_test(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false) # else # define dmsg(flags, args...) # endif |