ruby-changes:33049
From: naruse <ko1@a...>
Date: Sat, 22 Feb 2014 18:53:41 +0900 (JST)
Subject: [ruby-changes:33049] naruse:r45128 (ruby_2_1): merge revision(s) 45076: [Backport #9535]
naruse 2014-02-22 18:53:35 +0900 (Sat, 22 Feb 2014) New Revision: 45128 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45128 Log: merge revision(s) 45076: [Backport #9535] * class.c (rb_mod_init_copy): do nothing if copying self. [ruby-dev:47989] [Bug #9535] * hash.c (rb_hash_initialize_copy): ditto. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/class.c branches/ruby_2_1/ext/bigdecimal/bigdecimal.c branches/ruby_2_1/ext/json/generator/generator.c branches/ruby_2_1/ext/zlib/zlib.c branches/ruby_2_1/hash.c branches/ruby_2_1/test/ruby/test_hash.rb 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 45127) +++ ruby_2_1/ChangeLog (revision 45128) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Sat Feb 22 18:48:57 2014 Nobuyoshi Nakada <nobu@r...> + + * class.c (rb_mod_init_copy): do nothing if copying self. + [ruby-dev:47989] [Bug #9535] + + * hash.c (rb_hash_initialize_copy): ditto. + Sat Feb 22 18:20:58 2014 Masaki Matsushita <glass.saga@g...> * hash.c (rb_hash_flatten): fix behavior of flatten(-1). Index: ruby_2_1/class.c =================================================================== --- ruby_2_1/class.c (revision 45127) +++ ruby_2_1/class.c (revision 45128) @@ -321,7 +321,7 @@ rb_mod_init_copy(VALUE clone, VALUE orig https://github.com/ruby/ruby/blob/trunk/ruby_2_1/class.c#L321 if (RB_TYPE_P(clone, T_CLASS)) { class_init_copy_check(clone, orig); } - rb_obj_init_copy(clone, orig); + if (!OBJ_INIT_COPY(clone, orig)) return clone; if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) { RBASIC_SET_CLASS(clone, rb_singleton_class_clone(orig)); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); Index: ruby_2_1/ext/bigdecimal/bigdecimal.c =================================================================== --- ruby_2_1/ext/bigdecimal/bigdecimal.c (revision 45127) +++ ruby_2_1/ext/bigdecimal/bigdecimal.c (revision 45128) @@ -2481,7 +2481,9 @@ BigDecimal_initialize_copy(VALUE self, V https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/bigdecimal/bigdecimal.c#L2481 Real *pv = rb_check_typeddata(self, &BigDecimal_data_type); Real *x = rb_check_typeddata(other, &BigDecimal_data_type); - DATA_PTR(self) = VpCopy(pv, x); + if (self != other) { + DATA_PTR(self) = VpCopy(pv, x); + } return self; } Index: ruby_2_1/ext/zlib/zlib.c =================================================================== --- ruby_2_1/ext/zlib/zlib.c (revision 45127) +++ ruby_2_1/ext/zlib/zlib.c (revision 45128) @@ -1556,6 +1556,7 @@ rb_deflate_init_copy(VALUE self, VALUE o https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/zlib/zlib.c#L1556 Data_Get_Struct(self, struct zstream, z1); z2 = get_zstream(orig); + if (z1 == z2) return self; err = deflateCopy(&z1->stream, &z2->stream); if (err != Z_OK) { raise_zlib_error(err, 0); Index: ruby_2_1/ext/json/generator/generator.c =================================================================== --- ruby_2_1/ext/json/generator/generator.c (revision 45127) +++ ruby_2_1/ext/json/generator/generator.c (revision 45128) @@ -965,6 +965,7 @@ static VALUE cState_init_copy(VALUE obj, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/json/generator/generator.c#L965 { JSON_Generator_State *objState, *origState; + if (obj == orig) return obj; Data_Get_Struct(obj, JSON_Generator_State, objState); Data_Get_Struct(orig, JSON_Generator_State, origState); if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State"); Index: ruby_2_1/hash.c =================================================================== --- ruby_2_1/hash.c (revision 45127) +++ ruby_2_1/hash.c (revision 45128) @@ -1428,6 +1428,8 @@ rb_hash_initialize_copy(VALUE hash, VALU https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L1428 Check_Type(hash2, T_HASH); + if (hash == hash2) return hash; + ntbl = RHASH(hash)->ntbl; if (RHASH(hash2)->ntbl) { if (ntbl) st_free_table(ntbl); Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 45127) +++ ruby_2_1/version.h (revision 45128) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.1" #define RUBY_RELEASE_DATE "2014-02-22" -#define RUBY_PATCHLEVEL 71 +#define RUBY_PATCHLEVEL 72 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_1/test/ruby/test_module.rb =================================================================== --- ruby_2_1/test/ruby/test_module.rb (revision 45127) +++ ruby_2_1/test/ruby/test_module.rb (revision 45128) @@ -364,6 +364,17 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_module.rb#L364 assert_equal([:MIXIN, :USER], User.constants.sort) end + def test_self_initialize_copy + bug9535 = '[ruby-dev:47989] [Bug #9535]' + m = Module.new do + def foo + :ok + end + initialize_copy(self) + end + assert_equal(:ok, Object.new.extend(m).foo, bug9535) + end + def test_dup bug6454 = '[ruby-core:45132]' Index: ruby_2_1/test/ruby/test_hash.rb =================================================================== --- ruby_2_1/test/ruby/test_hash.rb (revision 45127) +++ ruby_2_1/test/ruby/test_hash.rb (revision 45128) @@ -108,6 +108,12 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_hash.rb#L108 assert_empty(h) end + def test_self_initialize_copy + h = @cls[1=>2] + h.instance_eval {initialize_copy(h)} + assert_equal(2, h[1]) + end + def test_dup_will_rehash set1 = @cls[] set2 = @cls[set1 => true] Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45076 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/