summaryrefslogtreecommitdiff
path: root/src/fundamental
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2022-09-09 10:04:36 +0200
committerDavid Tardon <dtardon@redhat.com>2022-09-14 08:21:40 +0200
commit23cd0025621c17d9007c2e912bd5745a8986d260 (patch)
treea5fa9146c61bbb82adb5a59a630eb62b88825333 /src/fundamental
parentc9bc7a449cf5cafb233cd2c7a8654117c7fd950a (diff)
downloadsystemd-23cd0025621c17d9007c2e912bd5745a8986d260.tar.gz
macro-fundamental: allow to nest ASSERT_PTR
E.g., int job_frobnicate(Job *j) { Unit *u = ASSERT_PTR(ASSERT_PTR(j)->unit); ... }
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/macro-fundamental.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index 8b483f0b50..2536c741c6 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -81,18 +81,13 @@
#endif
/* This passes the argument through after (if asserts are enabled) checking that it is not null. */
-#define ASSERT_PTR(expr) \
- ({ \
- typeof(expr) _expr_ = (expr); \
- assert(_expr_); \
- _expr_; \
- })
-
-#define ASSERT_SE_PTR(expr) \
- ({ \
- typeof(expr) _expr_ = (expr); \
- assert_se(_expr_); \
- _expr_; \
+#define ASSERT_PTR(expr) _ASSERT_PTR(expr, UNIQ_T(_expr_, UNIQ), assert)
+#define ASSERT_SE_PTR(expr) _ASSERT_PTR(expr, UNIQ_T(_expr_, UNIQ), assert_se)
+#define _ASSERT_PTR(expr, var, check) \
+ ({ \
+ typeof(expr) var = (expr); \
+ check(var); \
+ var; \
})
#define ASSERT_NONNEG(expr) \