ruby-changes:34417
From: nagachika <ko1@a...>
Date: Mon, 23 Jun 2014 02:52:34 +0900 (JST)
Subject: [ruby-changes:34417] nagachika:r46498 (ruby_2_1): merge revision(s) r45874: [Backport #9813]
nagachika 2014-06-23 02:52:26 +0900 (Mon, 23 Jun 2014) New Revision: 46498 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46498 Log: merge revision(s) r45874: [Backport #9813] * class.c (rb_mod_init_copy): always clear instance variable, constant and method tables first, regardless the source tables. [ruby-dev:48182] [Bug #9813] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/class.c branches/ruby_2_1/test/ruby/test_module.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 46497) +++ ruby_2_1/ChangeLog (revision 46498) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Mon Jun 23 02:46:14 2014 Nobuyoshi Nakada <nobu@r...> + + * class.c (rb_mod_init_copy): always clear instance variable, + constant and method tables first, regardless the source tables. + [ruby-dev:48182] [Bug #9813] + Mon Jun 23 02:36:04 2014 Nobuyoshi Nakada <nobu@r...> * thread.c (thread_start_func_2): stop if forked in a sub-thread, Index: ruby_2_1/class.c =================================================================== --- ruby_2_1/class.c (revision 46497) +++ ruby_2_1/class.c (revision 46498) @@ -328,12 +328,21 @@ rb_mod_init_copy(VALUE clone, VALUE orig https://github.com/ruby/ruby/blob/trunk/ruby_2_1/class.c#L328 } RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig)); RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator; + if (RCLASS_IV_TBL(clone)) { + st_free_table(RCLASS_IV_TBL(clone)); + RCLASS_IV_TBL(clone) = 0; + } + if (RCLASS_CONST_TBL(clone)) { + rb_free_const_table(RCLASS_CONST_TBL(clone)); + RCLASS_CONST_TBL(clone) = 0; + } + if (RCLASS_M_TBL_WRAPPER(clone)) { + rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone)); + RCLASS_M_TBL_WRAPPER(clone) = 0; + } if (RCLASS_IV_TBL(orig)) { st_data_t id; - if (RCLASS_IV_TBL(clone)) { - st_free_table(RCLASS_IV_TBL(clone)); - } RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig)); CONST_ID(id, "__tmp_classpath__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); @@ -344,18 +353,13 @@ rb_mod_init_copy(VALUE clone, VALUE orig https://github.com/ruby/ruby/blob/trunk/ruby_2_1/class.c#L353 } if (RCLASS_CONST_TBL(orig)) { struct clone_const_arg arg; - if (RCLASS_CONST_TBL(clone)) { - rb_free_const_table(RCLASS_CONST_TBL(clone)); - } + RCLASS_CONST_TBL(clone) = st_init_numtable(); arg.klass = clone; arg.tbl = RCLASS_CONST_TBL(clone); st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg); } if (RCLASS_M_TBL(orig)) { - if (RCLASS_M_TBL_WRAPPER(clone)) { - rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone)); - } RCLASS_M_TBL_INIT(clone); st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone); } Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 46497) +++ ruby_2_1/version.h (revision 46498) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-06-23" -#define RUBY_PATCHLEVEL 136 +#define RUBY_PATCHLEVEL 137 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_1/test/ruby/test_module.rb =================================================================== --- ruby_2_1/test/ruby/test_module.rb (revision 46497) +++ ruby_2_1/test/ruby/test_module.rb (revision 46498) @@ -375,6 +375,25 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_module.rb#L375 assert_equal(:ok, Object.new.extend(m).foo, bug9535) end + def test_initialize_copy_empty + bug9813 = '[ruby-dev:48182] [Bug #9813]' + m = Module.new do + def x + end + const_set(:X, 1) + @x = 2 + end + assert_equal([:x], m.instance_methods) + assert_equal([:@x], m.instance_variables) + assert_equal([:X], m.constants) + m.module_eval do + initialize_copy(Module.new) + end + assert_empty(m.instance_methods, bug9813) + assert_empty(m.instance_variables, bug9813) + assert_empty(m.constants, bug9813) + end + def test_dup bug6454 = '[ruby-core:45132]' Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45874 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/