[asterisk-commits] kpfleming: trunk r155967 - /trunk/include/asterisk/strings.h
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Nov 11 11:57:20 CST 2008
Author: kpfleming
Date: Tue Nov 11 11:57:20 2008
New Revision: 155967
URL: http://svn.digium.com/view/asterisk?view=rev&rev=155967
Log:
use some fancy compiler magic (thanks to Matthew Woehlke on the gcc-help mailing list) to restore type-safety to S_OR by going back to a macro, but preserve the side-effect-safe usage of the macro arguments
Modified:
trunk/include/asterisk/strings.h
Modified: trunk/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=155967&r1=155966&r2=155967
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Tue Nov 11 11:57:20 2008
@@ -52,19 +52,13 @@
/*! \brief returns the equivalent of logic or for strings:
* first one if not empty, otherwise second one.
*/
-static force_inline char *S_OR(const char *a, const char *b)
-{
- return ast_strlen_zero(a) ? (char *) b : (char *) a;
-}
+#define S_OR(a, b) ({typeof(&((a)[0])) __x = (a); ast_strlen_zero(__x) ? (b) : __x;})
/*! \brief returns the equivalent of logic or for strings, with an additional boolean check:
* second one if not empty and first one is true, otherwise third one.
* example: S_COR(usewidget, widget, "<no widget>")
*/
-static force_inline char *S_COR(unsigned char a, const char *b, const char *c)
-{
- return a && !ast_strlen_zero(b) ? (char *) b : (char *) c;
-}
+#define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
/*!
\brief Gets a pointer to the first non-whitespace character in a string.
More information about the asterisk-commits
mailing list