From: Lennart Poettering Date: Mon, 23 Mar 2009 20:03:52 +0000 (+0100) Subject: add pa_assert_cc() for compile time assertions X-Git-Tag: 1.0_branch~1978 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52dcb950efead46a398da977bc28e560f8564b62;p=profile%2Fivi%2Fpulseaudio.git add pa_assert_cc() for compile time assertions --- diff --git a/src/pulse/fork-detect.c b/src/pulse/fork-detect.c index f10fc02..a4e0dd1 100644 --- a/src/pulse/fork-detect.c +++ b/src/pulse/fork-detect.c @@ -39,7 +39,7 @@ int pa_detect_fork(void) { * however have to deal with this cleanly, so we try to detect the * forks making sure all our calls fail cleanly after the fork. */ - pa_assert(sizeof(pa_atomic_t) >= sizeof(pid_t)); + pa_assert_cc(sizeof(pa_atomic_t) >= sizeof(pid_t)); for (;;) { pid_t stored_pid = (pid_t) pa_atomic_load(&pid); diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h index 309f1a0..a5ca696 100644 --- a/src/pulsecore/macro.h +++ b/src/pulsecore/macro.h @@ -193,11 +193,25 @@ typedef int pa_bool_t; #define pa_assert_fp(expr) pa_assert_se(expr) #endif +#ifdef NDEBUG +#define pa_assert_not_reached() pa_nop() +#else #define pa_assert_not_reached() \ do { \ pa_log_error("Code should not be reached at %s:%u, function %s(). Aborting.", __FILE__, __LINE__, PA_PRETTY_FUNCTION); \ abort(); \ } while (FALSE) +#endif + +/* A compile time assertion */ +#define pa_assert_cc(expr) \ + do { \ + switch (0) { \ + case 0: \ + case !!(expr): \ + ; \ + } \ + } while (FALSE) #define PA_PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) #define PA_UINT_TO_PTR(u) ((void*) ((uintptr_t) (u)))