QPMS
Electromagnetic multiple scattering library and toolkit.
|
QPMS miscellanous internal error handling functions and macros. More...
#include "optim.h"
Go to the source code of this file.
Macros | |
#define | QPMS_WARN(msg, ...) qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) |
Print a warning to stderr and flush the buffer. More... | |
#define | QPMS_WARN_ONCE(msg, ...) |
Print a warning to stderr and flush the buffer – only once per run (or current thread). More... | |
#define | QPMS_DEBUG(type, msg, ...) qpms_debug_at_flf(__FILE__,__LINE__,__func__,type,msg, ##__VA_ARGS__) |
Print a debugging message to stderr and flush the buffer. More... | |
#define | QPMS_CRASHING_MALLOC(pointer, size) |
Wrapper macro of standard malloc(), crashing on failure. More... | |
#define | QPMS_CRASHING_MALLOCPY(dest, src, size) |
Allocate and copy. More... | |
#define | QPMS_CRASHING_CALLOC(pointer, nmemb, size) |
Wrapper macro of standard calloc(), crashing on failure. More... | |
#define | QPMS_CRASHING_REALLOC(pointer, size) |
Wrapper macro of standard realloc(), crashing on failure. More... | |
#define | QPMS_WTF qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Unexpected error.") |
Prints an "unexpected error" message and aborts the program. More... | |
#define | QPMS_INVALID_ENUM(x) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Invalid enum value (" #x " == %d)", (int) (x)) |
Aborts the program with "invalid enumerator" error message. | |
#define | QPMS_UNTESTED |
Prints an "untested function/feature" warning once when reached in the code. More... | |
#define | QPMS_PR_ERROR(msg, ...) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) |
Prints a given error message and aborts the program. More... | |
#define | QPMS_ENSURE_SUCCESS(x) |
Raises an error if x is not zero. More... | |
#define | QPMS_ENSURE_SUCCESS_M(x, msg, ...) |
Raises an error if x is not zero, with custom error message. More... | |
#define | QPMS_ENSURE_SUCCESS_OR(x, ...) |
Raises an error if x is not zero or one of the values listed in arguments. More... | |
#define | QPMS_ENSURE(x, msg, ...) {if(QPMS_UNLIKELY(!(x))) qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__); } |
Raises an error if x is not true, with custom error message. | |
#define | QPMS_ASSERT(x) |
Raises an error if x is false. More... | |
#define | QPMS_PARANOID_ASSERT(x) {;} |
#define | QPMS_NOT_IMPLEMENTED(msg, ...) |
Raises a "not implemented" error with additional custom message. More... | |
#define | QPMS_INCOMPLETE_IMPLEMENTATION(msg, ...) |
Prints an "incomplete implementation" warning once with a custom message. More... | |
Enumerations | |
enum | qpms_dbgmsg_flags { QPMS_DBGMSG_MISC = 1 , QPMS_DBGMSG_THREADS = 2 , QPMS_DBGMSG_INTEGRATION = 4 } |
Classification of debugging messages. More... | |
Functions | |
QPMS_NORETURN void | qpms_pr_error (const char *fmt,...) |
Print error message and abort();. | |
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(). More... | |
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(). | |
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, use QPMS_DEBUG(). | |
qpms_dbgmsg_flags | qpms_dbgmsg_disable (qpms_dbgmsg_flags types) |
Enable debugging messages of given types. More... | |
qpms_dbgmsg_flags | qpms_dbgmsg_enable (qpms_dbgmsg_flags types) |
Disable debugging messages of given types. More... | |
Variables | |
qpms_dbgmsg_flags | qpms_dbgmsg_enabled |
Global variable determining which types of debug messages shall be printed with QPMS_DEBUG(). More... | |
QPMS miscellanous internal error handling functions and macros.
#define QPMS_ASSERT | ( | x | ) |
Raises an error if x is false.
Currently, this is always expanded, ignoring the possible NDEBUG macro. In places where the evaluation could have significant performance impact, consider using QPMS_PARANOID_ASSERT() instead.
#define QPMS_CRASHING_CALLOC | ( | pointer, | |
nmemb, | |||
size | |||
) |
Wrapper macro of standard calloc(), crashing on failure.
Normally corresponds to a pointer = calloc(nmemb, size)
statement; however, if NULL is returned, this prints an error message and abort()s the program.
The arguments are expanded several times.
Note that this macro expands to a code block, to be kept in mind when using together with if/else etc.
Assigned memory block is to be deallocated with standard free().
#define QPMS_CRASHING_MALLOC | ( | pointer, | |
size | |||
) |
Wrapper macro of standard malloc(), crashing on failure.
Normally corresponds to a pointer = malloc(size)
statement; however, if NULL is returned, this prints an error message and abort()s the program.
The arguments are expanded several times.
Note that this macro expands to a code block, to be kept in mind when using together with if/else etc.
Assigned memory block is to be deallocated with standard free().
#define QPMS_CRASHING_MALLOCPY | ( | dest, | |
src, | |||
size | |||
) |
Allocate and copy.
Behaves as QPMS_CRASHING_MALLOC(dest, size), but additionaly copies a chunk of memory from src to dest.
#define QPMS_CRASHING_REALLOC | ( | pointer, | |
size | |||
) |
Wrapper macro of standard realloc(), crashing on failure.
Normally corresponds to a pointer = realloc(pointer, size)
statement; however, if NULL is returned, this prints an error message and abort()s the program.
The arguments are expanded several times.
Note that this macro expands to a code block, to be kept in mind when using together with if/else etc.
Assigned memory block is to be deallocated with standard free().
#define QPMS_DEBUG | ( | type, | |
msg, | |||
... | |||
) | qpms_debug_at_flf(__FILE__,__LINE__,__func__,type,msg, ##__VA_ARGS__) |
Print a debugging message to stderr and flush the buffer.
The arguments after type are the same as in standard printf().
The debugging message is printed only if the corresponding type flag is set in qpms_dbgmsg_enabled.
#define QPMS_ENSURE_SUCCESS | ( | x | ) |
Raises an error if x is not zero.
#define QPMS_ENSURE_SUCCESS_M | ( | x, | |
msg, | |||
... | |||
) |
Raises an error if x is not zero, with custom error message.
#define QPMS_ENSURE_SUCCESS_OR | ( | x, | |
... | |||
) |
Raises an error if x is not zero or one of the values listed in arguments.
#define QPMS_INCOMPLETE_IMPLEMENTATION | ( | msg, | |
... | |||
) |
Prints an "incomplete implementation" warning once with a custom message.
Serves mainly as a label/placeholder of incomplete parts of the code.
#define QPMS_NOT_IMPLEMENTED | ( | msg, | |
... | |||
) |
Raises a "not implemented" error with additional custom message.
Serves also as a label/placeholder of not implemented parts of the code.
#define QPMS_PR_ERROR | ( | msg, | |
... | |||
) | qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) |
Prints a given error message and aborts the program.
The arguments are as in standard printf().
#define QPMS_UNTESTED |
Prints an "untested function/feature" warning once when reached in the code.
#define QPMS_WARN | ( | msg, | |
... | |||
) | qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) |
Print a warning to stderr and flush the buffer.
The arguments are the same as in standard printf().
#define QPMS_WARN_ONCE | ( | msg, | |
... | |||
) |
Print a warning to stderr and flush the buffer – only once per run (or current thread).
The arguments are the same as in standard printf().
#define QPMS_WTF qpms_pr_error_at_flf(__FILE__,__LINE__,__func__,"Unexpected error.") |
Prints an "unexpected error" message and aborts the program.
Usually only put to presumably unreachable places in the code and similar.
enum qpms_dbgmsg_flags |
qpms_dbgmsg_flags qpms_dbgmsg_disable | ( | qpms_dbgmsg_flags | types | ) |
Enable debugging messages of given types.
qpms_dbgmsg_flags qpms_dbgmsg_enable | ( | qpms_dbgmsg_flags | types | ) |
Disable debugging messages of given types.
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().
Usually not used directly, but rather via some of the macros that fill the first arguments automatically.
|
extern |
Global variable determining which types of debug messages shall be printed with QPMS_DEBUG().
Use qpms_dbgmsg_enable() and qpms_dbgmsg_disable() to manipulate this variable.