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

ruby-changes:28915

From: ko1 <ko1@a...>
Date: Tue, 28 May 2013 02:08:36 +0900 (JST)
Subject: [ruby-changes:28915] ko1:r40967 (trunk): * vm_trace.c (rb_postponed_job_register_one): fix iteration bug.

ko1	2013-05-28 02:08:25 +0900 (Tue, 28 May 2013)

  New Revision: 40967

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

  Log:
    * vm_trace.c (rb_postponed_job_register_one): fix iteration bug.
    * ext/-test-/postponed_job/postponed_job.c,
      test/-ext-/postponed_job/test_postponed_job.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/ext/-test-/postponed_job/postponed_job.c
    trunk/test/-ext-/postponed_job/test_postponed_job.rb
    trunk/vm_trace.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40966)
+++ ChangeLog	(revision 40967)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 28 02:07:21 2013  Koichi Sasada  <ko1@a...>
+
+	* vm_trace.c (rb_postponed_job_register_one): fix iteration bug.
+
+	* ext/-test-/postponed_job/postponed_job.c,
+	  test/-ext-/postponed_job/test_postponed_job.rb: add a test.
+
 Tue May 28 00:34:23 2013  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/ruby.h, gc.c: add new internal event
Index: ext/-test-/postponed_job/postponed_job.c
===================================================================
--- ext/-test-/postponed_job/postponed_job.c	(revision 40966)
+++ ext/-test-/postponed_job/postponed_job.c	(revision 40967)
@@ -17,6 +17,24 @@ pjob_register(VALUE self, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/-test-/postponed_job/postponed_job.c#L17
     return self;
 }
 
+static void
+pjob_one_callback(void *data)
+{
+    VALUE ary = (VALUE)data;
+    Check_Type(ary, T_ARRAY);
+
+    rb_ary_push(ary, INT2FIX(1));
+}
+
+static VALUE
+pjob_register_one(VALUE self, VALUE obj)
+{
+    rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
+    rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
+    rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
+    return self;
+}
+
 static VALUE
 pjob_call_direct(VALUE self, VALUE obj)
 {
@@ -29,6 +47,7 @@ Init_postponed_job(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/-test-/postponed_job/postponed_job.c#L47
 {
     VALUE mBug = rb_define_module("Bug");
     rb_define_module_function(mBug, "postponed_job_register", pjob_register, 1);
+    rb_define_module_function(mBug, "postponed_job_register_one", pjob_register_one, 1);
     rb_define_module_function(mBug, "postponed_job_call_direct", pjob_call_direct, 1);
 }
 
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 40966)
+++ vm_trace.c	(revision 40967)
@@ -1415,6 +1415,7 @@ rb_postponed_job_register_one(unsigned i https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1415
 	if (pjob->func == func) {
 	    return 2;
 	}
+	pjob = pjob->next;
     }
 
     return rb_postponed_job_register(flags, func, data);
Index: test/-ext-/postponed_job/test_postponed_job.rb
===================================================================
--- test/-ext-/postponed_job/test_postponed_job.rb	(revision 40966)
+++ test/-ext-/postponed_job/test_postponed_job.rb	(revision 40967)
@@ -21,5 +21,8 @@ class TestPostponed_job < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/postponed_job/test_postponed_job.rb#L21
 
     assert_match     /postponed_job_call_direct_wrapper/, direct.join
     assert_not_match /postponed_job_register_wrapper/, registered.join
+
+    Bug.postponed_job_register_one(ary = [])
+    assert_equal [1], ary
   end
 end

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

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