From bd0f111397588871ac6924f86fd47b1cf6c23735 Mon Sep 17 00:00:00 2001 From: dearblue Date: Mon, 21 Jul 2025 22:44:39 +0900 Subject: [PATCH] Stricter type tag in `mrb_obj_alloc()` Instances cannot be created with `MRB_TT_FALSE`. _**Compatibility Note**_ This change may cause runtime errors. However, that is probably because it is not set correctly by `MRB_SET_INSTANCE_TT()`. --- src/gc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gc.c b/src/gc.c index ab50b4b23..0be46af7c 100644 --- a/src/gc.c +++ b/src/gc.c @@ -482,12 +482,12 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) mrb_raise(mrb, E_TYPE_ERROR, "allocation failure"); } tt = MRB_INSTANCE_TT(cls); - if (tt != MRB_TT_FALSE && - ttype != MRB_TT_SCLASS && + if (ttype != MRB_TT_SCLASS && ttype != MRB_TT_ICLASS && ttype != MRB_TT_ENV && ttype != MRB_TT_BIGINT && - ttype != tt) { + ttype != tt && + !(cls == mrb->object_class && (ttype == MRB_TT_CPTR || ttype == MRB_TT_CDATA || ttype == MRB_TT_ISTRUCT))) { mrb_raisef(mrb, E_TYPE_ERROR, "allocation failure of %C", cls); } }