]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
utils: Add ast_assert_return
authorGeorge Joseph <gjoseph@digium.com>
Fri, 13 Apr 2018 20:17:36 +0000 (14:17 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Mon, 16 Apr 2018 12:34:35 +0000 (06:34 -0600)
Similar to pjproject's PJ_ASSERT_RETURN macro, this one will do the
following...

If the assert passes... NoOp

If the assert fails and AST_DEVMODE is defined, execute ast_assert()
then, if DO_CRASH isn't set, return from the calling function with
the supplied value.

If the assert fails and AST_DEVMODE is not defined, return from the
calling function with the supplied value.

The macro will execute a return without a value if one isn't suppled.

Change-Id: I0003844affeab550d5ff5bca7aa7cf8a559b873e

include/asterisk/utils.h

index 798caabc563c28cd7fb916cbdf8ace33cf8ea7a1..b6fd9e825a2f9deef75c77602823c9d301fafb01 100644 (file)
@@ -859,6 +859,13 @@ void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_
 
 #ifdef AST_DEVMODE
 #define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define ast_assert_return(a, ...) \
+({ \
+       if (__builtin_expect(!(a), 1)) { \
+               _ast_assert(0, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+               return __VA_ARGS__; \
+       }\
+})
 static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
 {
        if (__builtin_expect(!condition, 1)) {
@@ -867,6 +874,12 @@ static void force_inline _ast_assert(int condition, const char *condition_str, c
 }
 #else
 #define ast_assert(a)
+#define ast_assert_return(a, ...) \
+({ \
+       if (__builtin_expect(!(a), 1)) { \
+               return __VA_ARGS__; \
+       }\
+})
 #endif
 
 /*!