From: Enlightenment S. <no-...@en...> - 2010-04-30 14:54:12
|
Log: 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. Author: lucas Date: 2010-04-30 07:54:05 -0700 (Fri, 30 Apr 2010) New Revision: 48478 Modified: trunk/eina/src/include/eina_safety_checks.h Modified: trunk/eina/src/include/eina_safety_checks.h =================================================================== --- trunk/eina/src/include/eina_safety_checks.h 2010-04-30 14:39:04 UTC (rev 48477) +++ trunk/eina/src/include/eina_safety_checks.h 2010-04-30 14:54:05 UTC (rev 48478) @@ -126,6 +126,18 @@ } \ 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 @@ } \ 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 |