ruby-changes:33047
From: naruse <ko1@a...>
Date: Sat, 22 Feb 2014 18:24:54 +0900 (JST)
Subject: [ruby-changes:33047] naruse:r45126 (ruby_2_1): merge revision(s) 45057, 45059: [Backport #9533]
naruse 2014-02-22 18:24:49 +0900 (Sat, 22 Feb 2014) New Revision: 45126 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45126 Log: merge revision(s) 45057,45059: [Backport #9533] * hash.c (rb_hash_flatten): fix behavior of flatten(-1). [ruby-dev:47988] [Bug #9533] * test/ruby/test_array.rb: test for above. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/hash.c branches/ruby_2_1/test/ruby/test_hash.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 45125) +++ ruby_2_1/ChangeLog (revision 45126) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Sat Feb 22 18:20:58 2014 Masaki Matsushita <glass.saga@g...> + + * hash.c (rb_hash_flatten): fix behavior of flatten(-1). + [ruby-dev:47988] [Bug #9533] + + * test/ruby/test_array.rb: test for above. + Sat Feb 22 17:46:32 2014 Tanaka Akira <akr@f...> * lib/open-uri.rb: Make proxy disabling working again. Index: ruby_2_1/hash.c =================================================================== --- ruby_2_1/hash.c (revision 45125) +++ ruby_2_1/hash.c (revision 45126) @@ -67,7 +67,7 @@ rb_hash_freeze(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L67 VALUE rb_cHash; static VALUE envtbl; -static ID id_hash, id_yield, id_default; +static ID id_hash, id_yield, id_default, id_flatten_bang; VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone) @@ -2399,15 +2399,25 @@ rb_hash_flatten(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L2399 { VALUE ary; - ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2); - rb_hash_foreach(hash, flatten_i, ary); if (argc) { - int level = NUM2INT(*argv) - 1; - if (level > 0) { - *argv = INT2FIX(level); - rb_funcall2(ary, rb_intern("flatten!"), argc, argv); + int level = NUM2INT(*argv); + if (level == 0) return rb_hash_to_a(hash); + + ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2); + rb_hash_foreach(hash, flatten_i, ary); + if (level - 1 > 0) { + *argv = INT2FIX(level - 1); + rb_funcall2(ary, id_flatten_bang, argc, argv); + } + else if (level < 0) { + rb_funcall2(ary, id_flatten_bang, 0, 0); } } + else { + ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2); + rb_hash_foreach(hash, flatten_i, ary); + } + return ary; } @@ -3757,6 +3767,7 @@ Init_Hash(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L3767 id_hash = rb_intern("hash"); id_yield = rb_intern("yield"); id_default = rb_intern("default"); + id_flatten_bang = rb_intern("flatten!"); rb_cHash = rb_define_class("Hash", rb_cObject); Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 45125) +++ ruby_2_1/version.h (revision 45126) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.1" #define RUBY_RELEASE_DATE "2014-02-22" -#define RUBY_PATCHLEVEL 70 +#define RUBY_PATCHLEVEL 71 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_1/test/ruby/test_hash.rb =================================================================== --- ruby_2_1/test/ruby/test_hash.rb (revision 45125) +++ ruby_2_1/test/ruby/test_hash.rb (revision 45126) @@ -973,11 +973,11 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_hash.rb#L973 a = @cls[1=> "one", 2 => [2,"two"], 3 => [3, ["three"]]] assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten) - assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(-1)) - assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(0)) + assert_equal([[1, "one"], [2, [2, "two"]], [3, [3, ["three"]]]], a.flatten(0)) assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(1)) assert_equal([1, "one", 2, 2, "two", 3, 3, ["three"]], a.flatten(2)) assert_equal([1, "one", 2, 2, "two", 3, 3, "three"], a.flatten(3)) + assert_equal([1, "one", 2, 2, "two", 3, 3, "three"], a.flatten(-1)) assert_raise(TypeError){ a.flatten(Object) } end Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45057,45059 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/