diff options
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 37 |
1 files changed, 20 insertions, 17 deletions
@@ -2,7 +2,7 @@ class.c - - $Author: yugui $ + $Author: usa $ created at: Tue Aug 10 15:05:44 JST 1993 Copyright (C) 1993-2007 Yukihiro Matsumoto @@ -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) { @@ -698,6 +699,8 @@ rb_include_module(VALUE klass, VALUE module) c = RCLASS_SUPER(c) = include_class_new(module, RCLASS_SUPER(c)); if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries) changed = 1; + if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries) + changed = 1; skip: module = RCLASS_SUPER(module); } |