diff options
| -rw-r--r-- | include/mruby.h | 1 | ||||
| -rw-r--r-- | src/gc.c | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/include/mruby.h b/include/mruby.h index e204820a3..5272d0400 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -125,6 +125,7 @@ typedef struct mrb_state { mrb_bool gc_disabled:1; mrb_bool gc_full:1; mrb_bool is_generational_gc_mode:1; + mrb_bool out_of_memory:1; size_t majorgc_old_threshold; struct alloca_header *mems; @@ -157,6 +157,20 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len) mrb_garbage_collect(mrb); p2 = (mrb->allocf)(mrb, p, len, mrb->ud); } + + if (!p2 && len) { + if (mrb->out_of_memory) { + /* mrb_panic(mrb); */ + } + else { + mrb->out_of_memory = 1; + mrb_raise(mrb, E_RUNTIME_ERROR, "Out of memory"); + } + } + else { + mrb->out_of_memory = 0; + } + return p2; } |
