[Asterisk-code-review] utils: Add ast assert return (asterisk[13])

Jenkins2 asteriskteam at digium.com
Wed Apr 18 14:35:57 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8778 )

Change subject: utils:  Add ast_assert_return
......................................................................

utils:  Add ast_assert_return

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
---
M include/asterisk/utils.h
1 file changed, 13 insertions(+), 0 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 290f7a3..f8f761d 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -860,6 +860,13 @@
 
 #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)) {
@@ -868,6 +875,12 @@
 }
 #else
 #define ast_assert(a)
+#define ast_assert_return(a, ...) \
+({ \
+	if (__builtin_expect(!(a), 1)) { \
+		return __VA_ARGS__; \
+	}\
+})
 #endif
 
 /*!

-- 
To view, visit https://gerrit.asterisk.org/8778
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I0003844affeab550d5ff5bca7aa7cf8a559b873e
Gerrit-Change-Number: 8778
Gerrit-PatchSet: 3
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180418/3f9b649a/attachment.html>


More information about the asterisk-code-review mailing list