From 1f29e8e2baa548bba9e385ebbade2198b4cc3859 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 21 Feb 2014 11:42:03 +0000 Subject: class.c: do nothing if copying self * 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/trunk@45076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 4 +++- ext/json/generator/generator.c | 1 + ext/zlib/zlib.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index f33dd82458..31479d4edb 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2494,7 +2494,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 06509ca93f..1b9652df24 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 c0f52c23cc..824dd1324a 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1563,6 +1563,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); -- cgit v1.2.3