use pre-allocated RuntimeError for out-of-memory

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-06-04 11:33:15 +09:00
parent b01bb33b75
commit d62ce565c6
3 changed files with 8 additions and 4 deletions
+1
View File
@@ -167,6 +167,7 @@ typedef struct mrb_state {
struct RClass *eException_class;
struct RClass *eStandardError_class;
struct RObject *nomem_err; /* pre-allocated NoMemoryError */
void *ud; /* auxiliary data */
} mrb_state;
+6 -3
View File
@@ -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 */
}
+1 -1
View File
@@ -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 {