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

ruby-changes:8896

From: nobu <ko1@a...>
Date: Mon, 1 Dec 2008 12:01:13 +0900 (JST)
Subject: [ruby-changes:8896] Ruby:r20432 (trunk): * cont.c (rb_fiber_start): calls with exact argument number.

nobu	2008-12-01 12:00:48 +0900 (Mon, 01 Dec 2008)

  New Revision: 20432

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

  Log:
    * cont.c (rb_fiber_start): calls with exact argument number.
      [ruby-core:20088]

  Modified files:
    trunk/ChangeLog
    trunk/cont.c
    trunk/test/ruby/test_fiber.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20431)
+++ ChangeLog	(revision 20432)
@@ -1,3 +1,8 @@
+Mon Dec  1 12:00:45 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* cont.c (rb_fiber_start): calls with exact argument number.
+	  [ruby-core:20088]
+
 Sun Nov 30 21:41:10 2008  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* man/rake.1: new manual page
Index: cont.c
===================================================================
--- cont.c	(revision 20431)
+++ cont.c	(revision 20432)
@@ -25,6 +25,7 @@
 typedef struct rb_context_struct {
     enum context_type type;
     VALUE self;
+    int argc;
     VALUE value;
     VALUE *vm_stack;
 #ifdef CAPTURE_JUST_VALID_VM_STACK
@@ -558,6 +559,7 @@
 	}
     }
 
+    cont->argc = argc;
     cont->value = make_passing_arg(argc, argv);
 
     cont_restore_0(cont, &contval);
@@ -685,7 +687,6 @@
     rb_fiber_t *fib;
     rb_context_t *cont;
     rb_proc_t *proc;
-    VALUE args;
     int state;
 
     GetFiberPtr(th->fiber, fib);
@@ -693,15 +694,18 @@
 
     TH_PUSH_TAG(th);
     if ((state = EXEC_TAG()) == 0) {
+	int argc;
+	VALUE *argv, args;
 	GetProcPtr(cont->saved_thread.first_proc, proc);
 	args = cont->value;
+	argv = (argc = cont->argc) > 1 ? RARRAY_PTR(args) : &args;
 	cont->value = Qnil;
 	th->errinfo = Qnil;
 	th->local_lfp = proc->block.lfp;
 	th->local_svar = Qnil;
 
 	fib->status = RUNNING;
-	cont->value = vm_invoke_proc(th, proc, proc->block.self, 1, &args, 0);
+	cont->value = vm_invoke_proc(th, proc, proc->block.self, argc, argv, 0);
     }
     TH_POP_TAG();
 
@@ -798,6 +802,7 @@
 	fib->prev = rb_fiber_current();
     }
 
+    cont->argc = argc;
     cont->value = make_passing_arg(argc, argv);
 
     if ((value = fiber_store(fib)) == Qundef) {
Index: test/ruby/test_fiber.rb
===================================================================
--- test/ruby/test_fiber.rb	(revision 20431)
+++ test/ruby/test_fiber.rb	(revision 20432)
@@ -14,6 +14,10 @@
     assert_equal([:a, :b], Fiber.new{|a, b| [a, b]}.resume(:a, :b))
   end
 
+  def test_argument
+    assert_equal(4, Fiber.new {|i=4| i}.resume)
+  end
+
   def test_term
     assert_equal(:ok, Fiber.new{:ok}.resume)
     assert_equal([:a, :b, :c, :d, :e],

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

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