Author: tene
Date: Wed Dec 10 21:14:08 2008
New Revision: 33792
Modified:
trunk/src/pmc/exceptionhandler.pmc
Log:
[ExceptionHandler]: Add handle_types_except()
Modified: trunk/src/pmc/exceptionhandler.pmc
==============================================================================
--- trunk/src/pmc/exceptionhandler.pmc (original)
+++ trunk/src/pmc/exceptionhandler.pmc Wed Dec 10 21:14:08 2008
@@ -26,6 +26,7 @@
pmclass ExceptionHandler extends Continuation need_ext {
ATTR PMC *handled_types;
+ ATTR PMC *handled_types_except;
ATTR INTVAL min_severity;
ATTR INTVAL max_severity;
@@ -51,6 +52,7 @@
core_struct->min_severity = 0;
core_struct->max_severity = 0;
core_struct->handled_types = PMCNULL;
+ core_struct->handled_types_except = PMCNULL;
/* an exception handler has no separate context; it's only a snapshot
* of an "earlier" context, which is contained in the interpreter's
@@ -74,6 +76,8 @@
PARROT_EXCEPTIONHANDLER(SELF);
if (core_struct->handled_types)
pobject_lives(interp, (PObj *)core_struct->handled_types);
+ if (core_struct->handled_types_except)
+ pobject_lives(interp, (PObj *)core_struct->handled_types_except);
}
/*
@@ -198,11 +202,11 @@
if (severity < core_struct->min_severity) {
RETURN(INTVAL 0);
}
- else if (core_struct->max_severity > 0
+ if (core_struct->max_severity > 0
&& severity > core_struct->max_severity) {
RETURN(INTVAL 0);
}
- else if (core_struct->handled_types != PMCNULL) {
+ if (core_struct->handled_types != PMCNULL) {
INTVAL elems = VTABLE_elements(interp,
core_struct->handled_types);
INTVAL type = VTABLE_get_integer_keyed_str(interp, exception,
CONST_STRING(interp, "type"));
INTVAL i;
@@ -216,6 +220,20 @@
RETURN(INTVAL 0);
}
+ if (core_struct->handled_types_except != PMCNULL) {
+ INTVAL elems = VTABLE_elements(interp,
core_struct->handled_types_except);
+ INTVAL type = VTABLE_get_integer_keyed_str(interp, exception,
CONST_STRING(interp, "type"));
+ INTVAL i;
+
+ for (i = 0; i < elems; i++) {
+ INTVAL handled_type = VTABLE_get_integer_keyed_int(interp,
+ core_struct->handled_types_except, i);
+ if (handled_type == type)
+ RETURN(INTVAL 0);
+ }
+
+ RETURN(INTVAL 1);
+ }
else if (core_struct->max_severity > 0 ||
core_struct->min_severity > 0) {
RETURN(INTVAL 1);
@@ -290,6 +308,25 @@
: PMCNULL;
}
+/*
+
+=item C<METHOD handle_types_except(PMC *types :slurpy)>
+
+Set the exception types that the ExceptionHandler will not handle.
+
+=cut
+
+*/
+
+ METHOD handle_types_except(PMC *types :slurpy) {
+ Parrot_ExceptionHandler_attributes * const core_struct =
+ PARROT_EXCEPTIONHANDLER(SELF);
+ core_struct->handled_types_except =
+ VTABLE_elements(interp, types) > 0
+ ? types
+ : PMCNULL;
+ }
+
}
/*