mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Prohibit Class#allocate in a different way
The method introduced by #5979 causes a fault by swapping classes. ```console % bin/mruby -e 'Method = Proc; p Object.method(:inspect)' zsh: segmentation fault (core dumped) bin/mruby -e 'Method = Proc; p Object.method(:inspect)' ``` After applying this patch, a `TypeError` exception will be raised. ```console % bin/mruby -e 'Method = Proc; p Object.method(:inspect)' trace (most recent call last): [1] -e:1 -e:1:in method: allocation failure of Proc (TypeError) ``` However, if the `mrb_vtype` is the same object, the same care must still be taken as before. ```console % bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")' trace (most recent call last): [1] -e:1 -e:1:in eval: wrong argument type nil (expected Proc) (TypeError) ```
This commit is contained in:
@@ -395,7 +395,8 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
|
||||
struct RClass *comp;
|
||||
|
||||
comp = mrb_define_class_id(mrb, MRB_SYM(Complex), mrb_class_get_id(mrb, MRB_SYM(Numeric)));
|
||||
MRB_SET_INSTANCE_TT(comp, MRB_TT_UNDEF);
|
||||
MRB_SET_INSTANCE_TT(comp, MRB_TT_COMPLEX);
|
||||
MRB_UNDEF_ALLOCATOR(comp);
|
||||
|
||||
mrb_undef_class_method(mrb, comp, "new");
|
||||
mrb_define_class_method(mrb, comp, "rectangular", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
|
||||
|
||||
Reference in New Issue
Block a user