Skip to content

Commit

Permalink
Refer to irep_capa as well as irep_len when irep is marked by GC.
Browse files Browse the repository at this point in the history
Initialize mrb->irep array with 0 when realloc is called.
  • Loading branch information
masamitsu-murase committed Aug 20, 2012
1 parent 72bc9c8 commit a851bcd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gc.c
Expand Up @@ -587,8 +587,10 @@ root_scan_phase(mrb_state *mrb)
mrb_gc_mark(mrb, (struct RBasic*)ci->target_class);
}
/* mark irep pool */
for (i=0; i<mrb->irep_len; i++) {
if (mrb->irep) {
if (mrb->irep) {
size_t len = mrb->irep_len;
if (len > mrb->irep_capa) len = mrb->irep_capa;
for (i=0; i<len; i++) {
mrb_irep *irep = mrb->irep[i];
if (!irep) continue;
for (j=0; j<irep->plen; j++) {
Expand Down
2 changes: 2 additions & 0 deletions src/state.c
Expand Up @@ -83,10 +83,12 @@ mrb_add_irep(mrb_state *mrb, int idx)
mrb->irep_capa = max;
}
else if (mrb->irep_capa <= idx) {
size_t old_capa = mrb->irep_capa;
while (mrb->irep_capa <= idx) {
mrb->irep_capa *= 2;
}
mrb->irep = (mrb_irep **)mrb_realloc(mrb, mrb->irep, sizeof(mrb_irep*)*mrb->irep_capa);
memset(mrb->irep + old_capa, 0, sizeof(mrb_irep*) * (mrb->irep_capa - old_capa));
}
}

Expand Down

0 comments on commit a851bcd

Please sign in to comment.