From 0dd5e0eba6806c8d16c1b38ba4e878455698d7e2 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 09:31:12 +0900 Subject: restore arena_idx after reading irep --- src/load.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index af0e519bd..d3e492856 100644 --- a/src/load.c +++ b/src/load.c @@ -502,6 +502,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; + int ai = mrb->arena_idx; if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -539,6 +540,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) mrb->irep_len += nirep; error_exit: + mrb->arena_idx = ai; if (ret != MRB_DUMP_OK) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3 From 2d887c57ff809b20f1e094b584a58aa9eb071ac8 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 09:56:48 +0900 Subject: use API to restore arena_idx --- src/load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index d3e492856..6894ac1ef 100644 --- a/src/load.c +++ b/src/load.c @@ -502,7 +502,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; - int ai = mrb->arena_idx; + int ai = mrb_gc_arena_save(mrb); if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -540,7 +540,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) mrb->irep_len += nirep; error_exit: - mrb->arena_idx = ai; + mrb_gc_arena_restore(mrb, ai); if (ret != MRB_DUMP_OK) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3 From c87ec7c33beb47c04bc00981fabfca371691ad97 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 10:29:01 +0900 Subject: compact arena before raising exception; also reserve a few slots to allocate exception objects --- src/gc.c | 20 ++++++++++++++++---- src/load.c | 1 - 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src/load.c') 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) { -- cgit v1.2.3 From b20388c004c11b338ee2b6e41d3b3dd641842162 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 22:05:06 +0900 Subject: make arena_idx restoration per irep, not per load --- src/load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index f2aff8cbe..e73f09b3a 100644 --- a/src/load.c +++ b/src/load.c @@ -337,6 +337,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 mrb_int fix_num; mrb_float f; mrb_value str; + int ai = mrb_gc_arena_save(mrb); recordStart = src; buf = mrb_malloc(mrb, bufsize); @@ -489,6 +490,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 *len = src - recordStart; error_exit: + mrb_gc_arena_restore(mrb, ai); if (buf) mrb_free(mrb, buf); @@ -502,7 +504,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; - int ai = mrb_gc_arena_save(mrb); if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -539,7 +540,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) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3