ruby-changes:30041
From: naruse <ko1@a...>
Date: Sun, 21 Jul 2013 05:45:02 +0900 (JST)
Subject: [ruby-changes:30041] naruse:r42093 (trunk): * hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit
naruse 2013-07-21 05:44:49 +0900 (Sun, 21 Jul 2013) New Revision: 42093 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42093 Log: * hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit platform. it's introduced by r42039 Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_hash.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42092) +++ ChangeLog (revision 42093) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jul 21 03:36:18 2013 NARUSE, Yui <naruse@r...> + + * hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit + platform. it's introduced by r42039 + Sun Jul 21 01:07:45 2013 Benoit Daloze <eregontp@g...> * common.mk (help): Fix environment variable name and argument. Index: hash.c =================================================================== --- hash.c (revision 42092) +++ hash.c (revision 42093) @@ -2223,7 +2223,7 @@ rb_hash_flatten(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/hash.c#L2223 ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2); rb_hash_foreach(hash, flatten_i, ary); if (argc) { - int level = FIX2INT(*argv) - 1; + int level = NUM2INT(*argv) - 1; if (level > 0) { *argv = INT2FIX(level); rb_funcall2(ary, rb_intern("flatten!"), argc, argv); Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 42092) +++ test/ruby/test_hash.rb (revision 42093) @@ -879,6 +879,15 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L879 def test_flatten assert_equal([[1], [2]], {[1] => [2]}.flatten) + + a = {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(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_raise(TypeError){ a.flatten(Object) } end def test_callcc -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/