mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
garbage collect context (fiber) properly
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user