garbage collect context (fiber) properly

parent 1cfd3fb9
......@@ -74,6 +74,8 @@ struct mrb_context {
int rsize;
struct RProc **ensure;
int esize;
struct RFiber *fib;
};
enum gc_state {
......
......@@ -80,9 +80,9 @@ fiber_init(mrb_state *mrb, mrb_value self)
f->cxt = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context));
*f->cxt = mrb_context_zero;
c = f->cxt;
/* initialize VM stack */
c = f->cxt;
c->stbase = (mrb_value *)mrb_calloc(mrb, FIBER_STACK_INIT_SIZE, sizeof(mrb_value));
c->stend = c->stbase + FIBER_STACK_INIT_SIZE;
c->stack = c->stbase;
......@@ -104,6 +104,8 @@ fiber_init(mrb_state *mrb, mrb_value self)
ci[1] = ci[0];
c->ci++; /* push dummy callinfo */
c->fib = f;
return self;
}
......
......@@ -412,7 +412,9 @@ mark_context(mrb_state *mrb, struct mrb_context *c)
mrb_gc_mark(mrb, (struct RBasic*)ci->proc);
mrb_gc_mark(mrb, (struct RBasic*)ci->target_class);
}
if (c->prev) mark_context(mrb, c->prev);
if (c->prev && c->prev->fib) {
mrb_gc_mark(mrb, (struct RBasic*)c->prev->fib);
}
}
static void
......@@ -472,7 +474,6 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
struct mrb_context *c = ((struct RFiber*)obj)->cxt;
mark_context(mrb, c);
((struct RFiber*)obj)->cxt = NULL;
}
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment