X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bd1afed305dfd477d90d107e060bfc3c22620110..1e18ccad74ce3d49299f1da9022c5d5e4ee76918:/include/xbt/ex.h diff --git a/include/xbt/ex.h b/include/xbt/ex.h index afa9c7ca86..e8594e7e8f 100644 --- a/include/xbt/ex.h +++ b/include/xbt/ex.h @@ -32,8 +32,8 @@ #ifndef __XBT_EX_H__ #define __XBT_EX_H__ -#include #include +#include /* do not include execinfo.h directly since it's not always available. Instead, copy the parts we need (and fake when it's not there) */ @@ -72,10 +72,6 @@ typedef struct { __ex_mctx_struct } __ex_mctx_t; /** @addtogroup XBT_ex * @brief A set of macros providing exception a la C++ in ANSI C (grounding feature) * - *
Top [\ref index]::[\ref XBT_API] - *
Prev [\ref XBT_syscall] - *
Next [\ref XBT_log]
- * * This module is a small ISO-C++ style exception handling library * for use in the ISO-C language. It allows you to use the paradigm * of throwing and catching exceptions in order to reduce the amount @@ -92,12 +88,16 @@ typedef struct { __ex_mctx_struct } __ex_mctx_t; * These features are brought to you by a modified version of the libex * library, one of the numerous masterpiece of Ralf S. Engelschall. * + * \htmlonly
\endhtmlonly + * * @section XBT_ex_toc TABLE OF CONTENTS * * - \ref XBT_ex_intro * - \ref XBT_ex_base * - \ref XBT_ex_pitfalls * + * \htmlonly
\endhtmlonly + * * @section XBT_ex_intro DESCRIPTION * * In SimGrid, an exception is a triple <\a msg , \a category , \a value> @@ -170,7 +170,7 @@ typedef struct { __ex_mctx_struct } __ex_mctx_t; * following code which shows some pitfalls and contains many errors (assuming * a mallocex() function which throws an exception if malloc(3) fails): * - * \dontinclude ex_test.c + * \dontinclude ex.c * \skip BAD_EXAMPLE * \until end_of_bad_example * @@ -211,6 +211,7 @@ typedef struct { __ex_mctx_struct } __ex_mctx_t; * @{ */ +/** @brief different kind of errors */ typedef enum { unknown_error=0, /**< unknown error */ arg_error, /**< Invalid argument */ @@ -237,7 +238,7 @@ typedef struct { int line; char *func; /**< to be freed only for remote exceptions */ /* Backtrace */ - void *bt[10]; + void *bt[XBT_BACKTRACE_SIZE]; int used; } xbt_ex_t; @@ -258,7 +259,7 @@ typedef struct { (ctx)->ctx_mctx = NULL; \ (ctx)->ctx_caught = 0; \ (ctx)->ctx_ex.msg = NULL; \ - (ctx)->ctx_ex.category = 0; \ + (ctx)->ctx_ex.category = unknown_error; \ (ctx)->ctx_ex.value = 0; \ (ctx)->ctx_ex.host = NULL; \ (ctx)->ctx_ex.procname = NULL; \ @@ -369,14 +370,14 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e); do { /* change this sequence into one block */ \ /* build the exception */ \ __xbt_ex_ctx()->ctx_ex.msg = (m); \ - __xbt_ex_ctx()->ctx_ex.category = (c); \ + __xbt_ex_ctx()->ctx_ex.category = (xbt_errcat_t)(c); \ __xbt_ex_ctx()->ctx_ex.value = (v); \ __xbt_ex_ctx()->ctx_ex.host = (char*)NULL; \ __xbt_ex_ctx()->ctx_ex.procname = strdup(xbt_procname()); \ __xbt_ex_ctx()->ctx_ex.file = (char*)__FILE__; \ __xbt_ex_ctx()->ctx_ex.line = __LINE__; \ __xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION; \ - __xbt_ex_ctx()->ctx_ex.used = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,10);\ + __xbt_ex_ctx()->ctx_ex.used = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,XBT_BACKTRACE_SIZE);\ /* deal with the exception */ \ if (__xbt_ex_ctx()->ctx_mctx == NULL) \ __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\ @@ -408,9 +409,14 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e); #define THROW6(c,v,m,a1,a2,a3,a4,a5,a6) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6)) #define THROW_IMPOSSIBLE THROW0(unknown_error,0,"The Impossible Did Happen (yet again)") -#define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible Did Happen (yet again)") #define THROW_UNIMPLEMENTED THROW1(unknown_error,0,"Function %s unimplemented",__FUNCTION__) +#ifndef NDEBUG +# define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible Did Happen (yet again)") +#else +# define DIE_IMPOSSIBLE exit(1); +#endif + /** @brief re-throwing of an already caught exception (ie, pass it to the upper catch block) * @hideinitializer */