mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+1
-2
@@ -3559,7 +3559,6 @@ static const mrb_mt_entry string_rom_entries[] = {
|
||||
MRB_MT_ENTRY(mrb_str_to_f, MRB_SYM(to_f), MRB_ARGS_NONE()), /* 15.2.10.5.38 */
|
||||
#endif
|
||||
};
|
||||
static mrb_mt_tbl string_rom_mt = MRB_MT_ROM_TAB(string_rom_entries);
|
||||
|
||||
void
|
||||
mrb_init_string(mrb_state *mrb)
|
||||
@@ -3572,7 +3571,7 @@ mrb_init_string(mrb_state *mrb)
|
||||
mrb->string_class = s = mrb_define_class_id(mrb, MRB_SYM(String), mrb->object_class); /* 15.2.10 */
|
||||
MRB_SET_INSTANCE_TT(s, MRB_TT_STRING);
|
||||
|
||||
mrb_mt_init_rom(s, &string_rom_mt);
|
||||
MRB_MT_INIT_ROM(mrb, s, string_rom_entries);
|
||||
|
||||
mrb_define_method_id(mrb, mrb->kernel_module, MRB_SYM(__ENCODING__), mrb_encoding, MRB_ARGS_NONE());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user