diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-08-14 14:09:56 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-08-14 14:09:56 +0900 |
| commit | 603005ba6508da59220a4c7385a0c98bda78a201 (patch) | |
| tree | 80d94f73726a2e31ac89597b8ea2c2393a85395f | |
| parent | 8ed15fd92e6d3ce7963db8c3162bdebee7b55e1b (diff) | |
| download | mruby-603005ba6508da59220a4c7385a0c98bda78a201.tar.gz mruby-603005ba6508da59220a4c7385a0c98bda78a201.zip | |
Integrate `kazuho/mruby-class-new-fiber-safe` in the master.
Avoid calling `initialize` via `mrb_funcall`, which cause `cross C
boundary` error from Fibers started in the method.
| -rw-r--r-- | mrblib/00class.rb | 8 | ||||
| -rw-r--r-- | src/class.c | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/mrblib/00class.rb b/mrblib/00class.rb index 1811236f0..8fcfb1362 100644 --- a/mrblib/00class.rb +++ b/mrblib/00class.rb @@ -1,3 +1,11 @@ +class Class + def new(*args, &block) + obj = self.allocate + obj.initialize(*args, &block) + obj + end +end + class Module # 15.2.2.4.12 def attr_accessor(*names) diff --git a/src/class.c b/src/class.c index 071b29901..112257380 100644 --- a/src/class.c +++ b/src/class.c @@ -2159,6 +2159,7 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, bob, "instance_eval", mrb_obj_instance_eval, MRB_ARGS_ANY()); /* 15.3.1.3.18 */ mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, cls, "allocate", mrb_instance_alloc, MRB_ARGS_NONE()); mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, MRB_ARGS_NONE()); /* 15.2.3.3.4 */ mrb_define_method(mrb, cls, "new", mrb_instance_new, MRB_ARGS_ANY()); /* 15.2.3.3.3 */ mrb_define_method(mrb, cls, "initialize", mrb_class_initialize, MRB_ARGS_OPT(1)); /* 15.2.3.3.1 */ |
