summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-02 10:54:39 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-02 10:54:39 +0000
commitb2a4cea3b95d89b8cb42df5fb269fc687ca19abe (patch)
tree089ba7afccf3bbac5ce3b78be0ab27ba5a3f3e0b /eval.c
parenta1692f7fdf62dc109886d9910b4dcca635dc2e25 (diff)
Modules should not have subclasses.
When refining a module, the module was set to the superclass of its refinement, and a segmentation fault occurred. The superclass of the refinement should be an iclass of the module. [ruby-core:83617] [Bug #14070] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/eval.c b/eval.c
index 8703e8e..0a8d32e 100644
--- a/eval.c
+++ b/eval.c
@@ -1304,6 +1304,10 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
}
}
FL_SET(module, RMODULE_IS_OVERLAID);
+ if (RB_TYPE_P(superclass, T_MODULE)) {
+ superclass = rb_include_class_new(superclass,
+ RCLASS_SUPER(superclass));
+ }
c = iclass = rb_include_class_new(module, superclass);
RCLASS_REFINED_CLASS(c) = klass;
@@ -1398,6 +1402,10 @@ add_activated_refinement(VALUE activated_refinements,
}
}
FL_SET(refinement, RMODULE_IS_OVERLAID);
+ if (RB_TYPE_P(superclass, T_MODULE)) {
+ superclass = rb_include_class_new(superclass,
+ RCLASS_SUPER(superclass));
+ }
c = iclass = rb_include_class_new(refinement, superclass);
RCLASS_REFINED_CLASS(c) = klass;
refinement = RCLASS_SUPER(refinement);
@@ -1453,7 +1461,12 @@ rb_mod_refine(VALUE module, VALUE klass)
refinement = rb_hash_lookup(refinements, klass);
if (NIL_P(refinement)) {
refinement = rb_module_new();
- RCLASS_SET_SUPER(refinement, klass);
+ if (RB_TYPE_P(klass, T_MODULE)) {
+ rb_include_module(refinement, klass);
+ }
+ else {
+ RCLASS_SET_SUPER(refinement, klass);
+ }
FL_SET(refinement, RMODULE_IS_REFINEMENT);
CONST_ID(id_refined_class, "__refined_class__");
rb_ivar_set(refinement, id_refined_class, klass);