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

ruby-changes:26726

From: usa <ko1@a...>
Date: Fri, 11 Jan 2013 17:02:16 +0900 (JST)
Subject: [ruby-changes:26726] usa:r38778 (ruby_1_9_3): [Backport #7624]

usa	2013-01-11 17:02:06 +0900 (Fri, 11 Jan 2013)

  New Revision: 38778

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

  Log:
    [Backport #7624]
    
    * vm_trace.c (rb_threadptr_exec_event_hooks): added a parameter to pop
      a frame before JUMP_TAG() if exception occurred. This change fix bug
      of Ruby 1.9. [ruby-core:51128] [ruby-trunk - Bug #7624]
    
    * vm_core.h (EXEC_EVENT_HOOK_AND_POP_FRAME): add to use
      `rb_threadptr_exec_event_hooks()' with the pop flag.
    
    * vm.c (vm_exec): use EXEC_EVENT_HOOK_AND_POP_FRAME() while exception
      handling. While exception hadnling, if an exception is raised in
      hooks, need to pop current frame and raise this raised exception by
      hook.
    
    * bootstraptest/test_flow.rb: add a test.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/KNOWNBUGS.rb
    branches/ruby_1_9_3/bootstraptest/test_flow.rb
    branches/ruby_1_9_3/thread.c
    branches/ruby_1_9_3/version.h
    branches/ruby_1_9_3/vm.c
    branches/ruby_1_9_3/vm_core.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 38777)
+++ ruby_1_9_3/ChangeLog	(revision 38778)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Fri Jan 11 16:57:31 2013  NAKAMURA Usaku  <usa@r...>
+
+	* vm_trace.c (rb_threadptr_exec_event_hooks): added a parameter to pop
+	  a frame before JUMP_TAG() if exception occurred. This change fix bug
+	  of Ruby 1.9. [ruby-core:51128] [ruby-trunk - Bug #7624]
+
+	* vm_core.h (EXEC_EVENT_HOOK_AND_POP_FRAME): add to use
+	  `rb_threadptr_exec_event_hooks()' with the pop flag.
+
+	* vm.c (vm_exec): use EXEC_EVENT_HOOK_AND_POP_FRAME() while exception
+	  handling. While exception hadnling, if an exception is raised in
+	  hooks, need to pop current frame and raise this raised exception by
+	  hook.
+
+	* bootstraptest/test_flow.rb: add a test.
+
 Mon Jan  7 15:50:25 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm.c (rb_vm_make_proc): save the proc made from the given block so
Index: ruby_1_9_3/bootstraptest/test_flow.rb
===================================================================
--- ruby_1_9_3/bootstraptest/test_flow.rb	(revision 38777)
+++ ruby_1_9_3/bootstraptest/test_flow.rb	(revision 38778)
@@ -562,3 +562,17 @@ assert_equal %Q{ENSURE\n}, %q{ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/bootstraptest/test_flow.rb#L562
   assert_equal "false", src + %q{e.all? {false}}, bug
   assert_equal "true", src + %q{e.include?(:foo)}, bug
 end
+
+assert_equal('ok', %q{
+  class FOO < RuntimeError; end
+  class BAR < RuntimeError; end
+  def m
+    raise FOO
+  end
+  set_trace_func(proc{|t,| raise BAR if t == 'return'})
+  begin
+    m
+  rescue BAR
+    'ok'
+  end
+}, '[ruby-core:51128] [ruby-trunk - Bug #7624]')
Index: ruby_1_9_3/vm_core.h
===================================================================
--- ruby_1_9_3/vm_core.h	(revision 38777)
+++ ruby_1_9_3/vm_core.h	(revision 38778)
@@ -728,17 +728,23 @@ void rb_thread_lock_destroy(rb_thread_lo https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/vm_core.h#L728
 
 /* tracer */
 void
-rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass);
+rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass, int pop_p);
 
-#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
+#define EXEC_EVENT_HOOK_ORIG(th, flag, self, id, klass, pop_p) do { \
     rb_event_flag_t wait_event__ = (th)->event_flags; \
     if (UNLIKELY(wait_event__)) { \
 	if (wait_event__ & ((flag) | RUBY_EVENT_VM)) { \
-	    rb_threadptr_exec_event_hooks((th), (flag), (self), (id), (klass)); \
+	    rb_threadptr_exec_event_hooks((th), (flag), (self), (id), (klass), (pop_p)); \
 	} \
     } \
 } while (0)
 
+#define EXEC_EVENT_HOOK(th, flag, self, id, klass) \
+  EXEC_EVENT_HOOK_ORIG(th, flag, self, id, klass, 0)
+
+#define EXEC_EVENT_HOOK_AND_POP_FRAME(th, flag, self, id, klass) \
+  EXEC_EVENT_HOOK_ORIG(th, flag, self, id, klass, 1)
+
 #if defined __GNUC__ && __GNUC__ >= 4
 #pragma GCC visibility push(default)
 #endif
Index: ruby_1_9_3/thread.c
===================================================================
--- ruby_1_9_3/thread.c	(revision 38777)
+++ ruby_1_9_3/thread.c	(revision 38778)
@@ -4060,7 +4060,7 @@ enum { https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4060
     EVENT_RUNNING_EVENT_MASK = EVENT_RUNNING_VM|EVENT_RUNNING_THREAD
 };
 
-static VALUE thread_suppress_tracing(rb_thread_t *th, int ev, VALUE (*func)(VALUE, int), VALUE arg, int always);
+static VALUE thread_suppress_tracing(rb_thread_t *th, int ev, VALUE (*func)(VALUE, int), VALUE arg, int always, int pop_p);
 
 struct event_call_args {
     rb_thread_t *th;
@@ -4145,25 +4145,16 @@ set_threads_event_flags(int flag) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4145
 static inline int
 exec_event_hooks(const rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
 {
-    volatile int removed = 0;
-    const rb_event_hook_t *volatile hnext = 0;
-    int state;
-
-    PUSH_TAG();
-    if ((state = EXEC_TAG()) != 0) {
-	hook = hnext;
-    }
+    int removed = 0;
     for (; hook; hook = hook->next) {
 	if (hook->flag & RUBY_EVENT_REMOVED) {
 	    removed++;
 	    continue;
 	}
 	if (flag & hook->flag) {
-	    hnext = hook->next;
 	    (*hook->func)(flag, hook->data, self, id, klass);
 	}
     }
-    POP_TAG();
     return removed;
 }
 
@@ -4208,7 +4199,7 @@ thread_exec_event_hooks(VALUE args, int https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4199
 }
 
 void
-rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
+rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass, int pop_p)
 {
     const VALUE errinfo = th->errinfo;
     struct event_call_args args;
@@ -4218,7 +4209,7 @@ rb_threadptr_exec_event_hooks(rb_thread_ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4209
     args.id = id;
     args.klass = klass;
     args.proc = 0;
-    thread_suppress_tracing(th, EVENT_RUNNING_EVENT_MASK, thread_exec_event_hooks, (VALUE)&args, FALSE);
+    thread_suppress_tracing(th, EVENT_RUNNING_EVENT_MASK, thread_exec_event_hooks, (VALUE)&args, FALSE, pop_p);
     th->errinfo = errinfo;
 }
 
@@ -4567,11 +4558,11 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4558
 ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
 {
     rb_thread_t *th = GET_THREAD();
-    return thread_suppress_tracing(th, EVENT_RUNNING_TRACE, func, arg, always);
+    return thread_suppress_tracing(th, EVENT_RUNNING_TRACE, func, arg, always, 0);
 }
 
 static VALUE
-thread_suppress_tracing(rb_thread_t *th, int ev, VALUE (*func)(VALUE, int), VALUE arg, int always)
+thread_suppress_tracing(rb_thread_t *th, int ev, VALUE (*func)(VALUE, int), VALUE arg, int always, int pop_p)
 {
     int state, tracing = th->tracing, running = tracing & ev;
     volatile int raised;
@@ -4601,6 +4592,9 @@ thread_suppress_tracing(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L4592
 
     th->tracing = tracing;
     if (state) {
+	if (pop_p) {
+	    th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
+	}
 	JUMP_TAG(state);
     }
     th->state = outer_state;
Index: ruby_1_9_3/KNOWNBUGS.rb
===================================================================
--- ruby_1_9_3/KNOWNBUGS.rb	(revision 38777)
+++ ruby_1_9_3/KNOWNBUGS.rb	(revision 38778)
@@ -3,5 +3,3 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/KNOWNBUGS.rb#L3
 # So all tests will cause failure.
 #
 
-assert_equal('', "set_trace_func(proc{|t,|raise if t == 'line'})\n""1\n'ok'")
-assert_finish(3, "def m; end\n""set_trace_func(proc{|t,|raise if t == 'return'})\n""m")
Index: ruby_1_9_3/vm.c
===================================================================
--- ruby_1_9_3/vm.c	(revision 38777)
+++ ruby_1_9_3/vm.c	(revision 38778)
@@ -1424,10 +1424,10 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/vm.c#L1424
 
 	    switch (VM_FRAME_TYPE(th->cfp)) {
 	      case VM_FRAME_MAGIC_METHOD:
-		EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0);
+		EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0);
 		break;
 	      case VM_FRAME_MAGIC_CLASS:
-		EXEC_EVENT_HOOK(th, RUBY_EVENT_END, th->cfp->self, 0, 0);
+		EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0);
 		break;
 	    }
 
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 38777)
+++ ruby_1_9_3/version.h	(revision 38778)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 363
+#define RUBY_PATCHLEVEL 364
 
-#define RUBY_RELEASE_DATE "2013-01-07"
+#define RUBY_RELEASE_DATE "2013-01-11"
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 1
-#define RUBY_RELEASE_DAY 7
+#define RUBY_RELEASE_DAY 11
 
 #include "ruby/version.h"
 

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

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