Define new error handling macros

EINA_SAFETY_ON_TRUE_GOTO and EINA_SAFETY_ON_FALSE_GOTO are now defined
to ease error handling. Functions might need to take actions before
returning upon safety checks fail.




SVN revision: 48478
This commit is contained in:
Lucas De Marchi 2010-04-30 14:54:05 +00:00
parent 7713be2a89
commit c98e00eec0
1 changed files with 24 additions and 0 deletions

View File

@ -126,6 +126,18 @@ EAPI extern Eina_Error EINA_ERROR_SAFETY_FAILED;
} \
while (0)
#define EINA_SAFETY_ON_TRUE_GOTO(exp, label) \
do \
{ \
if (EINA_UNLIKELY(exp)) \
{ \
eina_error_set(EINA_ERROR_SAFETY_FAILED); \
EINA_LOG_ERR("%s", "safety check failed: " #exp " is true"); \
goto label; \
} \
} \
while (0)
#define EINA_SAFETY_ON_FALSE_RETURN(exp) \
do \
{ \
@ -150,6 +162,18 @@ EAPI extern Eina_Error EINA_ERROR_SAFETY_FAILED;
} \
while (0)
#define EINA_SAFETY_ON_FALSE_GOTO(exp, label) \
do \
{ \
if (EINA_UNLIKELY(!(exp))) \
{ \
eina_error_set(EINA_ERROR_SAFETY_FAILED); \
EINA_LOG_ERR("%s", "safety check failed: " #exp " is false"); \
goto label; \
} \
} \
while (0)
#ifdef EINA_ARG_NONNULL
/* make EINA_ARG_NONNULL void so GCC does not optimize safety checks */
#undef EINA_ARG_NONNULL