From: David Tardon Date: Fri, 9 Sep 2022 08:04:36 +0000 (+0200) Subject: macro-fundamental: allow to nest ASSERT_PTR X-Git-Tag: v252-rc1~194^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23cd0025621c17d9007c2e912bd5745a8986d260;p=thirdparty%2Fsystemd.git macro-fundamental: allow to nest ASSERT_PTR E.g., int job_frobnicate(Job *j) { Unit *u = ASSERT_PTR(ASSERT_PTR(j)->unit); ... } --- diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 8b483f0b50d..2536c741c62 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) \