Safety checks are a set of macros to check for parameters or values that should never happen, it is similar in concept to assert(), but will log and return instead of abort() your program.
More...
|
#define | EINA_SAFETY_ON_NULL_RETURN(exp) |
|
#define | EINA_SAFETY_ON_NULL_RETURN_VAL(exp, val) |
|
#define | EINA_SAFETY_ON_NULL_GOTO(exp, label) |
|
#define | EINA_SAFETY_ON_TRUE_RETURN(exp) |
|
#define | EINA_SAFETY_ON_TRUE_RETURN_VAL(exp, val) |
|
#define | EINA_SAFETY_ON_TRUE_GOTO(exp, label) |
|
#define | EINA_SAFETY_ON_FALSE_RETURN(exp) |
|
#define | EINA_SAFETY_ON_FALSE_RETURN_VAL(exp, val) |
|
#define | EINA_SAFETY_ON_FALSE_GOTO(exp, label) |
|
#define | EINA_ARG_NONNULL(...) |
|
Safety checks are a set of macros to check for parameters or values that should never happen, it is similar in concept to assert(), but will log and return instead of abort() your program.
- Warning
eina_safety_checks.h
should only be included by source files, after all other includes and before the source file specific includes. By source file specific includes we mean those that define the functions that are being checked. The reason for such complexity is the trick to avoid compiler optimizations. If compilers are told that some given function will never receive NULL
(EINA_ARG_NONNULL(), then compiler will emit a warning if it detects so (good!) but will remove any checks for that condition as it believes it will never happen, removing all safety checks! By including eina_safety_checks.h
it will redefine EINA_ARG_NONNULL() to void and compiler warning will not be emitted, but checks will be there. The files already processed with the old macro EINA_ARG_NONNULL() will still work and emit the warnings.
#include <Evas.h>
#include <Ecore.h>
#include <eina_safety_checks.h>
#include "my_functions1.h"
#include "my_functions2.h"
Since these cases should never happen, one may wantto keep safety checks enabled during tests but disable then during deploy, not doing any checks at all. This is a common requirement for embedded systems. Whenever to check or not should be set during compile time by using –disable-safety-checks
or –enable-safety-checks
options to configure
script.
Whenever these macros capture an error, EINA_LOG_ERR() will be called.
- See Also
- EINA_SAFETY_ON_NULL_RETURN(), EINA_SAFETY_ON_NULL_RETURN_VAL() and other macros.
#define EINA_SAFETY_ON_NULL_RETURN |
( |
|
exp | ) |
|
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" == NULL"); \
return; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_NULL_RETURN_VAL |
( |
|
exp, |
|
|
|
val |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" == NULL"); \
return (val); \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_NULL_GOTO |
( |
|
exp, |
|
|
|
label |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" == NULL"); \
goto label; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_TRUE_RETURN |
( |
|
exp | ) |
|
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is true"); \
return; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_TRUE_RETURN_VAL |
( |
|
exp, |
|
|
|
val |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is true"); \
return val; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_TRUE_GOTO |
( |
|
exp, |
|
|
|
label |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is true"); \
goto label; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_FALSE_RETURN |
( |
|
exp | ) |
|
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is false"); \
return; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_FALSE_RETURN_VAL |
( |
|
exp, |
|
|
|
val |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is false"); \
return val; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
#define EINA_SAFETY_ON_FALSE_GOTO |
( |
|
exp, |
|
|
|
label |
|
) |
| |
Value:do \
{ \
EINA_LOG_ERR(
"%s",
"safety check failed: " # exp
" is false"); \
goto label; \
} \
} \
while (0)
#define EINA_UNLIKELY(exp)
Definition: eina_types.h:282
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376