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

ruby-changes:18863

From: kosaki <ko1@a...>
Date: Wed, 16 Feb 2011 20:42:11 +0900 (JST)
Subject: [ruby-changes:18863] Ruby:r30888 (trunk): * eval_jump.c (rb_exec_end_proc): changed at_exit and END proc

kosaki	2011-02-16 20:42:03 +0900 (Wed, 16 Feb 2011)

  New Revision: 30888

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

  Log:
    * eval_jump.c (rb_exec_end_proc): changed at_exit and END proc
      evaluation order. [Bug #4400] [ruby-core:35237]
    * eval_jump.c (rb_mark_end_proc): ditto.
    
    * test/ruby/test_beginendblock.rb (TestBeginEndBlock#test_nested_at_exit):
      added a test for nested at_exit.
    * test/ruby/test_beginendblock.rb (TestBeginEndBlock#test_beginendblock):
      changed the test to adopt new spec.

  Modified files:
    trunk/ChangeLog
    trunk/eval_jump.c
    trunk/test/ruby/test_beginendblock.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30887)
+++ ChangeLog	(revision 30888)
@@ -1,3 +1,14 @@
+Wed Feb 16 20:37:48 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* eval_jump.c (rb_exec_end_proc): changed at_exit and END proc
+	  evaluation order. [Bug #4400] [ruby-core:35237]
+	* eval_jump.c (rb_mark_end_proc): ditto.
+
+	* test/ruby/test_beginendblock.rb (TestBeginEndBlock#test_nested_at_exit):
+	  added a test for nested at_exit.
+	* test/ruby/test_beginendblock.rb (TestBeginEndBlock#test_beginendblock):
+	  changed the test to adopt new spec.
+
 Wed Feb 16 20:17:06 2011  Tanaka Akira  <akr@f...>
 
 	* ext/openssl/openssl_missing.h: parenthesize macro arguments.
Index: eval_jump.c
===================================================================
--- eval_jump.c	(revision 30887)
+++ eval_jump.c	(revision 30888)
@@ -54,7 +54,7 @@
     struct end_proc_data *next;
 };
 
-static struct end_proc_data *end_procs, *ephemeral_end_procs, *tmp_end_procs;
+static struct end_proc_data *end_procs, *ephemeral_end_procs;
 
 void
 rb_set_end_proc(void (*func)(VALUE), VALUE data)
@@ -91,11 +91,6 @@
 	rb_gc_mark(link->data);
 	link = link->next;
     }
-    link = tmp_end_procs;
-    while (link) {
-	rb_gc_mark(link->data);
-	link = link->next;
-    }
 }
 
 void
@@ -107,40 +102,35 @@
     volatile int safe = rb_safe_level();
 
     while (ephemeral_end_procs) {
-	tmp_end_procs = link = ephemeral_end_procs;
-	ephemeral_end_procs = 0;
-	while (link) {
-	    PUSH_TAG();
-	    if ((status = EXEC_TAG()) == 0) {
-		rb_set_safe_level_force(link->safe);
-		(*link->func) (link->data);
-	    }
-	    POP_TAG();
-	    if (status) {
-		error_handle(status);
-	    }
-	    tmp = link;
-	    tmp_end_procs = link = link->next;
-	    xfree(tmp);
+	link = ephemeral_end_procs;
+	ephemeral_end_procs = link->next;
+
+	PUSH_TAG();
+	if ((status = EXEC_TAG()) == 0) {
+	    rb_set_safe_level_force(link->safe);
+	    (*link->func) (link->data);
 	}
+	POP_TAG();
+	if (status) {
+	    error_handle(status);
+	}
+	xfree(link);
     }
+
     while (end_procs) {
-	tmp_end_procs = link = end_procs;
-	end_procs = 0;
-	while (link) {
-	    PUSH_TAG();
-	    if ((status = EXEC_TAG()) == 0) {
-		rb_set_safe_level_force(link->safe);
-		(*link->func) (link->data);
-	    }
-	    POP_TAG();
-	    if (status) {
-		error_handle(status);
-	    }
-	    tmp = link;
-	    tmp_end_procs = link = link->next;
-	    xfree(tmp);
+	link = end_procs;
+	end_procs = link->next;
+
+	PUSH_TAG();
+	if ((status = EXEC_TAG()) == 0) {
+	    rb_set_safe_level_force(link->safe);
+	    (*link->func) (link->data);
 	}
+	POP_TAG();
+	if (status) {
+	    error_handle(status);
+	}
+	xfree(link);
     }
     rb_set_safe_level_force(safe);
 }
Index: test/ruby/test_beginendblock.rb
===================================================================
--- test/ruby/test_beginendblock.rb	(revision 30887)
+++ test/ruby/test_beginendblock.rb	(revision 30888)
@@ -14,7 +14,7 @@
     ruby = EnvUtil.rubybin
     target = File.join(DIR, 'beginmainend.rb')
     result = IO.popen([ruby, target]){|io|io.read}
-    assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), result.split)
+    assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e1-1 e4 e4-2 e4-1 e4-1-1 e3 e2), result.split)
 
     input = Tempfile.new(self.class.name)
     inputpath = input.path
@@ -124,4 +124,25 @@
     assert_match(/e1/, out)
     assert_match(/e6/, out)
   end
+
+  def test_nested_at_exit
+    t = Tempfile.new(["test_nested_at_exit_", ".rb"])
+    t.puts "at_exit { puts :outer0 }"
+    t.puts "at_exit { puts :outer1_begin; at_exit { puts :inner1 }; puts :outer1_end }"
+    t.puts "at_exit { puts :outer2_begin; at_exit { puts :inner2 }; puts :outer2_end }"
+    t.puts "at_exit { puts :outer3 }"
+    t.flush
+
+    expected = [ "outer3",
+                 "outer2_begin",
+                 "outer2_end",
+                 "inner2",
+                 "outer1_begin",
+                 "outer1_end",
+                 "inner1",
+                 "outer0" ]
+
+    assert_in_out_err(t.path, "", expected, [], "[ruby-core:35237]")
+    t.close
+  end
 end

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

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