trynna fix click handler being garbage collected

This commit is contained in:
2026-05-19 13:33:02 +01:00
parent a692bfb2b3
commit 7bdb74e099
5 changed files with 38 additions and 12 deletions
+1 -10
View File
@@ -60,11 +60,8 @@ struct Block {
Block() : proc(mrb_nil_value()) {}
void set_proc(mrb_value new_proc) {
if (!mrb_nil_p(proc))
mrb_gc_unregister(mrb, proc);
proc = new_proc;
if (!mrb_nil_p(proc))
mrb_gc_protect(mrb, proc);
mrb_gc_protect(mrb, proc);
}
Block(const Block &) = delete;
@@ -76,16 +73,10 @@ struct Block {
mrb_value result = mrb_funcall_argv(mrb, proc, mrb_intern_cstr(mrb, "call"), argc, argv);
return result;
}
~Block() {
mrb_gc_unregister(mrb, proc);
}
};
inline void run_string(const char *code, size_t length) {
int ai = mrb_gc_arena_save(mrb);
mrb_load_nstring(mrb, code, length);
mrb_gc_arena_restore(mrb, ai);
}
}; // namespace Ruby