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

ruby-changes:29210

From: nagachika <ko1@a...>
Date: Thu, 13 Jun 2013 00:03:43 +0900 (JST)
Subject: [ruby-changes:29210] nagachika:r41262 (ruby_2_0_0): merge revision(s) 41019,41020,41021,41041,41045,41057: [Backport #8463]

nagachika	2013-06-13 00:03:22 +0900 (Thu, 13 Jun 2013)

  New Revision: 41262

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

  Log:
    merge revision(s) 41019,41020,41021,41041,41045,41057: [Backport #8463]
    
    vm_insnhelper.c: add comments
    
    * vm_insnhelper.c (vm_yield_setup_block_args): break a long line and
      add comments.  remove useless code.
    * vm_insnhelper.c (vm_yield_setup_block_args): split single parameter
      if any keyword arguments exist, and then extract keyword arguments.
      [ruby-core:55203] [Bug #8463]
    
    * compile.c (iseq_set_arguments): not a simple single argument if any
      keyword arguments exist.  [ruby-core:55203] [Bug #8463]
    
    * vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019.
      The code is not useless.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/compile.c
    branches/ruby_2_0_0/test/ruby/test_keyword.rb
    branches/ruby_2_0_0/test/ruby/test_yield.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 41261)
+++ ruby_2_0_0/ChangeLog	(revision 41262)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Jun 12 23:41:21 2013  NARUSE, Yui  <naruse@r...>
+
+	* vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019.
+	  The code is not useless.
+
+Wed Jun 12 23:41:21 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_yield_setup_block_args): split single parameter
+	  if any keyword arguments exist, and then extract keyword arguments.
+	  [ruby-core:55203] [Bug #8463]
+
 Wed Jun 12 23:05:41 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (io_getc): fix 7bit coderange condition, check if ascii read
Index: ruby_2_0_0/compile.c
===================================================================
--- ruby_2_0_0/compile.c	(revision 41261)
+++ ruby_2_0_0/compile.c	(revision 41262)
@@ -1264,7 +1264,8 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/compile.c#L1264
 	}
 
 	if (iseq->type == ISEQ_TYPE_BLOCK) {
-	    if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 && iseq->arg_rest == -1) {
+	    if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 &&
+		iseq->arg_rest == -1 && iseq->arg_keyword == -1) {
 		if (iseq->argc == 1 && last_comma == 0) {
 		    /* {|a|} */
 		    iseq->arg_simple |= 0x02;
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 41261)
+++ ruby_2_0_0/version.h	(revision 41262)
@@ -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-06-12"
-#define RUBY_PATCHLEVEL 215
+#define RUBY_PATCHLEVEL 216
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 6
Index: ruby_2_0_0/vm_insnhelper.c
===================================================================
--- ruby_2_0_0/vm_insnhelper.c	(revision 41261)
+++ ruby_2_0_0/vm_insnhelper.c	(revision 41262)
@@ -2166,11 +2166,6 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2166
 
     th->mark_stack_len = argc;
 
-    /* keyword argument */
-    if (iseq->arg_keyword != -1) {
-	argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
-    }
-
     /*
      * yield [1, 2]
      *  => {|a|} => a = [1, 2]
@@ -2178,7 +2173,10 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2173
      */
     arg0 = argv[0];
     if (!(iseq->arg_simple & 0x02) &&                           /* exclude {|a|} */
-	((m + iseq->arg_post_len) > 0 || iseq->arg_opts > 2) &&        /* this process is meaningful */
+	((m + iseq->arg_post_len) > 0 ||			/* positional arguments exist */
+	 iseq->arg_opts > 2 ||					/* multiple optional arguments exist */
+	 iseq->arg_keyword != -1 ||				/* any keyword arguments */
+	 0) &&
 	argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
 	th->mark_stack_len = argc = RARRAY_LENINT(ary);
 
@@ -2187,9 +2185,20 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2185
 	MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
     }
     else {
+	/* vm_push_frame current argv is at the top of sp because vm_invoke_block
+	 * set sp at the first element of argv.
+	 * Therefore when rb_check_array_type(arg0) called to_ary and called to_ary
+	 * or method_missing run vm_push_frame, it initializes local variables.
+	 * see also https://bugs.ruby-lang.org/issues/8484
+	 */
 	argv[0] = arg0;
     }
 
+    /* keyword argument */
+    if (iseq->arg_keyword != -1) {
+	argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
+    }
+
     for (i=argc; i<m; i++) {
 	argv[i] = Qnil;
     }
Index: ruby_2_0_0/test/ruby/test_keyword.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_keyword.rb	(revision 41261)
+++ ruby_2_0_0/test/ruby/test_keyword.rb	(revision 41262)
@@ -263,9 +263,16 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_keyword.rb#L263
 
   def test_rest_keyrest
     bug7665 = '[ruby-core:51278]'
+    bug8463 = '[ruby-core:55203] [Bug #8463]'
     expect = [*%w[foo bar], {zzz: 42}]
     assert_equal(expect, rest_keyrest(*expect), bug7665)
-    assert_equal(expect, proc {|*args, **opt| next *args, opt}.call(*expect), bug7665)
+    pr = proc {|*args, **opt| next *args, opt}
+    assert_equal(expect, pr.call(*expect), bug7665)
+    assert_equal(expect, pr.call(expect), bug8463)
+    pr = proc {|a, *b, **opt| next a, *b, opt}
+    assert_equal(expect, pr.call(expect), bug8463)
+    pr = proc {|a, **opt| next a, opt}
+    assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
   end
 
   def test_bare_kwrest
Index: ruby_2_0_0/test/ruby/test_yield.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_yield.rb	(revision 41261)
+++ ruby_2_0_0/test/ruby/test_yield.rb	(revision 41262)
@@ -379,4 +379,15 @@ class TestRubyYieldGen < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_yield.rb#L379
     }
   end
 
+  def test_block_with_mock
+    y = Object.new
+    def y.s(a)
+      yield(a)
+    end
+    m = Object.new
+    def m.method_missing(*a)
+      super
+    end
+    assert_equal [m, nil], y.s(m){|a,b|[a,b]}
+  end
 end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r41019-41021,41041,41045,41057


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

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