OSSP CVS Repository

ossp - Difference in ossp-pkg/ex/ex.h versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/ex/ex.h 1.1 -> 1.2

--- ex.h 2002/01/25 15:25:51     1.1
+++ ex.h 2002/01/25 18:31:07     1.2
@@ -23,8 +23,8 @@
 **  ex.h: exception handling (pre-processor part)
 */
 
-#ifndef __TEXAS_H__
-#define __TEXAS_H__
+#ifndef __EX_H__
+#define __EX_H__
 
 /* the required ISO-C standard facilities */
 #include <stdio.h>   /* for NULL */
@@ -34,16 +34,31 @@
 #if (   defined(__STDC__) \
      && defined(__STDC_VERSION__) \
      && __STDC_VERSION__ >= 199901L)
-#define __TEXAS_FUNC__ __func__      /* ISO C99 compliant */
+#define __EX_FUNC__ __func__      /* ISO C99 compliant */
 #elif (   defined(__GNUC__) \
        && defined(__GNUC_MINOR__) \
        && (   __GNUC__ > 2 \
            || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))
-#define __TEXAS_FUNC__ __FUNCTION__  /* gcc >= 2.8 */
+#define __EX_FUNC__ __FUNCTION__  /* gcc >= 2.8 */
 #else
-#define __TEXAS_FUNC__ "#NA#"        /* not available */
+#define __EX_FUNC__ "#NA#"        /* not available */
 #endif
 
+/* the machine context */
+#ifndef __ex_mctx_st
+#define __ex_mctx_st             struct { jmp_buf jb; }
+#endif
+#ifndef __ex_mctx_save
+#define __ex_mctx_save(mctx)     setjmp((mctx)->jb)
+#endif
+#ifndef __ex_mctx_restore
+#define __ex_mctx_restore(mctx)  (void)longjmp((mctx)->jb, 1)
+#endif
+#ifndef __ex_mctx_restored
+#define __ex_mctx_restored(mctx) /* NOOP */
+#endif
+typedef __ex_mctx_st __ex_mctx_t;
+
 /* declare the exception type (public) */
 typedef struct {
     /* throw value */
@@ -58,7 +73,7 @@
 
 /* declare the exception context type (private) */
 typedef struct {
-    jmp_buf      *ctx_jbprev; /* previous jump buffer */
+    __ex_mctx_t  *ctx_mctx_prev; /* previous jump buffer */
     int           ctx_caught; /* flag whether exception was caught */
     volatile ex_t ctx_ex;     /* the exception temporary storage */
 } ex_ctx_t;
@@ -72,11 +87,11 @@
 /* block for trying execution */
 #define ex_try \
     { \
-        jmp_buf *__ex_jbprev; \
-        jmp_buf __ex_jbme; \
-        __ex_jbprev = __ex_ctx->ctx_jbprev; \
-        __ex_ctx->ctx_jbprev = &__ex_jbme; \
-        if (setjmp(__ex_jbme) == 0) { \
+        __ex_mctx_t *__ex_mctx_prev; \
+        __ex_mctx_t __ex_mctx_me; \
+        __ex_mctx_prev = __ex_ctx->ctx_mctx_prev; \
+        __ex_ctx->ctx_mctx_prev = &__ex_mctx_me; \
+        if (__ex_mctx_save(&__ex_mctx_me) == 0) { \
             if (1)
 
 /* block for catching an exception */
@@ -86,9 +101,10 @@
             __ex_ctx->ctx_caught = 0; \
         } \
         else { \
+            __ex_mctx_restored(&__ex_mctx_me); \
             __ex_ctx->ctx_caught = 1; \
         } \
-        __ex_ctx->ctx_jbprev = __ex_jbprev; \
+        __ex_ctx->ctx_mctx_prev = __ex_mctx_prev; \
     } \
     if (!__ex_ctx->ctx_caught || ((e) = __ex_ctx->ctx_ex, 0)) { \
     } \
@@ -96,39 +112,39 @@
 
 /* throw a new exception */
 #define ex_throw(c,o,v) \
-    (__ex_ctx->ctx_jbprev == NULL ? \
+    (__ex_ctx->ctx_mctx_prev == NULL ? \
      (abort(), 0) : \
      ( __ex_ctx->ctx_ex.ex_class  = (void *)(c), \
        __ex_ctx->ctx_ex.ex_object = (void *)(o), \
        __ex_ctx->ctx_ex.ex_value  = (void *)(v), \
        __ex_ctx->ctx_ex.ex_file   = __FILE__, \
        __ex_ctx->ctx_ex.ex_line   = __LINE__, \
-       __ex_ctx->ctx_ex.ex_func   = __TEXAS_FUNC__, \
-       longjmp(*(__ex_ctx->ctx_jbprev), 1), \
+       __ex_ctx->ctx_ex.ex_func   = __EX_FUNC__, \
+       __ex_mctx_restore(__ex_ctx->ctx_mctx_prev), \
        0 \
      ) \
     )
 
 /* re-throw a caught exception */
 #define ex_rethrow \
-    (__ex_ctx->ctx_jbprev == NULL ? \
+    (__ex_ctx->ctx_mctx_prev == NULL ? \
      (abort(), 0) : \
-     (longjmp(*(__ex_ctx->ctx_jbprev), 1), 0) \
+     (__ex_mctx_restore(__ex_ctx->ctx_mctx_prev), 0) \
     )
 
 /* optional namespace mapping */
-#if !defined(__cplusplus) && !defined(__TEXAS_NO_CXX_NS__)
+#if !defined(__cplusplus) && !defined(__EX_NO_CXX_NS__)
 #define try      ex_try
 #define catch    ex_catch
 #define throw    ex_throw
 #define rethrow  ex_rethrow
 #endif
-#if !defined(__TEXAS_NO_SIMPLE_NS__)
+#if !defined(__EX_NO_SIMPLE_NS__)
 #define Try      ex_try
 #define Catch    ex_catch
 #define Throw    ex_throw
 #define Rethrow  ex_rethrow
 #endif
 
-#endif /* __TEXAS_H__ */
+#endif /* __EX_H__ */
 

CVSTrac 2.0.1