134
144
/* Macros to provide type safety for callback functions' context parameters */
136
# define CONTEXT_TYPE_SAFETY
138
#ifdef CONTEXT_TYPE_SAFETY
139
# define CONTEXT_CALLBACK(name, callback_type, callback, context, ...) \
140
({(void)(1 ? 0 : callback(context)); \
141
name(__VA_ARGS__, (callback_type *)callback, context); })
142
# define CONTEXT_CALLBACK2(name, callback_type, callback, arg1_type, context, ...) \
143
({(void)(1 ? 0 : callback((arg1_type)0, context)); \
144
name(__VA_ARGS__, (callback_type *)callback, context); })
145
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))
146
# define CALLBACK_TYPECHECK(callback, type) \
147
(COMPILE_ERROR_IF_TRUE(!__builtin_types_compatible_p( \
148
typeof(&callback), type)) ? 1 : 0)
146
# define CONTEXT_CALLBACK(name, callback_type, callback, context, ...) \
147
name(__VA_ARGS__, (callback_type *)callback, context)
148
# define CONTEXT_CALLBACK2(name, callback_type, callback, arg1_type, context, ...) \
149
name(__VA_ARGS__, (callback_type *)callback, context)
150
# define CALLBACK_TYPECHECK(callback, type) 0
152
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
153
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) && !defined(__cplusplus)
154
154
# define COMPILE_ERROR_IF_TRUE(condition) \
155
155
(sizeof(char[1 - 2 * !!(condition)]) - 1)
156
156
# define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) \
157
157
COMPILE_ERROR_IF_TRUE( \
158
158
!__builtin_types_compatible_p(typeof(_a), typeof(_b)))
159
#define COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE(_a1, _a2, _b) \
160
COMPILE_ERROR_IF_TRUE( \
161
!__builtin_types_compatible_p(typeof(_a1), typeof(_b)) && \
162
!__builtin_types_compatible_p(typeof(_a2), typeof(_b)))
160
164
# define COMPILE_ERROR_IF_TRUE(condition) 0
161
165
# define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) 0
166
# define COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE(_a1, _a2, _b) 0
201
#define i_close_fd(fd) STMT_START { \
202
if (unlikely(close_keep_errno(fd) < 0)) \
203
i_error("close(%d[%s:%d]) failed: %m", \
204
*(fd), __FILE__, __LINE__); \
196
207
#define i_unreached() \
197
208
i_panic("file %s: line %d: unreached", __FILE__, __LINE__)
210
/* Convenience macros to test the versions of dovecot. */
211
#if defined DOVECOT_VERSION_MAJOR && defined DOVECOT_VERSION_MINOR
212
# define DOVECOT_PREREQ(maj, min) \
213
((DOVECOT_VERSION_MAJOR << 16) + DOVECOT_VERSION_MINOR >= ((maj) << 16) + (min))
215
# define DOVECOT_PREREQ(maj, min) 0