24 const char *fmt, ...);
29 const char *fmt, ...);
45 const char *fmt, ...);
68 #define QPMS_WARN(msg, ...) qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__)
74 #define QPMS_WARN_ONCE(msg, ...) {\
75 static _Bool already_bitched = 0; \
76 if (QPMS_UNLIKELY(!already_bitched)) {\
77 qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__);\
92 #define QPMS_DEBUG(type , msg, ...) qpms_debug_at_flf(__FILE__,__LINE__,__func__,type,msg, ##__VA_ARGS__)
109 #define QPMS_CRASHING_MALLOC(pointer, size) {\
110 (pointer) = malloc(size);\
111 if(QPMS_UNLIKELY(!(pointer) && (size)))\
112 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
113 "Allocation of %zd bytes for " #pointer " failed.",\
124 #define QPMS_CRASHING_MALLOCPY(dest, src, size) {\
125 (dest) = malloc(size);\
126 if(QPMS_UNLIKELY(!(dest) && (size)))\
127 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
128 "Allocation of %zd bytes for " #dest " failed.",\
130 memcpy((dest), (src), (size));\
148 #define QPMS_CRASHING_CALLOC(pointer, nmemb, size) {\
149 (pointer) = calloc((nmemb), (size));\
150 if(QPMS_UNLIKELY(!(pointer) && (nmemb) && (size)))\
151 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
152 "Allocation of %zd bytes for " #pointer " failed.",\
153 (size_t)((nmemb)*(size)));\
171 #define QPMS_CRASHING_REALLOC(pointer, size) {\
172 (pointer) = realloc((pointer), size);\
173 if(QPMS_UNLIKELY(!(pointer) && (size)))\
174 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
175 "Rellocation of %zd bytes for " #pointer " failed.",\
181 #define QPMS_WTF qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Unexpected error.")
184 #define QPMS_INVALID_ENUM(x) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Invalid enum value (" #x " == %d)", (int) (x))
187 #define QPMS_UNTESTED {\
188 static _Bool already_bitched = 0; \
189 if (QPMS_UNLIKELY(!already_bitched)) {\
190 qpms_warn_at_flf(__FILE__,__LINE__,__func__,"Warning: untested function/feature!");\
191 already_bitched = 1;\
197 #define QPMS_PR_ERROR(msg, ...) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__)
200 #define QPMS_ENSURE_SUCCESS(x) { \
201 int errorcode = (x); \
202 if(QPMS_UNLIKELY(errorcode)) \
203 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Unexpected error (%d)", errorcode); \
207 #define QPMS_ENSURE_SUCCESS_M(x, msg, ...) { \
208 int errorcode = (x); \
209 if(QPMS_UNLIKELY(errorcode)) \
210 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__); \
214 #define QPMS_ENSURE_SUCCESS_OR(x, ...) { \
215 int errorcode = (x); \
216 static const int allowed_errorcodes[] = {0, ##__VA_ARGS__};\
217 static const int n_allowed = sizeof(allowed_errorcodes) / sizeof(int); \
219 for(i = 0; i < n_allowed; ++i) \
220 if (errorcode == allowed_errorcodes[i]) break; \
221 if (QPMS_UNLIKELY(i >= n_allowed)) \
222 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Unexpected error (%d)", errorcode); \
226 #define QPMS_ENSURE(x, msg, ...) {if(QPMS_UNLIKELY(!(x))) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__); }
234 #define QPMS_ASSERT(x) {\
235 if(QPMS_UNLIKELY(!(x)))\
236 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
237 "Unexpected error. This is most certainly a bug.");\
240 #ifdef QPMS_EVALUATE_PARANOID_ASSERTS
245 #define QPMS_PARANOID_ASSERT(x) {\
246 if(QPMS_UNLIKELY(!(x)))\
247 qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,\
248 "Unexpected error. This is most certainly a bug.");\
251 #define QPMS_PARANOID_ASSERT(x) {;}
256 #define QPMS_NOT_IMPLEMENTED(msg, ...) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__, \
257 "Not implemented:" msg, ##__VA_ARGS__)
261 #define QPMS_INCOMPLETE_IMPLEMENTATION(msg, ...) {\
262 static _Bool already_bitched = 0; \
263 if (QPMS_UNLIKELY(!already_bitched)) {\
264 qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__);\
265 already_bitched = 1;\
Macros for compiler optimisation.
QPMS_NORETURN void qpms_pr_error_at_flf(const char *filename, unsigned int linenum, const char *func, const char *fmt,...)
Print an error message, indicating source, function name and line number, and abort().
Definition: error.c:43
qpms_dbgmsg_flags qpms_dbgmsg_enable(qpms_dbgmsg_flags types)
Disable debugging messages of given types.
Definition: error.c:8
qpms_dbgmsg_flags
Classification of debugging messages.
Definition: qpms_error.h:35
@ QPMS_DBGMSG_INTEGRATION
Quadrature-related debug messages.
Definition: qpms_error.h:38
@ QPMS_DBGMSG_THREADS
Multithreading-related debug messages.
Definition: qpms_error.h:37
QPMS_NORETURN void qpms_pr_error(const char *fmt,...)
Print error message and abort();.
Definition: error.c:16
qpms_dbgmsg_flags qpms_dbgmsg_enabled
Global variable determining which types of debug messages shall be printed with QPMS_DEBUG().
Definition: error.c:6
qpms_dbgmsg_flags qpms_dbgmsg_disable(qpms_dbgmsg_flags types)
Enable debugging messages of given types.
Definition: error.c:12
void qpms_debug_at_flf(const char *filename, unsigned int linenum, const char *func, qpms_dbgmsg_flags type, const char *fmt,...)
Print a debugging message to stderr and flush the buffer. Don't call this directly,...
Definition: error.c:69
void qpms_warn_at_flf(const char *filename, unsigned int linenum, const char *func, const char *fmt,...)
Print a warning message to stderr and flush the buffer. Don't call this directly, use QPMS_WARN().
Definition: error.c:57