X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fmacros.h;h=13ba2d3628c1abf4b36239838be6e00146224da5;hb=e0f8968a1182ea437ee4db0abc4043ba1dc286a2;hp=9014afc2c637d1b1df6eb31764c4815074ae03c3;hpb=826b4673c08ce7dbb9da3426bf4f2131ae41a092;p=babeltrace.git diff --git a/src/common/macros.h b/src/common/macros.h index 9014afc2..13ba2d36 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -11,18 +11,38 @@ extern "C" { #endif +#ifdef __cplusplus +#define BT_EXTERN_C extern "C" +#else +#define BT_EXTERN_C +#endif + #define bt_max_t(type, a, b) \ ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) /* - * BT_HIDDEN: set the hidden attribute for internal functions - * On Windows, symbols are local unless explicitly exported, - * see https://gcc.gnu.org/wiki/Visibility + * BT_EXPORT: set the visibility for exported functions. */ #if defined(_WIN32) || defined(__CYGWIN__) -#define BT_HIDDEN +#define BT_EXPORT #else -#define BT_HIDDEN __attribute__((visibility("hidden"))) +#define BT_EXPORT __attribute__((visibility("default"))) +#endif + +/* + * BT_NOEXCEPT: defined to `noexcept` if compiling as C++, else empty. + */ +#if defined(__cplusplus) +#define BT_NOEXCEPT noexcept +#else +#define BT_NOEXCEPT +#endif + +/* Enable `txt` if developer mode is enabled. */ +#ifdef BT_DEV_MODE +#define BT_IF_DEV_MODE(txt) txt +#else +#define BT_IF_DEV_MODE(txt) #endif /* @@ -43,11 +63,15 @@ extern "C" { #define BT_MOVE_REF(ref) \ ({ \ - typeof(ref) _ref = ref; \ + __typeof__(ref) _ref = ref; \ ref = NULL; \ _ref; \ }) +/* Wrapper for g_array_index that adds bound checking. */ +#define bt_g_array_index(a, t, i) \ + g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); })) + /* * Copied from: * : @@ -75,6 +99,17 @@ extern "C" { ((void) sizeof((void) (_expr1), (void) (_expr2), \ (void) (_expr3), (void) (_expr4), (void) (_expr5), 0)) +#if defined __clang__ +# if __has_warning("-Wunused-but-set-variable") +# define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE \ + _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") +# endif +#endif + +#if !defined BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE +# define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE +#endif + #ifdef __cplusplus } #endif