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

ruby-changes:26456

From: usa <ko1@a...>
Date: Thu, 20 Dec 2012 19:04:03 +0900 (JST)
Subject: [ruby-changes:26456] usa:r38507 (ruby_1_9_3): merge revision(s) 38364,38366: [Backport #7557]

usa	2012-12-20 19:03:54 +0900 (Thu, 20 Dec 2012)

  New Revision: 38507

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

  Log:
    merge revision(s) 38364,38366: [Backport #7557]
    
    * object.c (Init_Object): use rb_mod_init_copy for Class#initialize_copy
    
    * class.c (rb_class_init_copy): rename to class_init_copy_check, performs type
      checks on arguments to prevent reinitialization of initialized class
      [ruby-core:50869] [Bug #7557]
    
    * class.c (rb_mod_init_copy): use class_init_copy_check if receiver is T_CLASS
    
    * test/ruby/test_class.rb (class TestClass): related test

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/class.c
    branches/ruby_1_9_3/object.c
    branches/ruby_1_9_3/test/ruby/test_class.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 38506)
+++ ruby_1_9_3/ChangeLog	(revision 38507)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Thu Dec 13 23:10:52  Charlie Somerville  <charlie@c...>
+	* object.c (Init_Object): use rb_mod_init_copy for Class#initialize_copy
+	* class.c (rb_class_init_copy): rename to class_init_copy_check, performs type
+	  checks on arguments to prevent reinitialization of initialized class
+	  [ruby-core:50869] [Bug #7557]
+	* class.c (rb_mod_init_copy): use class_init_copy_check if receiver is T_CLASS
+	* test/ruby/test_class.rb (class TestClass): related test
+
+
 Thu Dec 20 18:46:17 2012  Naohisa Goto  <ngotogenome@g...>
 
 	* test/dl/test_func.rb (test_name_with_block, test_bind, test_qsort1):
Index: ruby_1_9_3/object.c
===================================================================
--- ruby_1_9_3/object.c	(revision 38506)
+++ ruby_1_9_3/object.c	(revision 38507)
@@ -2791,7 +2791,6 @@ Init_Object(void) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/object.c#L2791
     rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
     rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
     rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
-    rb_define_method(rb_cClass, "initialize_copy", rb_class_init_copy, 1); /* in class.c */
     rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
     rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
     rb_undef_method(rb_cClass, "extend_object");
Index: ruby_1_9_3/class.c
===================================================================
--- ruby_1_9_3/class.c	(revision 38506)
+++ ruby_1_9_3/class.c	(revision 38507)
@@ -159,10 +159,27 @@ clone_const_i(st_data_t key, st_data_t v https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/class.c#L159
     return clone_const((ID)key, (const rb_const_entry_t *)value, (st_table *)data);
 }
 
+static void
+class_init_copy_check(VALUE clone, VALUE orig)
+{
+    if (orig == rb_cBasicObject) {
+	rb_raise(rb_eTypeError, "can't copy the root class");
+    }
+    if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
+	rb_raise(rb_eTypeError, "already initialized class");
+    }
+    if (FL_TEST(orig, FL_SINGLETON)) {
+	rb_raise(rb_eTypeError, "can't copy singleton class");
+    }
+}
+
 /* :nodoc: */
 VALUE
 rb_mod_init_copy(VALUE clone, VALUE orig)
 {
+    if (RB_TYPE_P(clone, T_CLASS)) {
+	class_init_copy_check(clone, orig);
+    }
     rb_obj_init_copy(clone, orig);
     if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
 	RBASIC(clone)->klass = rb_singleton_class_clone(orig);
@@ -203,22 +220,6 @@ rb_mod_init_copy(VALUE clone, VALUE orig https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/class.c#L220
     return clone;
 }
 
-/* :nodoc: */
-VALUE
-rb_class_init_copy(VALUE clone, VALUE orig)
-{
-    if (orig == rb_cBasicObject) {
-	rb_raise(rb_eTypeError, "can't copy the root class");
-    }
-    if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
-	rb_raise(rb_eTypeError, "already initialized class");
-    }
-    if (FL_TEST(orig, FL_SINGLETON)) {
-	rb_raise(rb_eTypeError, "can't copy singleton class");
-    }
-    return rb_mod_init_copy(clone, orig);
-}
-
 VALUE
 rb_singleton_class_clone(VALUE obj)
 {
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 38506)
+++ ruby_1_9_3/version.h	(revision 38507)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 353
+#define RUBY_PATCHLEVEL 354
 
 #define RUBY_RELEASE_DATE "2012-12-20"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/ruby/test_class.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_class.rb	(revision 38506)
+++ ruby_1_9_3/test/ruby/test_class.rb	(revision 38507)
@@ -258,4 +258,19 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_class.rb#L258
     END
     assert_equal(42, PrivateClass.new.foo)
   end
+
+  def test_cannot_reinitialize_class_with_initialize_copy # [ruby-core:50869]
+    assert_in_out_err([], <<-RUBY, ["Object"], [])
+      class Class
+        def initialize_copy(*); super; end
+      end
+
+      class A; end
+      class B; end
+
+      A.send(:initialize_copy, Class.new(B)) rescue nil
+
+      p A.superclass
+    RUBY
+  end
 end

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r38364,38366


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

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