Safety Checks
[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...Defines | |
#define | EINA_SAFETY_ON_NULL_RETURN(exp) do { (void)(!(exp)); } while (0) |
The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. | |
#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. | |
#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. | |
#define | EINA_SAFETY_ON_TRUE_RETURN(exp) do { (void)(exp); } while (0) |
The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. | |
#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. | |
#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. | |
#define | EINA_SAFETY_ON_FALSE_RETURN(exp) do { (void)(!(exp)); } while (0) |
The macro doesn't do anything unless EINA_SAFETY_CHECKS is defined. | |
#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. | |
#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. | |
Variables | |
Eina_Error | EINA_ERROR_SAFETY_FAILED |
Error identifier corresponding to safety check failure. |
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 receiveNULL
(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 includingeina_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.
// all these files will emit warning from EINA_ARG_NONNULL() #include <Evas.h> // third party headers #include <Ecore.h> #include <eina_error.h> // eina own header #include <eina_safety_checks.h> // all these 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 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 and eina_error
set to EINA_ERROR_SAFETY_FAILED
and can be checked with eina_error_get() after call.
- See also:
- EINA_SAFETY_ON_NULL_RETURN(), EINA_SAFETY_ON_NULL_RETURN_VAL() and other macros.
Define Documentation
#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:
-
exp The expression to be evaluated.
Referenced by eina_accessor_free(), eina_accessor_over(), eina_array_flush(), eina_array_free(), eina_array_step_set(), eina_counter_free(), eina_counter_start(), eina_counter_stop(), eina_file_close(), eina_file_map_free(), eina_hash_foreach(), eina_hash_free_cb_set(), eina_inarray_reverse(), eina_inarray_sort(), eina_inarray_step_set(), eina_iterator_foreach(), eina_iterator_free(), eina_log_domain_level_set(), eina_module_list_free(), eina_module_list_load(), eina_module_list_unload(), eina_rbtree_delete(), eina_rectangle_free(), eina_rectangle_pool_data_set(), eina_rectangle_pool_free(), eina_rectangle_pool_release(), and eina_value_free().
#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:
-
exp The expression to be evaluated. val The value to be returned.
Referenced by eina_accessor_container_get(), eina_accessor_data_get(), eina_accessor_lock(), eina_accessor_unlock(), eina_array_accessor_new(), eina_array_iterator_new(), eina_array_remove(), eina_convert_atod(), eina_convert_dtoa(), eina_convert_fptoa(), eina_convert_itoa(), eina_convert_xtoa(), eina_counter_dump(), eina_counter_new(), eina_error_find(), eina_error_msg_modify(), eina_error_msg_register(), eina_error_msg_static_register(), eina_file_dir_list(), eina_file_direct_ls(), eina_file_filename_get(), eina_file_ls(), eina_file_map_all(), eina_file_map_faulted(), eina_file_map_new(), eina_file_mtime_get(), eina_file_open(), eina_file_size_get(), eina_file_split(), eina_file_stat_ls(), eina_file_statat(), eina_file_xattr_get(), eina_file_xattr_value_get(), eina_hash_add(), eina_hash_del(), eina_hash_del_by_data(), eina_hash_del_by_hash(), eina_hash_del_by_key(), eina_hash_del_by_key_hash(), eina_hash_direct_add(), eina_hash_find(), eina_hash_find_by_hash(), eina_hash_iterator_data_new(), eina_hash_iterator_key_new(), eina_hash_iterator_tuple_new(), eina_hash_modify(), eina_hash_modify_by_hash(), eina_hash_move(), eina_hash_new(), eina_hash_set(), eina_inarray_foreach(), eina_inarray_foreach_remove(), eina_inarray_insert(), eina_inarray_insert_sorted(), eina_inarray_push(), eina_inarray_remove(), eina_inarray_search(), eina_inarray_search_sorted(), eina_inlist_append(), eina_inlist_append_relative(), eina_inlist_demote(), eina_inlist_find(), eina_inlist_prepend(), eina_inlist_prepend_relative(), eina_inlist_promote(), eina_inlist_remove(), eina_inlist_sort(), eina_inlist_sorted_insert(), eina_iterator_container_get(), eina_iterator_lock(), eina_iterator_next(), eina_iterator_unlock(), eina_list_move(), eina_list_move_list(), eina_list_sort(), eina_list_sorted_merge(), eina_log_domain_level_get(), eina_log_domain_register(), eina_magic_string_set(), eina_magic_string_static_set(), eina_matrixsparse_cell_idx_get(), eina_module_environment_path_get(), eina_module_file_get(), eina_module_free(), eina_module_load(), eina_module_new(), eina_module_symbol_get(), eina_module_symbol_path_get(), eina_module_unload(), eina_rbtree_inline_insert(), eina_rbtree_inline_remove(), eina_rectangle_pool_count(), eina_rectangle_pool_data_get(), eina_rectangle_pool_geometry_get(), eina_rectangle_pool_get(), eina_rectangle_pool_request(), eina_strbuf_replace(), eina_strbuf_replace_all(), eina_unicode_escape(), eina_unicode_strcmp(), eina_unicode_strcpy(), eina_unicode_strdup(), eina_unicode_strncpy(), eina_unicode_strndup(), eina_unicode_strnlen(), eina_unicode_strstr(), eina_unicode_unicode_to_utf8(), eina_unicode_utf8_get_len(), eina_unicode_utf8_get_next(), eina_unicode_utf8_get_prev(), eina_unicode_utf8_to_unicode(), eina_value_convert(), eina_value_copy(), eina_value_to_string(), eina_value_type_check(), eina_xattr_double_get(), eina_xattr_get(), eina_xattr_int_get(), eina_xattr_ls(), eina_xattr_set(), eina_xattr_string_set(), and eina_xattr_value_ls().
#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:
-
exp The expression to be evaluated. label The label to jump to.
#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:
-
exp The expression to be evaluated.
Referenced by eina_inarray_step_set().
#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:
-
exp The expression to be evaluated. val The value to be returned.
Referenced by eina_file_dir_list(), eina_hash_new(), eina_inarray_alloc_at(), eina_inarray_insert_at(), eina_inarray_new(), eina_inarray_nth(), eina_inarray_pop(), eina_inarray_remove_at(), eina_inarray_replace_at(), eina_log_domain_registered_level_get(), eina_xattr_get(), and eina_xattr_set().
#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:
-
exp The expression to be evaluated. label The label to jump to.
#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:
-
exp The expression to be evaluated.
Referenced by eina_accessor_over(), and eina_log_domain_unregister().
#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:
-
exp The expression to be evaluated. val The value to be returned.
Referenced by eina_log_domain_registered_level_get(), eina_matrixsparse_cell_idx_clear(), eina_matrixsparse_cell_idx_get(), eina_matrixsparse_column_idx_clear(), eina_matrixsparse_data_idx_replace(), eina_matrixsparse_data_idx_set(), eina_matrixsparse_new(), eina_matrixsparse_row_idx_clear(), eina_matrixsparse_size_set(), eina_module_new(), eina_value_array_new(), eina_value_convert(), eina_value_copy(), eina_value_hash_new(), eina_value_list_new(), eina_value_to_string(), and eina_value_type_name_get().
#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:
-
exp The expression to be evaluated. label The label to jump to.