]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro-fundamental: allow to nest ASSERT_PTR
authorDavid Tardon <dtardon@redhat.com>
Fri, 9 Sep 2022 08:04:36 +0000 (10:04 +0200)
committerDavid Tardon <dtardon@redhat.com>
Wed, 14 Sep 2022 06:21:40 +0000 (08:21 +0200)
E.g.,

int job_frobnicate(Job *j) {
        Unit *u = ASSERT_PTR(ASSERT_PTR(j)->unit);
        ...
}

src/fundamental/macro-fundamental.h

index 8b483f0b50d21176049bd405f727ed0fbf94cee9..2536c741c62f3d38cf6f1d487a9d1d580c93ea00 100644 (file)
 #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)                              \