From 272dd5c6b7c5cfe05a8b360b9e9d76a90f9e647f Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 20 Dec 2012 10:03:54 +0000 Subject: 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@38507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- class.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'class.c') diff --git a/class.c b/class.c index df19812d15..4fbdf18fb7 100644 --- a/class.c +++ b/class.c @@ -159,10 +159,27 @@ clone_const_i(st_data_t key, st_data_t value, st_data_t data) 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) 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) { -- cgit v1.2.3