Commit f6b5a829 authored by take_cheeze's avatar take_cheeze Committed by Yukihiro "Matz" Matsumoto

Use class array instead of variadic.

parent cdd72d9c
......@@ -35,7 +35,8 @@ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t rescue, mrb_value r_data);
MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t rescue, mrb_value r_data, ...);
mrb_func_t rescue, mrb_value r_data,
mrb_int len, struct RClass **classes);
#if defined(__cplusplus)
} /* extern "C" { */
......
#include <stdarg.h>
#include "mruby.h"
#include "mruby/throw.h"
#include "mruby/error.h"
......@@ -52,18 +51,19 @@ MRB_API mrb_value
mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t rescue, mrb_value r_data)
{
return mrb_rescue_exceptions(mrb, body, b_data, rescue, r_data, mrb->eStandardError_class, NULL);
return mrb_rescue_exceptions(mrb, body, b_data, rescue, r_data, 1, &mrb->eStandardError_class);
}
MRB_API mrb_value
mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data, ...)
mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data,
mrb_int len, struct RClass **classes)
{
struct mrb_jmpbuf *prev_jmp = mrb->jmp;
struct mrb_jmpbuf c_jmp;
mrb_value result;
va_list excs;
struct RClass *cls;
mrb_bool error_matched = FALSE;
mrb_int i;
MRB_TRY(&c_jmp) {
mrb->jmp = &c_jmp;
......@@ -72,14 +72,12 @@ mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_fun
} MRB_CATCH(&c_jmp) {
mrb->jmp = prev_jmp;
va_start(excs, r_data);
while((cls = va_arg(excs, struct RClass*))) {
if (mrb_obj_is_kind_of(mrb, mrb_obj_value(mrb->exc), cls)) {
for (i = 0; i < len; ++i) {
if (mrb_obj_is_kind_of(mrb, mrb_obj_value(mrb->exc), classes[i])) {
error_matched = TRUE;
break;
}
}
va_end(excs);
if (!error_matched) { MRB_THROW(mrb->jmp); }
......
......@@ -40,8 +40,10 @@ static mrb_value
run_rescue_exceptions(mrb_state *mrb, mrb_value self)
{
mrb_value b, r;
struct RClass *cls[1];
mrb_get_args(mrb, "oo", &b, &r);
return mrb_rescue_exceptions(mrb, protect_cb, b, protect_cb, r, E_TYPE_ERROR, NULL);
cls[0] = E_TYPE_ERROR;
return mrb_rescue_exceptions(mrb, protect_cb, b, protect_cb, r, 1, cls);
}
void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment