diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-22 02:49:01 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-22 02:49:01 +0000 |
commit | 8c6dd375a7fc4da62b49475bce5ea5a64105e5cd (patch) | |
tree | 215f0dc13854fb6523da641f87aa198e127a0786 | |
parent | 9702331cd53bcaf3ceb79687dedc8e0358a5309a (diff) |
merge revision(s) r45076: [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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@45096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | class.c | 2 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 4 | ||||
-rw-r--r-- | ext/json/generator/generator.c | 1 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 1 | ||||
-rw-r--r-- | hash.c | 2 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 6 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 11 | ||||
-rw-r--r-- | version.h | 6 |
9 files changed, 35 insertions, 5 deletions
@@ -1,3 +1,10 @@ +Sat Feb 22 11:44:50 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * class.c (rb_mod_init_copy): do nothing if copying self. + [ruby-dev:47989] [Bug #9535] + + * hash.c (rb_hash_initialize_copy): ditto. + Thu Feb 20 02:14:18 2014 Zachary Scott <e@zzak.io> * ext/openssl/lib/openssl/buffering.rb: Fix warning in copyright @@ -198,7 +198,7 @@ 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 (!OBJ_INIT_COPY(clone, orig)) return clone; if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) { RBASIC(clone)->klass = rb_singleton_class_clone(orig); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 9601d1c70f..266e85311e 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2427,7 +2427,9 @@ BigDecimal_initialize_copy(VALUE self, VALUE other) 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; } diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c index 5df8de1ddf..f32f866419 100644 --- a/ext/json/generator/generator.c +++ b/ext/json/generator/generator.c @@ -957,6 +957,7 @@ static VALUE cState_init_copy(VALUE obj, VALUE orig) { 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"); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index d3f29889b1..9294c2c857 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1554,6 +1554,7 @@ rb_deflate_init_copy(VALUE self, VALUE orig) 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); @@ -1240,6 +1240,8 @@ rb_hash_initialize_copy(VALUE hash, VALUE hash2) Check_Type(hash2, T_HASH); + if (hash == hash2) return hash; + ntbl = RHASH(hash)->ntbl; if (RHASH(hash2)->ntbl) { if (ntbl) st_free_table(ntbl); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index a77c5cf43f..b545395780 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -108,6 +108,12 @@ class TestHash < Test::Unit::TestCase 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] diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 4bc725d2b5..047f7c99d3 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -309,6 +309,17 @@ class TestModule < Test::Unit::TestCase 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]' @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.0.0" -#define RUBY_RELEASE_DATE "2014-02-21" -#define RUBY_PATCHLEVEL 443 +#define RUBY_RELEASE_DATE "2014-02-22" +#define RUBY_PATCHLEVEL 444 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 -#define RUBY_RELEASE_DAY 21 +#define RUBY_RELEASE_DAY 22 #include "ruby/version.h" |