class.c: allocate ROM table wrappers per mrb_state

ROM method tables used static mrb_mt_tbl variables shared
across the process. The next pointer in each wrapper was
mutated by mrb_mt_init_rom(), causing cross-state
contamination when multiple mrb_state instances existed.

Allocate mrb_mt_tbl wrappers per-state via mrb_malloc().
The const mrb_mt_entry[] arrays remain static and shared.
Wrappers are tracked in mrb->rom_mt and freed at mrb_close().

Remove MRB_MT_ROM_TAB macro; add MRB_MT_INIT_ROM macro that
auto-computes size and calls the new mrb_mt_init_rom().

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-20 22:24:31 +09:00
parent 10f36a0cbb
commit 71cb3c2e3a
36 changed files with 142 additions and 146 deletions
+1 -2
View File
@@ -2274,14 +2274,13 @@ static const mrb_mt_entry string_ext_rom_entries[] = {
MRB_MT_ENTRY(str_rjust_core, MRB_SYM(rjust), MRB_ARGS_ARG(1,1)),
MRB_MT_ENTRY(str_center_core, MRB_SYM(center), MRB_ARGS_ARG(1,1)),
};
static mrb_mt_tbl string_ext_rom_mt = MRB_MT_ROM_TAB(string_ext_rom_entries);
void
mrb_mruby_string_ext_gem_init(mrb_state* mrb)
{
struct RClass *s = mrb->string_class;
mrb_mt_init_rom(s, &string_ext_rom_mt);
MRB_MT_INIT_ROM(mrb, s, string_ext_rom_entries);
mrb_define_method_id(mrb, mrb->integer_class, MRB_SYM(chr), int_chr, MRB_ARGS_NONE()|MRB_ARGS_OPT(1));
}