Skip to content

Commit

Permalink
define named values for magic numbers used in exception handling long…
Browse files Browse the repository at this point in the history
… jumps
  • Loading branch information
NotFound committed Apr 28, 2012
1 parent b71c965 commit 4dcb543
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 6 additions & 1 deletion include/parrot/interpreter.h
@@ -1,5 +1,5 @@
/* interpreter.h
* Copyright (C) 2001-2010, Parrot Foundation.
* Copyright (C) 2001-2012, Parrot Foundation.
* Overview:
* The interpreter API handles running the operations
*/
Expand Down Expand Up @@ -90,6 +90,11 @@ typedef enum {
} Parrot_clone_flags;
/* &end_gen */

/* Codes used by long jumps to runloop */
#define PARROT_JMP_EXCEPTION_HANDLED 1
#define PARROT_JMP_EXCEPTION_FROM_C 2
#define PARROT_JMP_EXCEPTION_FINALIZED 3

struct parrot_interp_t;

/* One of the most common shim arguments is the interpreter itself, so it
Expand Down
6 changes: 3 additions & 3 deletions src/call/ops.c
Expand Up @@ -91,7 +91,7 @@ runops(PARROT_INTERP, size_t offs)
reenter:
interp->current_runloop->handler_start = NULL;
switch (setjmp(interp->current_runloop->resume)) {
case 1:
case PARROT_JMP_EXCEPTION_HANDLED:
/* an exception was handled */
if (STACKED_EXCEPTIONS)
free_runloop_jump_point(interp);
Expand All @@ -104,15 +104,15 @@ runops(PARROT_INTERP, size_t offs)
interp->current_runloop_id, interp->current_runloop_level);
#endif
return;
case 2:
case PARROT_JMP_EXCEPTION_FROM_C:
/* Reenter the runloop from a exception thrown from C
* with a pir handler */
free_runloops_until(interp, our_runloop_id);
PARROT_ASSERT(interp->current_runloop->handler_start);
offset = interp->current_runloop->handler_start - interp->code->base.data;
/* Prevent incorrect reuse */
goto reenter;
case 3:
case PARROT_JMP_EXCEPTION_FINALIZED:
/* Reenter the runloop when finished the handling of a
* exception */
free_runloops_until(interp, our_runloop_id);
Expand Down
8 changes: 4 additions & 4 deletions src/exceptions.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2010, Parrot Foundation.
Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -236,7 +236,7 @@ Parrot_ex_throw_from_op(PARROT_INTERP, ARGIN(PMC *exception), ARGIN_NULLOK(void
/* it's a C exception handler */
Parrot_runloop * const jump_point = (Parrot_runloop *)address;
jump_point->exception = exception;
longjmp(jump_point->resume, 1);
longjmp(jump_point->resume, PARROT_JMP_EXCEPTION_HANDLED);
}

/* return the address of the handler */
Expand Down Expand Up @@ -360,7 +360,7 @@ Parrot_ex_throw_from_c(PARROT_INTERP, ARGIN(PMC *exception))
Parrot_runloop * const jump_point =
(Parrot_runloop *)VTABLE_get_pointer(interp, handler);
jump_point->exception = exception;
longjmp(jump_point->resume, 1);
longjmp(jump_point->resume, PARROT_JMP_EXCEPTION_HANDLED);
}
else {
/* Run the handler. */
Expand All @@ -369,7 +369,7 @@ Parrot_ex_throw_from_c(PARROT_INTERP, ARGIN(PMC *exception))
setup_exception_args(interp, "P", exception);
PARROT_ASSERT(return_point->handler_start == NULL);
return_point->handler_start = address;
longjmp(return_point->resume, 2);
longjmp(return_point->resume, PARROT_JMP_EXCEPTION_FROM_C);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ops/core.ops
Expand Up @@ -896,7 +896,7 @@ op finalize(in PMC) {
if (rl) {
if (rl != interp->current_runloop) {
rl->handler_start = dest;
longjmp(rl->resume, 3);
longjmp(rl->resume, PARROT_JMP_EXCEPTION_FINALIZED);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/ops/core_ops.c
Expand Up @@ -14171,7 +14171,7 @@ Parrot_finalize_p(opcode_t *cur_opcode, PARROT_INTERP) {
if (rl) {
if ((rl != interp->current_runloop)) {
rl->handler_start = dest;
longjmp(rl->resume, 3);
longjmp(rl->resume, PARROT_JMP_EXCEPTION_FINALIZED);
}

}
Expand Down Expand Up @@ -14226,7 +14226,7 @@ Parrot_finalize_pc(opcode_t *cur_opcode, PARROT_INTERP) {
if (rl) {
if ((rl != interp->current_runloop)) {
rl->handler_start = dest;
longjmp(rl->resume, 3);
longjmp(rl->resume, PARROT_JMP_EXCEPTION_FINALIZED);
}

}
Expand Down

0 comments on commit 4dcb543

Please sign in to comment.