[svn:parrot] r36463 - trunk/src

NotFound at svn.parrot.org NotFound at svn.parrot.org
Sun Feb 8 19:23:50 UTC 2009


Author: NotFound
Date: Sun Feb  8 19:23:49 2009
New Revision: 36463
URL: https://trac.parrot.org/parrot/changeset/36463

Log:
[core] less drastic way of handling recursive throwing

Modified:
   trunk/src/scheduler.c

Modified: trunk/src/scheduler.c
==============================================================================
--- trunk/src/scheduler.c	Sun Feb  8 19:22:27 2009	(r36462)
+++ trunk/src/scheduler.c	Sun Feb  8 19:23:49 2009	(r36463)
@@ -837,18 +837,35 @@
 
     /*
      * Quick&dirty way to avoid infinite recursion
-     * when an exception is thown while looking
+     * when an exception is thrown while looking
      * for a handler
      */
     static int already_doing = 0;
+    static Parrot_Context * keep_context = NULL;
 
     Parrot_Context *context;
     PMC            *iter        = PMCNULL;
     STRING * const  handled_str = CONST_STRING(interp, "handled");
     STRING * const  iter_str    = CONST_STRING(interp, "handler_iter");
 
-    if (already_doing)
-        return NULL;
+    if (already_doing) {
+        Parrot_io_eprintf(interp,
+            "** Exception catched while looking for a handler, trying next **\n");
+        if (! keep_context)
+            return NULL;
+        /*
+         * Note that we are now trying to handle the new exception,
+         * not the initial task argument (exception or whatever).
+         */
+        context = keep_context->caller_ctx;
+        keep_context = NULL;
+        if (context && !PMC_IS_NULL(context->handlers))
+            iter = VTABLE_get_iter(interp, context->handlers);
+        else
+            iter = PMCNULL;
+    }
+    else {
+
     ++already_doing;
 
     /* Exceptions store the handler iterator for rethrow, other kinds of
@@ -864,7 +881,10 @@
             iter = VTABLE_get_iter(interp, context->handlers);
     }
 
+    }
+
     while (context) {
+        keep_context = context;
         /* Loop from newest handler to oldest handler. */
         while (!PMC_IS_NULL(iter) && VTABLE_get_bool(interp, iter)) {
             PMC *handler = VTABLE_shift_pmc(interp, iter);
@@ -881,6 +901,7 @@
                         VTABLE_set_pointer(interp, task, context);
                     }
                     --already_doing;
+                    keep_context = NULL;
                     return handler;
                 }
             }


More information about the parrot-commits mailing list