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

ruby-changes:37007

From: nobu <ko1@a...>
Date: Thu, 1 Jan 2015 09:14:29 +0900 (JST)
Subject: [ruby-changes:37007] nobu:r49088 (trunk): vm_args.c: fix non-symbol keys hash

nobu	2015-01-01 09:14:23 +0900 (Thu, 01 Jan 2015)

  New Revision: 49088

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

  Log:
    vm_args.c: fix non-symbol keys hash
    
    * vm_args.c (keyword_hash_p): fix non-symbol keys hash.
      rb_extract_keywords() returns 0 not Qnil when no symbol keys is
      included.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_keyword.rb
    trunk/vm_args.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49087)
+++ ChangeLog	(revision 49088)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan  1 09:14:21 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_args.c (keyword_hash_p): fix non-symbol keys hash.
+	  rb_extract_keywords() returns 0 not Qnil when no symbol keys is
+	  included.
+
 Wed Dec 31 17:48:43 2014  Tanaka Akira  <akr@f...>
 
 	* lib/resolv.rb (Resolv::DNS::Label::Str#initialize): Set encoding
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 49087)
+++ test/ruby/test_keyword.rb	(revision 49088)
@@ -559,4 +559,11 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L559
       assert_equal({:bar => "bar"}, obj.foo, bug10659)
     }
   end
+
+  def m(a) yield a end
+
+  def test_nonsymbol_key
+    result = m(["a" => 10]) { |a = nil, **b| [a, b] }
+    assert_equal([{"a" => 10}, {}], result)
+  end
 end
Index: vm_args.c
===================================================================
--- vm_args.c	(revision 49087)
+++ vm_args.c	(revision 49088)
@@ -179,7 +179,9 @@ keyword_hash_p(VALUE *kw_hash_ptr, VALUE https://github.com/ruby/ruby/blob/trunk/vm_args.c#L179
     th->mark_stack_len = msl;
 
     if (!NIL_P(*rest_hash_ptr)) {
-	*kw_hash_ptr = rb_extract_keywords(rest_hash_ptr);
+	VALUE hash = rb_extract_keywords(rest_hash_ptr);
+	if (!hash) hash = Qnil;
+	*kw_hash_ptr = hash;
 	return TRUE;
     }
     else {

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

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