summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-05 14:05:52 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-05 14:05:52 +0000
commit652e695a384563e0f96adc70d16ff53a3567451a (patch)
treeb69609f055f9fc87d053984fc2b0e7f44663ee95 /eval.c
parent82031fa8449ccc351da2e2c857d26be92c2cc281 (diff)
merge revision(s) 60980,60984: [Backport #14070]
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] The superclass of a refinement should have BasicObject as its ancestor. Otherwise, VM_ASSERT(callable_method_entry_p(cme)) in prepare_callable_method_entry() fails if VM_CHECK_MODE is 2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/eval.c b/eval.c
index 8a839ced7d..617cb6f1be 100644
--- a/eval.c
+++ b/eval.c
@@ -1144,6 +1144,18 @@ hidden_identity_hash_new(void)
return hash;
}
+static VALUE
+refinement_superclass(VALUE superclass)
+{
+ if (RB_TYPE_P(superclass, T_MODULE)) {
+ /* FIXME: Should ancestors of superclass be used here? */
+ return rb_include_class_new(superclass, rb_cBasicObject);
+ }
+ else {
+ return superclass;
+ }
+}
+
void
rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
{
@@ -1171,6 +1183,7 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
}
}
FL_SET(module, RMODULE_IS_OVERLAID);
+ superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(module, superclass);
RCLASS_REFINED_CLASS(c) = klass;
@@ -1260,6 +1273,7 @@ add_activated_refinement(VALUE activated_refinements,
}
}
FL_SET(refinement, RMODULE_IS_OVERLAID);
+ superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(refinement, superclass);
RCLASS_REFINED_CLASS(c) = klass;
refinement = RCLASS_SUPER(refinement);
@@ -1314,8 +1328,9 @@ rb_mod_refine(VALUE module, VALUE klass)
}
refinement = rb_hash_lookup(refinements, klass);
if (NIL_P(refinement)) {
+ VALUE superclass = refinement_superclass(klass);
refinement = rb_module_new();
- RCLASS_SET_SUPER(refinement, klass);
+ RCLASS_SET_SUPER(refinement, superclass);
FL_SET(refinement, RMODULE_IS_REFINEMENT);
CONST_ID(id_refined_class, "__refined_class__");
rb_ivar_set(refinement, id_refined_class, klass);