cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / common / macros.h
index 6a3e061d5f17464222d85701e96a0cbf6e871121..8120515c63fe5bbcd81672f8c7b4cf1df89d9ce8 100644 (file)
@@ -21,14 +21,28 @@ extern "C" {
        ((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
 
 /*
@@ -54,6 +68,10 @@ extern "C" {
                _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:
  * <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
@@ -81,6 +99,11 @@ extern "C" {
        ((void) sizeof((void) (_expr1), (void) (_expr2),                \
                (void) (_expr3), (void) (_expr4), (void) (_expr5), 0))
 
+#define BT_DIAG_PUSH _Pragma ("GCC diagnostic push")
+#define BT_DIAG_POP _Pragma ("GCC diagnostic push")
+
+#define BT_DIAG_IGNORE_SHADOW _Pragma("GCC diagnostic ignored \"-Wshadow\"")
+
 #if defined __clang__
 #  if __has_warning("-Wunused-but-set-variable")
 #    define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE \
This page took 0.024764 seconds and 4 git commands to generate.