diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-05-29 10:29:01 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-05-29 10:29:01 +0900 |
| commit | c87ec7c33beb47c04bc00981fabfca371691ad97 (patch) | |
| tree | c105bb526e1a8ef7a2ad259b68d9dc0db6b8552d /src/gc.c | |
| parent | 2d887c57ff809b20f1e094b584a58aa9eb071ac8 (diff) | |
| download | mruby-c87ec7c33beb47c04bc00981fabfca371691ad97.tar.gz mruby-c87ec7c33beb47c04bc00981fabfca371691ad97.zip | |
compact arena before raising exception; also reserve a few slots to allocate exception objects
Diffstat (limited to 'src/gc.c')
| -rw-r--r-- | src/gc.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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); |
