CAPS Universe documentation
1.0.4
All you need to know to be successful
|
Failure API used all over the CAPS universe. More...
Macros | |
#define | caps_developers_failure_report(fmt) |
#define | caps_memory_failure_report(fn) |
#define | caps_assert(expr) |
Assert the given expression is true, else terminate the program. | |
Functions | |
void | caps_developers_failure_report_and_terminate (const char *scope, const char *fn, int ln, const char *message) |
void | caps_memory_failure_report_and_terminate (const char *scope, const char *fn, int ln) |
void | caps_terminate (int rc) |
Don't do failure reporting and termination by your own, use the functions provided by this library instead.
#define caps_developers_failure_report | ( | fmt | ) |
Convenience macro to report a bad usage
It parametrizes the call to caps_developers_failure_report_and_terminate()
#define caps_memory_failure_report | ( | fn | ) |
Convenience macro to report a lack of memory
Since the system is out of resources, it is most of the time a useless action to report more than the function name here. Use the __func__
macro provided by the compiler.
It parametrizes the call to caps_memory_failure_report_and_terminate()
#define caps_assert | ( | expr | ) |
[in] | expr | The expression to check |
Creates an error message of the form:
<filename>:<line number>: <function name>: Assertion '<assertion>' failed
and a stack trace (if supported on the architecture) and terminates (or aborts) the program.
It uses caps_terminate() to terminate.
void caps_developers_failure_report_and_terminate | ( | const char * | scope, |
const char * | fn, | ||
int | ln, | ||
const char * | message | ||
) |
Report a bad usage of something and terminate
[in] | message | Main failure description (in English) without newline |
[in] | scope | The report's scope, like it's package name |
[in] | fn | Name of the function, this report is from |
[in] | ln | Line number this call is from |
Report the message and add a stack trace when debugging is enabled. Then terminate.
The goal is to terminate whenever something is used in a bad way. This should force the developer to fix the code and do things right. I know this is a pain - but it is intentional.
Refer Abort or Exit Choice how to setup if exit() or abort() is used to terminate.
message
has no printf() style. It is just one fixed string.void caps_memory_failure_report_and_terminate | ( | const char * | scope, |
const char * | fn, | ||
int | ln | ||
) |
Report a memory failure and terminate
[in] | scope | The report's scope, like it's package name |
[in] | fn | The function name where the failure happened |
[in] | ln | Line number this call is from |
Report something when the system is out of resources is most of the time a useless action. But we can still try... and then terminate/abort the process
Refer Abort or Exit Choice how to setup if exit() or abort() is used to terminate.
void caps_terminate | ( | int | rc | ) |
Generic function to terminate with a backtrace. It is more a development feature
[in] | rc | Return value to the OS, used if '–disable-abort' is used while configuration |
Refer Abort or Exit Choice how to setup if exit() or abort() is used to terminate.