Allow Class#allocate to be prohibited

Calling `Class#allocate` with `UnboundMethod#bind_call` usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with `MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF)`.

At the same time, it applies to the `Binding`, `Complex`, `Data`, `Float`, `Integer`, `Method`, `Rational` and `UnboundMethod` classes.
This commit is contained in:
dearblue
2023-04-09 21:14:07 +09:00
parent c3ba76794f
commit d3128ce58a
8 changed files with 13 additions and 5 deletions
+3
View File
@@ -1945,6 +1945,9 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv)
ttype = MRB_TT_OBJECT;
}
if (ttype <= MRB_TT_CPTR) {
if (ttype == MRB_TT_UNDEF) {
mrb_raisef(mrb, E_TYPE_ERROR, "allocator undefined for %v", cv);
}
mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %v", cv);
}
o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);