From 11b3b5ed9024fa0d02400f90373269c0b91bbddf Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 9 Dec 2010 06:46:25 +0000 Subject: [PATCH] * array.c (rb_ary_dup): should copy contents only. no instance variable, no class would be copied. it would affect methods #sort, #reject, #transpose, #uniq, #compact, and #shuffle. [ruby-core:33640] * array.c (rb_ary_reverse_m): ditto. * array.c (rb_ary_rotate_m): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ array.c | 20 ++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5f63a7d30..df47861416 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Dec 9 11:00:30 2010 Yukihiro Matsumoto + + * array.c (rb_ary_dup): should copy contents only. no instance + variable, no class would be copied. it would affect methods + #sort, #reject, #transpose, #uniq, #compact, and #shuffle. + [ruby-core:33640] + + * array.c (rb_ary_reverse_m): ditto. + + * array.c (rb_ary_rotate_m): ditto. + Wed Dec 8 21:38:40 2010 NARUSE, Yui * ext/dl/lib/dl/struct.rb: clean a warning: assigned but unused diff --git a/array.c b/array.c index abaae571ad..b7c913d40d 100644 --- a/array.c +++ b/array.c @@ -1527,22 +1527,12 @@ rb_ary_empty_p(VALUE ary) return Qfalse; } -static VALUE -rb_ary_dup_setup(VALUE ary) -{ - VALUE dup = rb_ary_new2(RARRAY_LEN(ary)); - int is_embed = ARY_EMBED_P(dup); - DUPSETUP(dup, ary); - if (is_embed) FL_SET_EMBED(dup); - ARY_SET_LEN(dup, RARRAY_LEN(ary)); - return dup; -} - VALUE rb_ary_dup(VALUE ary) { - VALUE dup = rb_ary_dup_setup(ary); + VALUE dup = rb_ary_new2(RARRAY_LEN(ary)); MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary)); + ARY_SET_LEN(dup, RARRAY_LEN(ary)); return dup; } @@ -1830,14 +1820,15 @@ rb_ary_reverse_bang(VALUE ary) static VALUE rb_ary_reverse_m(VALUE ary) { - VALUE dup = rb_ary_dup_setup(ary); long len = RARRAY_LEN(ary); + VALUE dup = rb_ary_new2(len); if (len > 0) { VALUE *p1 = RARRAY_PTR(ary); VALUE *p2 = RARRAY_PTR(dup) + len - 1; do *p2-- = *p1++; while (--len > 0); } + ARY_SET_LEN(dup, RARRAY_LEN(ary)); return dup; } @@ -1925,7 +1916,7 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary) } len = RARRAY_LEN(ary); - rotated = rb_ary_dup_setup(ary); + rotated = rb_ary_new2(len); if (len > 0) { cnt = rotate_count(cnt, len); ptr = RARRAY_PTR(ary); @@ -1934,6 +1925,7 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary) MEMCPY(ptr2, ptr + cnt, VALUE, len); MEMCPY(ptr2 + len, ptr, VALUE, cnt); } + ARY_SET_LEN(rotated, RARRAY_LEN(ary)); return rotated; }