Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make g++ happy. Hope it still has the same meaning though...
[simgrid.git] / include / xbt / ex.h
index 45225b2..cd66c73 100644 (file)
 #include <xbt/misc.h>
 #include <xbt/sysdep.h>
 
+/* 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) */
+extern int backtrace (void **__array, int __size);
+
 /* required ISO-C standard facilities */
 #include <errno.h>
 #include <stdio.h>
 
-//#define __EX_MCTX_MCSC__ 1
-#define __EX_MCTX_SSJLJ__ 1
 /* the machine context */
 #if defined(__EX_MCTX_MCSC__)
 #include <ucontext.h>            /* POSIX.1 ucontext(3) */
@@ -237,7 +239,7 @@ typedef struct {
 
 /* the static and dynamic initializers for a context structure */
 #define XBT_CTX_INITIALIZER \
-    { NULL, 0, { /* content */ NULL, 0, 0, \
+    { NULL, 0, { /* content */ NULL, unknown_error, 0, \
                  /* throw point*/ NULL, NULL, NULL, 0, NULL,\
                  /* backtrace */ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0 } }
 #define XBT_CTX_INITIALIZE(ctx) \
@@ -273,7 +275,7 @@ extern ex_ctx_t *__xbt_ex_ctx_default(void);
 /* the termination handler */
 typedef void (*ex_term_cb_t)(xbt_ex_t *);
 extern ex_term_cb_t __xbt_ex_terminate;
-extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__));
+extern void __xbt_ex_terminate_default(xbt_ex_t *e);
 
 /** @brief Introduce a block where exception may be dealed with 
  *  @hideinitializer
@@ -308,6 +310,12 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__
 /** @brief the block for catching (ie, deal with) an exception 
  *  @hideinitializer
  */
+#ifdef __cplusplus
+#  define XBT_EX_T_CPLUSPLUSCAST (xbt_ex_t&)
+#else
+#  define XBT_EX_T_CPLUSPLUSCAST 
+#endif
+
 #define CATCH(e) \
             else { \
             } \
@@ -322,7 +330,7 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__
         __xbt_ex_ctx_ptr->ctx_mctx = __ex_mctx_en; \
     } \
     if (   !(__xbt_ex_ctx()->ctx_caught) \
-        || ((e) = __xbt_ex_ctx()->ctx_ex, 0)) { \
+        || ((e) = XBT_EX_T_CPLUSPLUSCAST __xbt_ex_ctx()->ctx_ex, 0)) { \
     } \
     else
 
@@ -343,7 +351,7 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__
  * The THROW can be performed everywhere, including inside TRY, 
  * CLEANUP and CATCH blocks.
  */
-#include <execinfo.h>
+
 #define _THROW(c,v,m) \
   do { /* change this sequence into one block */                               \
      /* build the exception */ \
@@ -364,7 +372,7 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__
      abort();/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */ \
   } while (0)
 
-#define THROW0(c,v,m)                   _THROW(c,v,bprintf(m))
+#define THROW0(c,v,m)                   _THROW(c,v,(m?bprintf(m):NULL))
 #define THROW1(c,v,m,a1)                _THROW(c,v,bprintf(m,a1))
 #define THROW2(c,v,m,a1,a2)             _THROW(c,v,bprintf(m,a1,a2))
 #define THROW3(c,v,m,a1,a2,a3)          _THROW(c,v,bprintf(m,a1,a2,a3))
@@ -413,6 +421,8 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e)  __attribute__((__noreturn__
 void xbt_ex_free(xbt_ex_t e);
 const char * xbt_ex_catname(xbt_errcat_t cat);
 
+void xbt_ex_display(xbt_ex_t *e);
+
 /** @} */
 #endif /* __XBT_EX_H__ */