* object.c (rb_mod_initialize_clone): Override Kernel#initialize_clone

to avoid an exception on Class.new.freeze.clone.to_s.
  Reported by Andrew Grimm.  [ruby-core:41858] [Bug #5828]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-06-07 02:41:01 +00:00
Родитель aae1877882
Коммит 4169440f38
3 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sat Jun 7 11:35:01 2014 Tanaka Akira <akr@fsij.org>
* object.c (rb_mod_initialize_clone): Override Kernel#initialize_clone
to avoid an exception on Class.new.freeze.clone.to_s.
Reported by Andrew Grimm. [ruby-core:41858] [Bug #5828]
Sat Jun 7 06:03:11 2014 Benoit Daloze <eregontp@gmail.com>
* ext/digest/digest.c (rb_digest_instance_equal):

Просмотреть файл

@ -1701,6 +1701,16 @@ rb_mod_initialize(VALUE module)
return Qnil;
}
static VALUE
rb_mod_initialize_clone(VALUE clone, VALUE orig)
{
VALUE ret;
ret = rb_obj_init_dup_clone(clone, orig);
if (OBJ_FROZEN(orig))
rb_class_name(clone);
return ret;
}
/*
* call-seq:
* Class.new(super_class=Object) -> a_class
@ -3369,6 +3379,7 @@ Init_Object(void)
rb_define_alloc_func(rb_cModule, rb_module_s_alloc);
rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
rb_define_method(rb_cModule, "initialize_clone", rb_mod_initialize_clone, 1);
rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "public_instance_methods",
rb_class_public_instance_methods, -1); /* in class.c */

Просмотреть файл

@ -378,4 +378,10 @@ class TestClass < Test::Unit::TestCase
assert_predicate(self.singleton_class, :singleton_class?, feature7609)
assert_not_predicate(self.class, :singleton_class?, feature7609)
end
def test_freeze_to_s
assert_nothing_raised("[ruby-core:41858] [Bug #5828]") {
Class.new.freeze.clone.to_s
}
end
end