aboutsummaryrefslogtreecommitdiff
path: root/include/apos/assert.h
blob: f3d9a4df7d95baf2b3ab147479dc60970f8a7da3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef APOS_ASSERT_H
#define APOS_ASSERT_H

#include <apos/debug.h>
#include <apos/utils.h>

/* TODO: should this exit or do something explosive like that? */
#if !defined(DNDEBUG)
#define catastrophic_assert(x)                                                 \
	do {                                                                   \
		if (unlikely(!(x))) {                                          \
			error("catastrophic assertion failed: %s\n",           \
			      QUOTE(x));                                       \
			while (1)                                              \
				;                                              \
		}                                                              \
	} while (0);

#define hard_assert(x, r)                                                      \
	{                                                                      \
		if (unlikely(!(x))) {                                          \
			warn("hard assertion failed: %s\n", QUOTE(x));         \
			return r;                                              \
		}                                                              \
	}

#define soft_assert(x)                                                         \
	do {                                                                   \
		if (unlikely(!(x))) {                                          \
			info("soft assertion failed: %s\n", QUOTE(x));         \
		}                                                              \
	} while (0);
#else
#define catastrophic_assert(x)
#define hard_assert(x, r)
#define soft_assert(x)
#endif

/* use when return value doesn't exist, like hard_assert(x,
	 * RETURN_VOID); */
#define RETURN_VOID

#endif /* APOS_ASSERT_H */