Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/macros.h @ 8590:b9faf4db2a9f HEAD
Updated copyright notices to include year 2009.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 06 Jan 2009 09:25:38 -0500 |
parents | 3d65aeed7ea0 |
children |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
6128
diff
changeset
|
1 #ifndef MACROS_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
6128
diff
changeset
|
2 #define MACROS_H |
0 | 3 |
4 /* several useful macros, mostly from glib.h */ | |
5 | |
6 #ifndef NULL | |
7 # define NULL ((void *)0) | |
8 #endif | |
9 | |
10 #ifndef FALSE | |
11 # define FALSE (0) | |
12 #endif | |
13 | |
14 #ifndef TRUE | |
15 # define TRUE (!FALSE) | |
16 #endif | |
17 | |
6128 | 18 #define N_ELEMENTS(arr) \ |
19 (sizeof(arr) / sizeof((arr)[0])) | |
20 | |
0 | 21 #define BITS_IN_UINT (CHAR_BIT * sizeof(unsigned int)) |
187
ecbff0f2b811
nearest_power() uses now size_t.
Timo Sirainen <tss@iki.fi>
parents:
178
diff
changeset
|
22 #define BITS_IN_SIZE_T (CHAR_BIT * sizeof(size_t)) |
0 | 23 |
24 #define MEM_ALIGN(size) \ | |
25 (((size) + MEM_ALIGN_SIZE-1) & ~((unsigned int) MEM_ALIGN_SIZE-1)) | |
26 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1409
diff
changeset
|
27 #define PTR_OFFSET(ptr, offset) \ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1409
diff
changeset
|
28 ((void *) (((unsigned char *) (ptr)) + (offset))) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1409
diff
changeset
|
29 #define CONST_PTR_OFFSET(ptr, offset) \ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1409
diff
changeset
|
30 ((const void *) (((const unsigned char *) (ptr)) + (offset))) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1409
diff
changeset
|
31 |
0 | 32 /* Don't use simply MIN/MAX, as they're often defined elsewhere in include |
33 files that are included after this file generating tons of warnings. */ | |
34 #define I_MIN(a, b) (((a) < (b)) ? (a) : (b)) | |
35 #define I_MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
36 | |
37 #undef CLAMP | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
901
diff
changeset
|
38 #define CLAMP(x, low, high) \ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
901
diff
changeset
|
39 (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) |
0 | 40 |
41 #undef NVL | |
42 #define NVL(str, nullstr) ((str) != NULL ? (str) : (nullstr)) | |
43 | |
195
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
44 /* make it easier to cast from/to pointers. assumes that |
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
45 sizeof(size_t) == sizeof(void *) and they're both the largest datatypes |
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
46 that are allowed to be used. so, long long isn't safe with these. */ |
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
47 #define POINTER_CAST(i) \ |
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
48 ((void *) ((char *) NULL + (i))) |
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
49 #define POINTER_CAST_TO(p, type) \ |
579
e524da896d92
Several minor fixes: signess, casting away const, missing static, etc.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
50 ((type) ((const char *) (p) - (const char *) NULL)) |
0 | 51 |
859
c4754c5770f3
We weren't using va_list properly, especially gcc/PowerPC didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
579
diff
changeset
|
52 /* Define VA_COPY() to do the right thing for copying va_list variables. |
c4754c5770f3
We weren't using va_list properly, especially gcc/PowerPC didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
579
diff
changeset
|
53 config.h may have already defined VA_COPY as va_copy or __va_copy. */ |
0 | 54 #ifndef VA_COPY |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
901
diff
changeset
|
55 # if defined (__GNUC__) && defined (__PPC__) && \ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
901
diff
changeset
|
56 (defined (_CALL_SYSV) || defined (_WIN32)) |
0 | 57 # define VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) |
58 # elif defined (VA_COPY_AS_ARRAY) | |
1048
526415575295
No i_memmove here, just memmove.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
59 # define VA_COPY(ap1, ap2) memmove ((ap1), (ap2), sizeof (va_list)) |
0 | 60 # else /* va_list is a pointer */ |
61 # define VA_COPY(ap1, ap2) ((ap1) = (ap2)) | |
62 # endif /* va_list is a pointer */ | |
63 #endif | |
64 | |
65 /* Provide convenience macros for handling structure | |
66 * fields through their offsets. | |
67 */ | |
68 #define STRUCT_MEMBER_P(struct_p, struct_offset) \ | |
1052
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
69 ((void *) ((char *) (struct_p) + (long) (struct_offset))) |
0 | 70 #define STRUCT_MEMBER(member_type, struct_p, struct_offset) \ |
1052
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
71 (*(member_type *) G_STRUCT_MEMBER_P((struct_p), (struct_offset))) |
0 | 72 |
73 /* Provide simple macro statement wrappers (adapted from Perl): | |
74 STMT_START { statements; } STMT_END; | |
75 can be used as a single statement, as in | |
76 if (x) STMT_START { ... } STMT_END; else ... | |
77 | |
78 For gcc we will wrap the statements within `({' and `})' braces. | |
79 For SunOS they will be wrapped within `if (1)' and `else (void) 0', | |
80 and otherwise within `do' and `while (0)'. */ | |
81 #if !(defined (STMT_START) && defined (STMT_END)) | |
901
a225abf5f479
If PEDANTIC is defined, don't use (void)(..) with STMT_START/END.
Timo Sirainen <tss@iki.fi>
parents:
859
diff
changeset
|
82 # if defined (__GNUC__) && !defined (__cplusplus) && \ |
a225abf5f479
If PEDANTIC is defined, don't use (void)(..) with STMT_START/END.
Timo Sirainen <tss@iki.fi>
parents:
859
diff
changeset
|
83 !defined (__STRICT_ANSI__) && !defined (PEDANTIC) |
0 | 84 # define STMT_START (void)( |
85 # define STMT_END ) | |
86 # else | |
87 # if (defined (sun) || defined (__sun__)) | |
88 # define STMT_START if (1) | |
89 # define STMT_END else (void)0 | |
90 # else | |
91 # define STMT_START do | |
92 # define STMT_END while (0) | |
93 # endif | |
94 # endif | |
95 #endif | |
96 | |
97 /* Provide macros to feature the GCC function attribute. */ | |
98 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) | |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
99 # define ATTRS_DEFINED |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
100 # define ATTR_FORMAT(format_idx, arg_idx) \ |
0 | 101 __attribute__((format (printf, format_idx, arg_idx))) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
102 # define ATTR_FORMAT_ARG(arg_idx) \ |
0 | 103 __attribute__((format_arg (arg_idx))) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
104 # define ATTR_SCANF(format_idx, arg_idx) \ |
1409 | 105 __attribute__((format (scanf, format_idx, arg_idx))) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
106 # define ATTR_UNUSED __attribute__((unused)) |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
107 # define ATTR_NORETURN __attribute__((noreturn)) |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
108 # define ATTR_CONST __attribute__((const)) |
7911
3d65aeed7ea0
Added ATTR_PURE macro, which expands to pure attribute if available.
Timo Sirainen <tss@iki.fi>
parents:
7868
diff
changeset
|
109 # define ATTR_PURE __attribute__((pure)) |
0 | 110 #else |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
111 # define ATTR_FORMAT(format_idx, arg_idx) |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
112 # define ATTR_FORMAT_ARG(arg_idx) |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
113 # define ATTR_SCANF |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
114 # define ATTR_UNUSED |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
115 # define ATTR_NORETURN |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
116 # define ATTR_CONST |
7911
3d65aeed7ea0
Added ATTR_PURE macro, which expands to pure attribute if available.
Timo Sirainen <tss@iki.fi>
parents:
7868
diff
changeset
|
117 # define ATTR_PURE |
7204
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
118 #endif |
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
119 #if __GNUC__ > 2 |
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
120 # define ATTR_MALLOC __attribute__((malloc)) |
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
121 #else |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
122 # define ATTR_MALLOC |
5672
ca38eb4189e8
Added missing __attr_*__ macros for non-GCC compilers.
Timo Sirainen <tss@iki.fi>
parents:
5449
diff
changeset
|
123 #endif |
ca38eb4189e8
Added missing __attr_*__ macros for non-GCC compilers.
Timo Sirainen <tss@iki.fi>
parents:
5449
diff
changeset
|
124 #if __GNUC__ > 3 |
ca38eb4189e8
Added missing __attr_*__ macros for non-GCC compilers.
Timo Sirainen <tss@iki.fi>
parents:
5449
diff
changeset
|
125 /* GCC 4.0 and later */ |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
126 # define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
127 # define ATTR_SENTINEL __attribute__((sentinel)) |
5672
ca38eb4189e8
Added missing __attr_*__ macros for non-GCC compilers.
Timo Sirainen <tss@iki.fi>
parents:
5449
diff
changeset
|
128 #else |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
129 # define ATTR_WARN_UNUSED_RESULT |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
130 # define ATTR_SENTINEL |
0 | 131 #endif |
132 | |
1052
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
133 /* C99-style struct member definitions */ |
7868
04d86d65c469
MEMBER(): Don't try to use the C99 "." feature with HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
7204
diff
changeset
|
134 #if (defined(__STDC__) && __STDC_VERSION__ >= 199901L && \ |
04d86d65c469
MEMBER(): Don't try to use the C99 "." feature with HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
7204
diff
changeset
|
135 !defined(_HPUX_SOURCE)) || __GNUC__ > 2 |
1052
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
136 # define MEMBER(name) .name = |
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
137 #else |
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
138 # define MEMBER(name) |
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
139 #endif |
2f6225f9c170
Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added
Timo Sirainen <tss@iki.fi>
parents:
1048
diff
changeset
|
140 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
141 /* Macros to provide type safety for callback functions' context parameters */ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
142 #ifdef __GNUC__ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
143 # define CONTEXT_TYPE_SAFETY |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
144 #endif |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
145 #ifdef CONTEXT_TYPE_SAFETY |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
146 # define CONTEXT_CALLBACK(name, callback_type, callback, context, ...) \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
147 ({(void)(1 ? 0 : callback(context)); \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
148 name(__VA_ARGS__, (callback_type *)callback, context); }) |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
149 #else |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
150 # define CONTEXT_CALLBACK(name, callback_type, callback, context, ...) \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
151 name(__VA_ARGS__, (callback_type *)callback, context) |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
152 #endif |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4821
diff
changeset
|
153 |
7204
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
154 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) |
5449
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
155 # define HAVE_TYPEOF |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
156 # define COMPILE_ERROR_IF_TRUE(condition) \ |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
157 (sizeof(char[1 - 2 * !!(condition)]) - 1) |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
158 # define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) \ |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
159 COMPILE_ERROR_IF_TRUE( \ |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
160 !__builtin_types_compatible_p(typeof(_a), typeof(_b))) |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
161 #else |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
162 # define COMPILE_ERROR_IF_TRUE(condition) 0 |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
163 # define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) 0 |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
164 #endif |
bca896b09c7a
Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and
Timo Sirainen <tss@iki.fi>
parents:
5190
diff
changeset
|
165 |
0 | 166 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with |
167 macros, so we can refer to them as strings unconditionally. */ | |
168 #ifdef __GNUC__ | |
169 # define GNUC_FUNCTION __FUNCTION__ | |
170 # define GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ | |
171 #else | |
172 # define GNUC_FUNCTION "" | |
173 # define GNUC_PRETTY_FUNCTION "" | |
174 #endif | |
175 | |
7204
c3cb23ed73d1
Use malloc attribute, __builtin_expect() and __builtin_types_compatible_p()
Timo Sirainen <tss@iki.fi>
parents:
6862
diff
changeset
|
176 #if __GNUC__ > 2 |
6788
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
177 # define unlikely(expr) __builtin_expect(!!(expr), 0) |
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
178 # define likely(expr) __builtin_expect(!!(expr), 1) |
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
179 #else |
6862
ff884d70197b
unlikely() and likely() were broken with non-gcc.
Timo Sirainen <tss@iki.fi>
parents:
6788
diff
changeset
|
180 # define unlikely(expr) expr |
ff884d70197b
unlikely() and likely() were broken with non-gcc.
Timo Sirainen <tss@iki.fi>
parents:
6788
diff
changeset
|
181 # define likely(expr) expr |
6788
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
182 #endif |
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
183 |
0 | 184 /* Provide macros for error handling. */ |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
195
diff
changeset
|
185 #ifdef DISABLE_ASSERTS |
0 | 186 # define i_assert(expr) |
187 #elif defined (__GNUC__) && !defined (__STRICT_ANSI__) | |
188 | |
189 #define i_assert(expr) STMT_START{ \ | |
6788
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
190 if (unlikely(!(expr))) \ |
0 | 191 i_panic("file %s: line %d (%s): assertion failed: (%s)", \ |
6788
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
192 __FILE__, \ |
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
193 __LINE__, \ |
0 | 194 __PRETTY_FUNCTION__, \ |
195 #expr); }STMT_END | |
196 | |
197 #else /* !__GNUC__ */ | |
198 | |
199 #define i_assert(expr) STMT_START{ \ | |
6788
993760061348
Added likely() and unlikely() macros. Use unlikely() with asserts.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
200 if (unlikely(!(expr))) \ |
0 | 201 i_panic("file %s: line %d: assertion failed: (%s)", \ |
202 __FILE__, \ | |
203 __LINE__, \ | |
204 #expr); }STMT_END | |
205 | |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
195
diff
changeset
|
206 #endif |
0 | 207 |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
195
diff
changeset
|
208 #define i_unreached() \ |
2755
13c70c53cb55
i_unreached(): show also file and line number in error message
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
209 i_panic("file %s: line %d: unreached", __FILE__, __LINE__) |
0 | 210 |
211 #endif |