Debug.h
/*
* $Id: Debug.h 3444 2012-11-05 14:29:38Z karijes $
*
* Debug functions
* Copyright (c) 2005-2011 edelib authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_DEBUG_H__
#define __EDELIB_DEBUG_H__
#include "edelib-global.h"
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SKIP_DOCS
EDELIB_API void edelib_logv(const char *domain, int type, const char *fmt, va_list args);
EDELIB_API void edelib_log(const char *domain, int type, const char *fmt, ...);
#endif
typedef enum {
EDELIB_ERROR_MESSAGE_DEBUG,
EDELIB_ERROR_MESSAGE_WARNING,
EDELIB_ERROR_MESSAGE_FATAL
} EdelibErrorMessageType;
EDELIB_API void edelib_error_message_handler_install(void (*)(int t, const char* domain, const char* msg));
#ifndef E_LOG_DOMAIN
#define E_LOG_DOMAIN ((char*)0)
#endif
#ifdef __GNUC__
#define _E_FUNCTION_NAME __PRETTY_FUNCTION__
#else
#define _E_FUNCTION_NAME "<unknown>"
#endif
#ifdef EDELIB_HAVE_ISO_VARARGS
#define E_DEBUG(...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_DEBUG, __VA_ARGS__)
#define E_WARNING(...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_WARNING, __VA_ARGS__)
#define E_FATAL(...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_FATAL, __VA_ARGS__)
#elif defined(EDELIB_HAVE_GNUC_VARARGS)
#define E_DEBUG(format...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_DEBUG, format)
#define E_WARNING(format...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_WARNING, format)
#define E_FATAL(format...) edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_FATAL, format)
#else
void E_DEBUG(const char *fmt, ...);
void E_WARNING(const char *fmt, ...);
void E_FATAL(const char *fmt, ...);
#endif
#ifdef NDEBUG
#define E_ASSERT(expr)
#else
#define E_ASSERT(expr) \
do { \
if(!(expr)) \
edelib_log(E_LOG_DOMAIN, EDELIB_ERROR_MESSAGE_FATAL, "Assertion failed: \"%s\" in %s (%d), function: \"%s\"\n", \
#expr, __FILE__, __LINE__, _E_FUNCTION_NAME); \
} while(0);
#endif
#define _E_STRLOC_STRINGIFY(arg) _E_STRLOC_STRINGIFY_ARG(arg)
#define _E_STRLOC_STRINGIFY_ARG(content) #content
#define E_STRLOC __FILE__ ":" _E_STRLOC_STRINGIFY(__LINE__)
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _E_BOOLEAN_EXPR(expr) \
__extension__ ({ \
int _edelib_boolean_var_; \
if(expr) \
_edelib_boolean_var_ = 1; \
else \
_edelib_boolean_var_ = 0; \
_edelib_boolean_var_; \
})
#define E_LIKELY(expr) (__builtin_expect(_E_BOOLEAN_EXPR(expr), 1))
#define E_UNLIKELY(expr) (__builtin_expect(_E_BOOLEAN_EXPR(expr), 0))
#else
#define E_LIKELY(expr) (expr)
#define E_UNLIKELY(expr) (expr)
#endif
#define E_RETURN_IF_FAIL(expr) \
do { \
if E_LIKELY(expr) { } \
else { \
E_WARNING(E_STRLOC ": Condition '%s' failed\n", #expr); \
return; \
} \
} while(0)
#define E_RETURN_VAL_IF_FAIL(expr, val) \
do { \
if E_LIKELY(expr) { } \
else { \
E_WARNING(E_STRLOC ": Condition '%s' failed\n", #expr); \
return (val); \
} \
} while(0)
/* compatibility with the old code */
#define EDEBUG E_DEBUG
#define EWARNING E_WARNING
#define EFATAL E_FATAL
#define EASSERT E_ASSERT
#define ESTRLOC E_STRLOC
#ifdef __cplusplus
}
#endif
#endif
E_FATAL
#define E_FATAL(...)
Definition: Debug.h:96
E_DEBUG
#define E_DEBUG(...)
Definition: Debug.h:94
E_WARNING
#define E_WARNING(...)
Definition: Debug.h:95