Safety Checks

Macros | Variables
Safety Checks
Eina » Tools

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...

## Macros
#define | EINA_SAFETY_ON_NULL_RETURN(exp) do { (void)(!(exp)); } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_NULL_RETURN_VAL(exp, val) do { if (0 && !(exp)) { (void)val; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_NULL_GOTO(exp, label) do { if (0 && (exp) == NULL) { goto label; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_TRUE_RETURN(exp) do { (void)(exp); } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_TRUE_RETURN_VAL(exp, val) do { if (0 && (exp)) { (void)val; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_TRUE_GOTO(exp, label) do { if (0 && (exp)) { goto label; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_FALSE_RETURN(exp) do { (void)(!(exp)); } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_FALSE_RETURN_VAL(exp, val) do { if (0 && !(exp)) { (void)val; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...
#define | EINA_SAFETY_ON_FALSE_GOTO(exp, label) do { if (0 && !(exp)) { goto label; } } while (0)
| The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. More...

## Variables
EINA_API Eina_Error | EINA_ERROR_SAFETY_FAILED

## Detailed Description

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 the compiler will emit a warning if it detects so (good!) and also will remove any checks for that condition as it believes it will never happen, removing all safety checks! By including `eina_safety_checks.h` last 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.

// all these files will emit warning from EINA_ARG_NONNULL()
#include <Evas.h> // third party headers
#include <Ecore.h>
#include <eina_safety_checks.h>
// all the files below will NOT emit warning from EINA_ARG_NONNULL(),
// but this is required to have the functions defined there to be checked
// for NULL pointers
#include "my_functions1.h"
#include "my_functions2.h"

Since these cases should never happen, one may want to keep safety checks enabled during tests but disable them during deploy, not doing any checks at all. This is a common requirement for embedded systems. When 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.

## Macro Definition Documentation

## ◆ EINA_SAFETY_ON_NULL_RETURN

#define EINA_SAFETY_ON_NULL_RETURN | ( |  | exp | ) | do { (void)(!(exp)); } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.

## ◆ EINA_SAFETY_ON_NULL_RETURN_VAL

#define EINA_SAFETY_ON_NULL_RETURN_VAL | ( |  | exp,
|  |  | val
| ) |  | do { if (0 && !(exp)) { (void)val; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | val | The value to be returned.

## ◆ EINA_SAFETY_ON_NULL_GOTO

#define EINA_SAFETY_ON_NULL_GOTO | ( |  | exp,
|  |  | label
| ) |  | do { if (0 && (exp) == NULL) { goto label; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | label | The label to jump to.

Examples
  banshee.c.

## ◆ EINA_SAFETY_ON_TRUE_RETURN

#define EINA_SAFETY_ON_TRUE_RETURN | ( |  | exp | ) | do { (void)(exp); } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.

Examples
  banshee.c.

## ◆ EINA_SAFETY_ON_TRUE_RETURN_VAL

#define EINA_SAFETY_ON_TRUE_RETURN_VAL | ( |  | exp,
|  |  | val
| ) |  | do { if (0 && (exp)) { (void)val; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | val | The value to be returned.

## ◆ EINA_SAFETY_ON_TRUE_GOTO

#define EINA_SAFETY_ON_TRUE_GOTO | ( |  | exp,
|  |  | label
| ) |  | do { if (0 && (exp)) { goto label; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | label | The label to jump to.

## ◆ EINA_SAFETY_ON_FALSE_RETURN

#define EINA_SAFETY_ON_FALSE_RETURN | ( |  | exp | ) | do { (void)(!(exp)); } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.

## ◆ EINA_SAFETY_ON_FALSE_RETURN_VAL

#define EINA_SAFETY_ON_FALSE_RETURN_VAL | ( |  | exp,
|  |  | val
| ) |  | do { if (0 && !(exp)) { (void)val; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | val | The value to be returned.

## ◆ EINA_SAFETY_ON_FALSE_GOTO

#define EINA_SAFETY_ON_FALSE_GOTO | ( |  | exp,
|  |  | label
| ) |  | do { if (0 && !(exp)) { goto label; } } while (0)

The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined.

Parameters

  [in] | exp | The expression to be evaluated.
  [in] | label | The label to jump to.