[前][次][番号順一覧][スレッド一覧]

ruby-changes:47013

From: nobu <ko1@a...>
Date: Wed, 21 Jun 2017 11:25:32 +0900 (JST)
Subject: [ruby-changes:47013] nobu:r59128 (trunk): Fix Enumerable#uniq with non single yield arguments

nobu	2017-06-21 11:25:27 +0900 (Wed, 21 Jun 2017)

  New Revision: 59128

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59128

  Log:
    Fix Enumerable#uniq with non single yield arguments
    
    * enum.c (uniq_func, uniq_iter): need packed value as the unique
      key.  [ruby-core:81734] [Bug #13669] [Fix GH-1658]
    
    Author:    Kenichi Kamiya <kachick1@g...>

  Modified files:
    trunk/enum.c
    trunk/test/ruby/test_enum.rb
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 59127)
+++ test/ruby/test_enum.rb	(revision 59128)
@@ -977,5 +977,6 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L977
     assert_equal([[1896, "Athens"], [1900, "Paris"], [1904, "Chicago"], [1908, "Rome"]],
                  olympics.uniq{|k,v| v})
     assert_equal([1, 2, 3, 4, 5, 10], (1..100).uniq{|x| (x**2) % 10 }.first(6))
+    assert_equal([1, [1, 2]], Foo.new.to_enum.uniq)
   end
 end
Index: enum.c
===================================================================
--- enum.c	(revision 59127)
+++ enum.c	(revision 59128)
@@ -3855,6 +3855,7 @@ enum_sum(int argc, VALUE* argv, VALUE ob https://github.com/ruby/ruby/blob/trunk/enum.c#L3855
 static VALUE
 uniq_func(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
 {
+    ENUM_WANT_SVALUE();
     rb_hash_add_new_element(hash, i, i);
     return Qnil;
 }
@@ -3862,6 +3863,7 @@ uniq_func(RB_BLOCK_CALL_FUNC_ARGLIST(i, https://github.com/ruby/ruby/blob/trunk/enum.c#L3863
 static VALUE
 uniq_iter(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
 {
+    ENUM_WANT_SVALUE();
     rb_hash_add_new_element(hash, rb_yield_values2(argc, argv), i);
     return Qnil;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]