[pulseaudio-commits] r2194 - /branches/prepare-0.9.10/src/pulsecore/macro.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sat Mar 29 18:42:35 PDT 2008
Author: lennart
Date: Sun Mar 30 03:42:34 2008
New Revision: 2194
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2194&root=pulseaudio&view=rev
Log:
rework pa_assert_se() to make sure it never gets optmized away, even if NDEBUG is defined
Modified:
branches/prepare-0.9.10/src/pulsecore/macro.h
Modified: branches/prepare-0.9.10/src/pulsecore/macro.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/prepare-0.9.10/src/pulsecore/macro.h?rev=2194&root=pulseaudio&r1=2193&r2=2194&view=diff
==============================================================================
--- branches/prepare-0.9.10/src/pulsecore/macro.h (original)
+++ branches/prepare-0.9.10/src/pulsecore/macro.h Sun Mar 30 03:42:34 2008
@@ -29,6 +29,8 @@
#include <assert.h>
#include <limits.h>
#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <pulsecore/log.h>
#include <pulsecore/gccmacro.h>
@@ -103,34 +105,46 @@
#define PA_PRETTY_FUNCTION ""
#endif
-#define pa_return_if_fail(expr) \
- do { \
- if (!(expr)) { \
- pa_log_debug("%s: Assertion <%s> failed.\n", PA_PRETTY_FUNCTION, #expr ); \
- return; \
- } \
- } while(0)
+#define pa_return_if_fail(expr) \
+ do { \
+ if (PA_UNLIKELY(!(expr))) { \
+ pa_log_debug("Assertion '%s' failed at %s:%u, function %s.\n", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
+ return; \
+ } \
+ } while(FALSE)
-#define pa_return_val_if_fail(expr, val) \
- do { \
- if (!(expr)) { \
- pa_log_debug("%s: Assertion <%s> failed.\n", PA_PRETTY_FUNCTION, #expr ); \
- return (val); \
- } \
- } while(0)
+#define pa_return_val_if_fail(expr, val) \
+ do { \
+ if (PA_UNLIKELY(!(expr))) { \
+ pa_log_debug("Assertion '%s' failed at %s:%u, function %s.\n", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
+ return (val); \
+ } \
+ } while(FALSE)
#define pa_return_null_if_fail(expr) pa_return_val_if_fail(expr, NULL)
-#define pa_assert assert
+/* An assert which guarantees side effects of x, i.e. is never
+ * optimized away */
+#define pa_assert_se(expr) \
+ do { \
+ if (PA_UNLIKELY(!(expr))) { \
+ pa_log_error("Assertion '%s' failed at %s:%u, function %s(). Aborting.", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
+ abort(); \
+ } \
+ } while (FALSE)
-#define pa_assert_not_reached() pa_assert(!"Should not be reached.")
+/* An assert that may be optimized away by defining NDEBUG */
+#ifdef NDEBUG
+#define pa_assert(expr) do {} while (FALSE)
+#else
+#define pa_assert(expr) pa_assert_se(expr)
+#endif
-/* An assert which guarantees side effects of x */
-#ifdef NDEBUG
-#define pa_assert_se(x) x
-#else
-#define pa_assert_se(x) pa_assert(x)
-#endif
+#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)
#define PA_PTR_TO_UINT(p) ((unsigned int) (unsigned long) (p))
#define PA_UINT_TO_PTR(u) ((void*) (unsigned long) (u))
More information about the pulseaudio-commits
mailing list