summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-29 10:29:01 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-29 10:29:01 +0900
commitc87ec7c33beb47c04bc00981fabfca371691ad97 (patch)
treec105bb526e1a8ef7a2ad259b68d9dc0db6b8552d
parent2d887c57ff809b20f1e094b584a58aa9eb071ac8 (diff)
downloadmruby-c87ec7c33beb47c04bc00981fabfca371691ad97.tar.gz
mruby-c87ec7c33beb47c04bc00981fabfca371691ad97.zip
compact arena before raising exception; also reserve a few slots to allocate exception objects
-rw-r--r--src/gc.c20
-rw-r--r--src/load.c1
2 files changed, 16 insertions, 5 deletions
diff --git a/src/gc.c b/src/gc.c
index 1d7a8627f..46bce642d 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -261,12 +261,24 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
}
mrb->live++;
+ if (mrb->arena_idx > MRB_ARENA_SIZE - 4) {
+ struct RBasic **p, **q, **e;
+
+ p = q = mrb->arena;
+ e = p + mrb->arena_idx;
+ while (p < e) {
+ if (is_white(*p))
+ *q++ = *p;
+ p++;
+ }
+ if (p == q) {
+ /* arena overflow error */
+ mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error");
+ }
+ mrb->arena_idx = q - mrb->arena;
+ }
mrb->arena[mrb->arena_idx++] = p;
memset(p, 0, sizeof(RVALUE));
- if (mrb->arena_idx >= MRB_ARENA_SIZE) {
- /* arena overflow error */
- mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error");
- }
p->tt = ttype;
p->c = cls;
paint_partial_white(mrb, p);
diff --git a/src/load.c b/src/load.c
index 6894ac1ef..f2aff8cbe 100644
--- a/src/load.c
+++ b/src/load.c
@@ -538,7 +538,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
}
mrb->irep_len += nirep;
-
error_exit:
mrb_gc_arena_restore(mrb, ai);
if (ret != MRB_DUMP_OK) {