summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-22 09:53:35 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-22 09:53:35 +0000
commit776b8b1fd1932221621b85e0a3176cc69ebb0647 (patch)
tree7e3d7b854428b0f18542412f8be1dae2897d3445
parentd2164fc5f2c8d32aaa9a857ca680c8f6d05ed106 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--class.c2
-rw-r--r--ext/bigdecimal/bigdecimal.c4
-rw-r--r--ext/json/generator/generator.c1
-rw-r--r--ext/zlib/zlib.c1
-rw-r--r--hash.c2
-rw-r--r--test/ruby/test_hash.rb6
-rw-r--r--test/ruby/test_module.rb11
-rw-r--r--version.h2
9 files changed, 33 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e0be9a5532..b61a02d11e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Feb 22 18:48:57 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.
+
Sat Feb 22 18:20:58 2014 Masaki Matsushita <glass.saga@gmail.com>
* hash.c (rb_hash_flatten): fix behavior of flatten(-1).
diff --git a/class.c b/class.c
index e161e25063..bf9b2bb43e 100644
--- a/class.c
+++ b/class.c
@@ -321,7 +321,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_SET_CLASS(clone, 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 8c470fc2b7..4120a2346d 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2481,7 +2481,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 ed7bb82887..550e9beef0 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -965,6 +965,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 391bec1722..ffdd9a0b7d 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -1556,6 +1556,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);
diff --git a/hash.c b/hash.c
index db510c818e..66cd94bcdd 100644
--- a/hash.c
+++ b/hash.c
@@ -1428,6 +1428,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 800241a703..0bbdf13a07 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 ba6f273159..f89071c10f 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -364,6 +364,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]'
diff --git a/version.h b/version.h
index 52c4bf043e..2138e5e758 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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