#include "eina_log.h"
#include "eina_safety_checks.h"
-/*============================================================================*
-* Local *
-*============================================================================*/
+EAPI Eina_Error EINA_ERROR_SAFETY_FAILED = 0;
-/*============================================================================*
-* Global *
-*============================================================================*/
+static int EINA_SAFETY_LOG_DOMAIN = 0;
+static int initcnt = 0;
/**
- * @internal
- * @brief Shut down the safety checks module.
+ * Log entry-point called every time an eina safety check fails.
*
- * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ * One purpose of this dedicated function is to provide a convenient breakpoint
+ * for GDB debugging. Also, this gives it a dedicated log domain, rather than
+ * using the default one.
*
- * This function shuts down the error module set up by
- * eina_safety_checks_init(). It is called by eina_shutdown().
- *
- * @see eina_shutdown()
+ * @since 1.17
+ * @internal
*/
Eina_Bool
eina_safety_checks_shutdown(void)
{
+ if (!initcnt) return EINA_FALSE;
+ if (!(--initcnt))
+ {
+ eina_log_domain_unregister(EINA_SAFETY_LOG_DOMAIN);
+ EINA_SAFETY_LOG_DOMAIN = 0;
+ }
return EINA_TRUE;
}
-/*============================================================================*
-* API *
-*============================================================================*/
-
-/**
- * @cond LOCAL
- */
-
-EAPI Eina_Error EINA_ERROR_SAFETY_FAILED = 0;
-
-/**
- * @endcond
- */
-
/**
* @internal
* @brief Initialize the safety checks module.
Eina_Bool
eina_safety_checks_init(void)
{
+ if (!(initcnt++))
+ {
+ EINA_SAFETY_LOG_DOMAIN = eina_log_domain_register("eina_safety", EINA_COLOR_RED);
+ }
return EINA_TRUE;
}
-/**
- * @}
- */
+EAPI void
+_eina_safety_error(const char *file, const char *func, int line, const char *str)
+{
+ if (EINA_SAFETY_LOG_DOMAIN)
+ {
+ eina_log_print(EINA_SAFETY_LOG_DOMAIN, EINA_LOG_LEVEL_ERR,
+ file, func, line, "%s", str);
+ }
+ else
+ {
+ eina_log_print(EINA_LOG_DOMAIN_DEFAULT, EINA_LOG_LEVEL_ERR,
+ file, func, line, "%s", str);
+ }
+}
#include "eina_log.h"
+# ifdef EFL_BETA_API_SUPPORT
+/**
+ * Log entry-point called every time an eina safety check fails.
+ *
+ * One purpose of this dedicated function is to provide a convenient breakpoint
+ * for GDB debugging. Also, this gives it a dedicated log domain, rather than
+ * using the default one.
+ *
+ * @since 1.17
+ * @internal
+ */
+EAPI void _eina_safety_error(const char *file, const char *func, int line, const char *str);
+# define EINA_SAFETY_ERROR(msg) _eina_safety_error(__FILE__, __FUNCTION__, __LINE__, msg)
+# else
+# define EINA_SAFETY_ERROR(msg) EINA_LOG_ERR("%s", msg)
+# endif
+
#define EINA_SAFETY_ON_NULL_RETURN(exp) \
do \
{ \
if (EINA_UNLIKELY((exp) == NULL)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " == NULL"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " == NULL"); \
return; \
} \
} \
{ \
if (EINA_UNLIKELY((exp) == NULL)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " == NULL"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " == NULL"); \
return (val); \
} \
} \
{ \
if (EINA_UNLIKELY((exp) == NULL)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " == NULL"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " == NULL"); \
goto label; \
} \
} \
{ \
if (EINA_UNLIKELY(exp)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is true"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is true"); \
return; \
} \
} \
{ \
if (EINA_UNLIKELY(exp)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is true"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is true"); \
return val; \
} \
} \
{ \
if (EINA_UNLIKELY(exp)) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is true"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is true"); \
goto label; \
} \
} \
{ \
if (EINA_UNLIKELY(!(exp))) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is false"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is false"); \
return; \
} \
} \
{ \
if (EINA_UNLIKELY(!(exp))) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is false"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is false"); \
return val; \
} \
} \
{ \
if (EINA_UNLIKELY(!(exp))) \
{ \
- EINA_LOG_ERR("%s", "safety check failed: " # exp " is false"); \
+ EINA_SAFETY_ERROR("safety check failed: " # exp " is false"); \
goto label; \
} \
} \