Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created September 11, 2013 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/d3febe484052ce8976bf to your computer and use it in GitHub Desktop.
Save FROGGS/d3febe484052ce8976bf to your computer and use it in GitHub Desktop.
diff --git a/src/core/exceptions.c b/src/core/exceptions.c
index 7ff0fe1..b601f53 100644
--- a/src/core/exceptions.c
+++ b/src/core/exceptions.c
@@ -336,7 +336,24 @@ void MVM_exception_resume(MVMThreadContext *tc, MVMObject *ex_obj) {
else
MVM_exception_throw_adhoc(tc, "Can only resume an exception object");
- ah = (MVMActiveHandler *)ex->body.origin->special_return_data;
+ if (ex->body.origin->special_return == unwind_after_handler) {
+ /* A handler was already installed, just use it. */
+ ah = (MVMActiveHandler *)ex->body.origin->special_return_data;
+ }
+ else {
+ /* We need to allocate/register a handler and set some defaults. */
+ ah = malloc(sizeof(MVMActiveHandler));
+
+ /* Install active handler record. */
+ ah->ex_obj = ex_obj;
+ ah->next_handler = tc->active_handlers;
+ tc->active_handlers = ah;
+
+ tc->cur_frame->return_value = NULL;
+ tc->cur_frame->return_type = MVM_RETURN_VOID;
+ ex->body.origin->special_return_data = (void *)ah;
+ }
+
ah->frame = (void *)MVM_frame_inc_ref(tc, ex->body.origin);
ah->handler->goto_offset = ex->body.goto_offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment