diff --git a/include/mruby/internal.h b/include/mruby/internal.h index 11b15d057..a2948961a 100644 --- a/include/mruby/internal.h +++ b/include/mruby/internal.h @@ -70,7 +70,7 @@ struct RBacktrace { struct mrb_backtrace_location { mrb_sym method_id; int32_t idx; - const struct RProc *proc; + const mrb_irep *irep; }; /* gc */ diff --git a/src/backtrace.c b/src/backtrace.c index ebdfb6f29..f4ec6999a 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -33,22 +33,22 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void * if (!ci->proc || MRB_PROC_CFUNC_P(ci->proc)) { if (!ci->mid) continue; - loc.proc = NULL; + loc.irep = NULL; } else { - loc.proc = ci->proc; - if (!loc.proc->body.irep) continue; - if (!loc.proc->body.irep->debug_info) continue; + loc.irep = ci->proc->body.irep; + if (!loc.irep) continue; + if (!loc.irep->debug_info) continue; if (mrb->c->cibase[i].pc) { pc = &mrb->c->cibase[i].pc[-1]; } else { continue; } - loc.idx = (uint32_t)(pc - loc.proc->body.irep->iseq); + loc.idx = (uint32_t)(pc - loc.irep->iseq); } loc.method_id = ci->mid; - if (loc.proc == NULL) { + if (loc.irep == NULL) { for (ptrdiff_t j=i-1; j >= 0; j--) { ci = &mrb->c->cibase[j]; @@ -66,7 +66,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void * continue; } - loc.proc = ci->proc; + loc.irep = irep; loc.idx = (uint32_t)(pc - irep->iseq); break; } @@ -85,6 +85,9 @@ pack_backtrace_i(mrb_state *mrb, struct mrb_backtrace_location **pptr = (struct mrb_backtrace_location**)data; struct mrb_backtrace_location *ptr = *pptr; + if (loc->irep) { + mrb_irep_incref(mrb, (mrb_irep*)loc->irep); + } *ptr = *loc; *pptr = ptr+1; } @@ -161,7 +164,7 @@ mrb_unpack_backtrace(mrb_state *mrb, struct RObject *backtrace) int32_t lineno; const char *filename; - if (!entry->proc || !mrb_debug_get_position(mrb, entry->proc->body.irep, entry->idx, &lineno, &filename)) { + if (!entry->irep || !mrb_debug_get_position(mrb, entry->irep, entry->idx, &lineno, &filename)) { btline = mrb_str_new_lit(mrb, "(unknown):0"); } else if (lineno != -1) {//debug info was available diff --git a/src/gc.c b/src/gc.c index 685f2b055..63d3f1678 100644 --- a/src/gc.c +++ b/src/gc.c @@ -688,15 +688,6 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) mrb_gc_mark(mrb, (struct RBasic*)((struct RException*)obj)->backtrace); break; - case MRB_TT_BACKTRACE: - { - struct RBacktrace *bt = (struct RBacktrace*)obj; - for (size_t i = 0; i < bt->len; i++) { - mrb_gc_mark(mrb, (struct RBasic*)bt->locations[i].proc); - } - } - break; - default: break; } @@ -835,6 +826,9 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end) case MRB_TT_BACKTRACE: { struct RBacktrace *bt = (struct RBacktrace*)obj; + for (size_t i = 0; i < bt->len; i++) { + mrb_irep_decref(mrb, (mrb_irep*)bt->locations[i].irep); + } mrb_free(mrb, bt->locations); }