Fix gc issue

This commit is contained in:
2026-05-19 16:50:35 +01:00
parent 7bdb74e099
commit 1a337608f3
2 changed files with 10 additions and 6 deletions
+9 -2
View File
@@ -54,14 +54,21 @@ struct Block {
mrb_value proc;
Block(mrb_value proc) : proc(proc) {
mrb_gc_protect(mrb, proc);
mrb_gc_register(mrb, proc);
}
Block() : proc(mrb_nil_value()) {}
~Block() {
if (!mrb_nil_p(proc))
mrb_gc_unregister(mrb, proc);
}
void set_proc(mrb_value new_proc) {
if (!mrb_nil_p(proc))
mrb_gc_unregister(mrb, proc);
proc = new_proc;
mrb_gc_protect(mrb, proc);
mrb_gc_register(mrb, proc);
}
Block(const Block &) = delete;