forked from zerotao/libevhtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evhtp-internal.h
76 lines (63 loc) · 2.94 KB
/
evhtp-internal.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef __EVHTP_INTERNAL_H__
#define __EVHTP_INTERNAL_H__
#ifdef __cplusplus
extern "C" {
#endif
#if defined __GNUC__ || defined __llvm__
# define evhtp_likely(x) __builtin_expect(!!(x), 1)
# define evhtp_unlikely(x) __builtin_expect(!!(x), 0)
#else
# define evhtp_likely(x) (x)
# define evhtp_unlikely(x) (x)
#endif
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#define evhtp_safe_free(_var, _freefn) do { \
_freefn((_var)); \
(_var) = NULL; \
} while (0)
#define evhtp_assert(x) \
do { \
if (evhtp_unlikely(!(x))) { \
fprintf(stderr, "Assertion failed: %s (%s:%s:%d)\n", # x, \
__func__, __FILE__, __LINE__); \
fflush(stderr); \
abort(); \
} \
} while (0)
#define evhtp_alloc_assert(x) \
do { \
if (evhtp_unlikely(!x)) { \
fprintf(stderr, "Out of memory (%s:%s:%d)\n", \
__func__, __FILE__, __LINE__); \
fflush(stderr); \
abort(); \
} \
} while (0)
#define evhtp_assert_fmt(x, fmt, ...) \
do { \
if (evhtp_unlikely(!(x))) { \
fprintf(stderr, "Assertion failed: %s (%s:%s:%d) " fmt "\n", \
# x, __func__, __FILE__, __LINE__, __VA_ARGS__); \
fflush(stderr); \
abort(); \
} \
} while (0)
#define evhtp_errno_assert(x) \
do { \
if (evhtp_unlikely(!(x))) { \
fprintf(stderr, "%s [%d] (%s:%s:%d)\n", \
strerror(errno), errno, \
__func__, __FILE__, __LINE__); \
fflush(stderr); \
abort(); \
} \
} while (0)
#ifdef __cplusplus
}
#endif
#endif