OSSP CVS Repository

ossp - Check-in [1896]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1896
Date: 2002-Feb-25 11:30:15 (local)
2002-Feb-25 10:30:15 (UTC)
User:rse
Branch:
Comment: Allow ex_shield clauses to be dynamically nested. Without this the whole functionality would be useless in practice.
Tickets:
Inspections:
Files:
ossp-pkg/ex/ex.h      1.14 -> 1.15     13 inserted, 9 deleted
ossp-pkg/ex/ex.pod      1.19 -> 1.20     9 inserted, 0 deleted

ossp-pkg/ex/ex.h 1.14 -> 1.15

--- ex.h 2002/01/31 19:54:05     1.14
+++ ex.h 2002/02/25 10:30:15     1.15
@@ -94,7 +94,8 @@
 /* declare the context type (private) */
 typedef struct {
     __ex_mctx_t  *ctx_mctx;     /* permanent machine context of enclosing try/catch */
-    int           ctx_disabled; /* permanent flag whether exception handling is disabled */
+    int           ctx_shielding;/* permanent counter of exception shielding level */
+    int           ctx_shield;   /* temporary flag for exception shielding macro */
     int           ctx_caught;   /* temporary flag whether exception was caught */
     int           ctx_cleanup;  /* temporary flag whether cleanup block was present */
     volatile ex_t ctx_ex;       /* temporary exception storage */
@@ -102,11 +103,12 @@
 
 /* the static and dynamic initializers for a context structure */
 #define EX_CTX_INITIALIZER \
-    { NULL, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } }
+    { NULL, 0, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } }
 #define EX_CTX_INITIALIZE(ctx) \
     do { \
         (ctx)->ctx_mctx         = NULL; \
-        (ctx)->ctx_disabled     = 0;    \
+        (ctx)->ctx_shielding    = 0;    \
+        (ctx)->ctx_shield       = 0;    \
         (ctx)->ctx_caught       = 0;    \
         (ctx)->ctx_cleanup      = 0;    \
         (ctx)->ctx_ex.ex_class  = NULL; \
@@ -176,7 +178,7 @@
 
 /* the throwing of a new exception */
 #define ex_throw(c,o,v) \
-    (__ex_ctx()->ctx_disabled ? 0 : \
+    (__ex_ctx()->ctx_shielding > 0 ? 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), \
@@ -189,22 +191,24 @@
 
 /* the re-throwing of an already caught exception */
 #define ex_rethrow \
-    (__ex_ctx()->ctx_disabled ? 0 : \
+    (__ex_ctx()->ctx_shielding > 0 ? 0 : \
       (  __ex_ctx()->ctx_mctx == NULL \
        ? (__ex_terminate((ex_t *)&(__ex_ctx()->ctx_ex)), -1) \
        : (__ex_mctx_restore(__ex_ctx()->ctx_mctx), 1) ))
 
 /* shield an operation from exception handling */
 #define ex_shield \
-    for (__ex_ctx()->ctx_disabled = 1; \
-         __ex_ctx()->ctx_disabled == 1; \
-         __ex_ctx()->ctx_disabled = 0)
+    for (__ex_ctx()->ctx_shielding++, \
+         __ex_ctx()->ctx_shield =  1; \
+         __ex_ctx()->ctx_shield == 1; \
+         __ex_ctx()->ctx_shield =  0, \
+         __ex_ctx()->ctx_shielding--)
 
 /* exception handling tests */
 #define ex_catching \
     (__ex_ctx()->ctx_mctx != NULL)
 #define ex_shielding \
-    (__ex_ctx()->ctx_disabled)
+    (__ex_ctx()->ctx_shielding > 0)
 
 /* optional namespace mapping */
 #if defined(__EX_NS_UCCXX__)


ossp-pkg/ex/ex.pod 1.19 -> 1.20

--- ex.pod       2002/01/31 20:48:05     1.19
+++ ex.pod       2002/02/25 10:30:15     1.20
@@ -220,6 +220,15 @@
 of exceptions, i.e., inside the dynamic scope of B<ex_shield> all
 B<ex_throw> operations are silently ignored.
 
+The B<ex_shield> block is a regular B<ISO-C> language statement block,
+but it is not allowed to jump into it via C<goto> or C<longjmp>(3) or
+out of it via C<break>, C<return>, C<goto> or C<longjmp>(3) because this
+would cause the shielding level to become out of sync. Jumping into
+an B<ex_shield> clause would avoid increasing the exception shielding
+level, and jumping out of it would avoid decreasing it. In both cases
+the result is an incorrect exception shielding level. Nevertheless you
+are allowed to nest B<ex_shield> clauses.
+
 =item B<ex_catching>
 
 This is a boolean flag which can be checked inside the dynamic scope

CVSTrac 2.0.1