[systemd-devel] [PATCH] macro: allow assert_se() assertions to also be optimized when NDEBUG is set
Shawn Landden
shawn at churchofgit.com
Mon Mar 30 20:24:32 PDT 2015
replaces log with assert() to remove strings.
saves 3kB from text section of systemd.
---
src/shared/macro.h | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 7f89951..8cbff01 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -212,17 +212,21 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
(__x / __y + !!(__x % __y)); \
})
-#define assert_se(expr) \
- do { \
- if (_unlikely_(!(expr))) \
- log_assert_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
- } while (false) \
-
/* We override the glibc assert() here. */
#undef assert
#ifdef NDEBUG
+#define assert_se(expr) \
+ do {\
+ if (_unlikely_(!(expr)))\
+ abort();\
+ } while (false)
#define assert(expr) do {} while(false)
#else
+#define assert_se(expr) \
+ do { \
+ if (_unlikely_(!(expr))) \
+ log_assert_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+ } while (false)
#define assert(expr) assert_se(expr)
#endif
--
2.2.1.209.g41e5f3a
More information about the systemd-devel
mailing list