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

ruby-changes:28329

From: nagachika <ko1@a...>
Date: Sat, 20 Apr 2013 01:29:06 +0900 (JST)
Subject: [ruby-changes:28329] nagachika:r40381 (ruby_2_0_0): merge revision(s) 40260,40377: [Backport #8260]

nagachika	2013-04-20 01:28:55 +0900 (Sat, 20 Apr 2013)

  New Revision: 40381

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

  Log:
    merge revision(s) 40260,40377: [Backport #8260]
    
    * vm_insnhelper.c (vm_callee_setup_keyword_arg): non-symbol key is not
      a keyword argument, keep it as an positional argument.
      a keyword argument, keep it as a positional argument.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/test/ruby/test_keyword.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm_insnhelper.c

Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 40380)
+++ ruby_2_0_0/ChangeLog	(revision 40381)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Sat Apr 20 01:18:20 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_callee_setup_keyword_arg): non-symbol key is not
+	  a keyword argument, keep it as a positional argument.
+
 Sat Apr 20 01:14:08 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* thread.c (rb_mutex_synchronize_m): yield no block params.  patch by
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 40380)
+++ ruby_2_0_0/version.h	(revision 40381)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-04-20"
-#define RUBY_PATCHLEVEL 148
+#define RUBY_PATCHLEVEL 149
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_0_0/vm_insnhelper.c
===================================================================
--- ruby_2_0_0/vm_insnhelper.c	(revision 40380)
+++ ruby_2_0_0/vm_insnhelper.c	(revision 40381)
@@ -1064,16 +1064,47 @@ vm_caller_setup_args(const rb_thread_t * https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1064
     }
 }
 
+static int
+separate_symbol(st_data_t key, st_data_t value, st_data_t arg)
+{
+    VALUE *kwdhash = (VALUE *)arg;
+
+    if (!SYMBOL_P(key)) kwdhash++;
+    if (!*kwdhash) *kwdhash = rb_hash_new();
+    rb_hash_aset(*kwdhash, (VALUE)key, (VALUE)value);
+    return ST_CONTINUE;
+}
+
+static VALUE
+extract_keywords(VALUE *orighash)
+{
+    VALUE parthash[2] = {0, 0};
+    VALUE hash = *orighash;
+
+    if (RHASH_EMPTY_P(hash)) {
+	*orighash = 0;
+	return hash;
+    }
+    st_foreach(RHASH_TBL(hash), separate_symbol, (st_data_t)&parthash);
+    *orighash = parthash[1];
+    return parthash[0];
+}
+
 static inline int
 vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, VALUE *orig_argv, VALUE *kwd)
 {
-    VALUE keyword_hash;
+    VALUE keyword_hash, orig_hash;
     int i, j;
 
     if (argc > 0 &&
-	!NIL_P(keyword_hash = rb_check_hash_type(orig_argv[argc-1]))) {
-	argc--;
-	keyword_hash = rb_hash_dup(keyword_hash);
+	!NIL_P(orig_hash = rb_check_hash_type(orig_argv[argc-1])) &&
+	(keyword_hash = extract_keywords(&orig_hash)) != 0) {
+	if (!orig_hash) {
+	    argc--;
+	}
+	else {
+	    orig_argv[argc-1] = orig_hash;
+	}
 	if (iseq->arg_keyword_check) {
 	    for (i = j = 0; i < iseq->arg_keywords; i++) {
 		if (st_lookup(RHASH_TBL(keyword_hash), ID2SYM(iseq->arg_keyword_table[i]), 0)) j++;
Index: ruby_2_0_0/test/ruby/test_keyword.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_keyword.rb	(revision 40380)
+++ ruby_2_0_0/test/ruby/test_keyword.rb	(revision 40381)
@@ -23,6 +23,7 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_keyword.rb#L23
   def test_f2
     assert_equal([:xyz, "foo", 424242], f2(:xyz))
     assert_raise(ArgumentError) { f2({}) } # [ruby-dev:46712] [Bug #7529]
+    assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42))
   end
 
 

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r40260,40377


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

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