[前][次][番号順一覧][スレッド一覧]

ruby-changes:34289

From: akr <ko1@a...>
Date: Sat, 7 Jun 2014 11:41:16 +0900 (JST)
Subject: [ruby-changes:34289] akr:r46370 (trunk): * object.c (rb_mod_initialize_clone): Override Kernel#initialize_clone

akr	2014-06-07 11:41:01 +0900 (Sat, 07 Jun 2014)

  New Revision: 46370

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46370

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/object.c
    trunk/test/ruby/test_class.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46369)
+++ ChangeLog	(revision 46370)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  7 11:35:01 2014  Tanaka Akira  <akr@f...>
+
+	* 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@g...>
 
 	* ext/digest/digest.c (rb_digest_instance_equal):
Index: object.c
===================================================================
--- object.c	(revision 46369)
+++ object.c	(revision 46370)
@@ -1701,6 +1701,16 @@ rb_mod_initialize(VALUE module) https://github.com/ruby/ruby/blob/trunk/object.c#L1701
     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) https://github.com/ruby/ruby/blob/trunk/object.c#L3379
 
     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 */
Index: test/ruby/test_class.rb
===================================================================
--- test/ruby/test_class.rb	(revision 46369)
+++ test/ruby/test_class.rb	(revision 46370)
@@ -378,4 +378,10 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L378
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]