Skip to content

Commit 8a059b4

Browse files
committed
merge revision(s) 45076: [Backport ruby#9535]
* class.c (rb_mod_init_copy): do nothing if copying self. [ruby-dev:47989] [Bug ruby#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
1 parent ada0c63 commit 8a059b4

File tree

9 files changed

+33
-3
lines changed

9 files changed

+33
-3
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Sat Feb 22 18:48:57 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* class.c (rb_mod_init_copy): do nothing if copying self.
4+
[ruby-dev:47989] [Bug #9535]
5+
6+
* hash.c (rb_hash_initialize_copy): ditto.
7+
18
Sat Feb 22 18:20:58 2014 Masaki Matsushita <[email protected]>
29

310
* hash.c (rb_hash_flatten): fix behavior of flatten(-1).

class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
321321
if (RB_TYPE_P(clone, T_CLASS)) {
322322
class_init_copy_check(clone, orig);
323323
}
324-
rb_obj_init_copy(clone, orig);
324+
if (!OBJ_INIT_COPY(clone, orig)) return clone;
325325
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
326326
RBASIC_SET_CLASS(clone, rb_singleton_class_clone(orig));
327327
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);

ext/bigdecimal/bigdecimal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,9 @@ BigDecimal_initialize_copy(VALUE self, VALUE other)
24812481
Real *pv = rb_check_typeddata(self, &BigDecimal_data_type);
24822482
Real *x = rb_check_typeddata(other, &BigDecimal_data_type);
24832483

2484-
DATA_PTR(self) = VpCopy(pv, x);
2484+
if (self != other) {
2485+
DATA_PTR(self) = VpCopy(pv, x);
2486+
}
24852487
return self;
24862488
}
24872489

ext/json/generator/generator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ static VALUE cState_init_copy(VALUE obj, VALUE orig)
965965
{
966966
JSON_Generator_State *objState, *origState;
967967

968+
if (obj == orig) return obj;
968969
Data_Get_Struct(obj, JSON_Generator_State, objState);
969970
Data_Get_Struct(orig, JSON_Generator_State, origState);
970971
if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State");

ext/zlib/zlib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ rb_deflate_init_copy(VALUE self, VALUE orig)
15561556
Data_Get_Struct(self, struct zstream, z1);
15571557
z2 = get_zstream(orig);
15581558

1559+
if (z1 == z2) return self;
15591560
err = deflateCopy(&z1->stream, &z2->stream);
15601561
if (err != Z_OK) {
15611562
raise_zlib_error(err, 0);

hash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ rb_hash_initialize_copy(VALUE hash, VALUE hash2)
14281428

14291429
Check_Type(hash2, T_HASH);
14301430

1431+
if (hash == hash2) return hash;
1432+
14311433
ntbl = RHASH(hash)->ntbl;
14321434
if (RHASH(hash2)->ntbl) {
14331435
if (ntbl) st_free_table(ntbl);

test/ruby/test_hash.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ def test_clear_initialize_copy
108108
assert_empty(h)
109109
end
110110

111+
def test_self_initialize_copy
112+
h = @cls[1=>2]
113+
h.instance_eval {initialize_copy(h)}
114+
assert_equal(2, h[1])
115+
end
116+
111117
def test_dup_will_rehash
112118
set1 = @cls[]
113119
set2 = @cls[set1 => true]

test/ruby/test_module.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,17 @@ def test_constants
364364
assert_equal([:MIXIN, :USER], User.constants.sort)
365365
end
366366

367+
def test_self_initialize_copy
368+
bug9535 = '[ruby-dev:47989] [Bug #9535]'
369+
m = Module.new do
370+
def foo
371+
:ok
372+
end
373+
initialize_copy(self)
374+
end
375+
assert_equal(:ok, Object.new.extend(m).foo, bug9535)
376+
end
377+
367378
def test_dup
368379
bug6454 = '[ruby-core:45132]'
369380

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-22"
3-
#define RUBY_PATCHLEVEL 71
3+
#define RUBY_PATCHLEVEL 72
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)