mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
use pre-allocated RuntimeError for out-of-memory
This commit is contained in:
@@ -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
@@ -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 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user