From d62ce565c66a427a0f01cf7301ff59362a460aba Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 4 Jun 2014 11:33:15 +0900 Subject: use pre-allocated RuntimeError for out-of-memory --- src/error.c | 9 ++++++--- src/gc.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/error.c b/src/error.c index c60fff10d..a100da67d 100644 --- a/src/error.c +++ b/src/error.c @@ -227,7 +227,9 @@ mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc) { mrb->exc = mrb_obj_ptr(exc); - exc_debug_info(mrb, mrb->exc); + if (!mrb->out_of_memory) { + exc_debug_info(mrb, mrb->exc); + } if (!mrb->jmp) { mrb_p(mrb, exc); abort(); @@ -459,7 +461,7 @@ mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_int argc, const mrb_value *a void mrb_init_exception(mrb_state *mrb) { - struct RClass *exception, *script_error; + struct RClass *exception, *runtime_error, *script_error; mrb->eException_class = exception = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */ mrb_define_class_method(mrb, exception, "exception", mrb_instance_new, MRB_ARGS_ANY()); @@ -472,7 +474,8 @@ mrb_init_exception(mrb_state *mrb) mrb_define_method(mrb, exception, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE()); mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ - mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ + runtime_error = mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ + mrb->nomem_err = mrb_obj_ptr(mrb_exc_new_str(mrb, runtime_error, mrb_str_new_lit(mrb, "Out of memory"))); script_error = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ mrb_define_class(mrb, "SyntaxError", script_error); /* 15.2.38 */ } diff --git a/src/gc.c b/src/gc.c index 171f0858d..a04dc527c 100644 --- a/src/gc.c +++ b/src/gc.c @@ -189,7 +189,7 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len) } else { mrb->out_of_memory = TRUE; - mrb_raise(mrb, E_RUNTIME_ERROR, "Out of memory"); + mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err)); } } else { -- cgit v1.2.3