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

ruby-changes:33847

From: nagachika <ko1@a...>
Date: Mon, 12 May 2014 22:49:39 +0900 (JST)
Subject: [ruby-changes:33847] nagachika:r45928 (ruby_2_1): merge revision(s) r45758, r45759: [Backport #9759]

nagachika	2014-05-12 22:49:33 +0900 (Mon, 12 May 2014)

  New Revision: 45928

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

  Log:
    merge revision(s) r45758,r45759: [Backport #9759]
    
    * vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record
      it is bmethod frame.
    
    * vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame
      is VM_FRAME_FLAG_BMETHOD.
      [Bug #9759]
    
    * test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
    
    * vm_core.h: rename rb_thread_t::passed_me to
      rb_thread_t::passed_bmethod_me to clarify the usage.
    
    * vm_insnhelper.c (vm_call_bmethod_body): use renamed member.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/test/ruby/test_settracefunc.rb
    branches/ruby_2_1/version.h
    branches/ruby_2_1/vm.c
    branches/ruby_2_1/vm_core.h
    branches/ruby_2_1/vm_insnhelper.c
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 45927)
+++ ruby_2_1/ChangeLog	(revision 45928)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon May 12 22:22:43 2014  Koichi Sasada  <ko1@a...>
+
+	* vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record
+	  it is bmethod frame.
+
+	* vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame
+	  is VM_FRAME_FLAG_BMETHOD.
+	  [Bug #9759]
+
+	* test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
+
+	* vm_core.h: rename rb_thread_t::passed_me to
+	  rb_thread_t::passed_bmethod_me to clarify the usage.
+
+	* vm_insnhelper.c (vm_call_bmethod_body): use renamed member.
+
 Mon May 12 22:11:47 2014  Shota Fukumori  <her@s...>
 
 	* vm_eval.c (eval_string_with_cref): Unify to use NIL_P.
Index: ruby_2_1/vm_core.h
===================================================================
--- ruby_2_1/vm_core.h	(revision 45927)
+++ ruby_2_1/vm_core.h	(revision 45928)
@@ -542,7 +542,7 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_core.h#L542
     const rb_block_t *passed_block;
 
     /* for bmethod */
-    const rb_method_entry_t *passed_me;
+    const rb_method_entry_t *passed_bmethod_me;
 
     /* for cfunc */
     rb_call_info_t *passed_ci;
@@ -768,9 +768,11 @@ enum vm_special_object_type { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_core.h#L768
 #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
 
 /* other frame flag */
-#define VM_FRAME_FLAG_PASSED 0x0100
-#define VM_FRAME_FLAG_FINISH 0x0200
-#define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
+#define VM_FRAME_FLAG_PASSED  0x0100
+#define VM_FRAME_FLAG_FINISH  0x0200
+#define VM_FRAME_FLAG_BMETHOD 0x0400
+#define VM_FRAME_TYPE_FINISH_P(cfp)  (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
+#define VM_FRAME_TYPE_BMETHOD_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_BMETHOD) != 0)
 
 #define RUBYVM_CFUNC_FRAME_P(cfp) \
   (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
Index: ruby_2_1/vm.c
===================================================================
--- ruby_2_1/vm.c	(revision 45927)
+++ ruby_2_1/vm.c	(revision 45928)
@@ -717,13 +717,24 @@ invoke_block_from_c(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L717
 	opt_pc = vm_yield_setup_args(th, iseq, argc, cfp->sp, blockptr,
 				     type == VM_FRAME_MAGIC_LAMBDA);
 
-	vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH,
-		      self, defined_class,
-		      VM_ENVVAL_PREV_EP_PTR(block->ep),
-		      iseq->iseq_encoded + opt_pc,
-		      cfp->sp + arg_size, iseq->local_size - arg_size,
-		      th->passed_me, iseq->stack_max);
-	th->passed_me = 0;
+	if (th->passed_bmethod_me != 0) {
+	    /* bmethod */
+	    vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_BMETHOD,
+			  self, defined_class,
+			  VM_ENVVAL_PREV_EP_PTR(block->ep),
+			  iseq->iseq_encoded + opt_pc,
+			  cfp->sp + arg_size, iseq->local_size - arg_size,
+			  th->passed_bmethod_me, iseq->stack_max);
+	    th->passed_bmethod_me = 0;
+	}
+	else {
+	    vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH,
+			  self, defined_class,
+			  VM_ENVVAL_PREV_EP_PTR(block->ep),
+			  iseq->iseq_encoded + opt_pc,
+			  cfp->sp + arg_size, iseq->local_size - arg_size,
+			  0, iseq->stack_max);
+	}
 
 	if (cref) {
 	    th->cfp->ep[-1] = (VALUE)cref;
@@ -1512,7 +1523,13 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L1523
 		break;
 	      case VM_FRAME_MAGIC_BLOCK:
 	      case VM_FRAME_MAGIC_LAMBDA:
-		EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
+		if (VM_FRAME_TYPE_BMETHOD_P(th->cfp)) {
+		    EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
+		    EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, th->cfp->me->called_id, th->cfp->me->klass, Qnil);
+		}
+		else {
+		    EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
+		}
 		break;
 	      case VM_FRAME_MAGIC_CLASS:
 		EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 45927)
+++ ruby_2_1/version.h	(revision 45928)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
 #define RUBY_RELEASE_DATE "2014-05-12"
-#define RUBY_PATCHLEVEL 98
+#define RUBY_PATCHLEVEL 99
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 5
Index: ruby_2_1/vm_insnhelper.c
===================================================================
--- ruby_2_1/vm_insnhelper.c	(revision 45927)
+++ ruby_2_1/vm_insnhelper.c	(revision 45928)
@@ -1587,7 +1587,7 @@ vm_call_bmethod_body(rb_thread_t *th, rb https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_insnhelper.c#L1587
     EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, ci->recv, ci->me->called_id, ci->me->klass, Qnil);
 
     /* control block frame */
-    th->passed_me = ci->me;
+    th->passed_bmethod_me = ci->me;
     GetProcPtr(ci->me->def->body.proc, proc);
     val = vm_invoke_proc(th, proc, ci->recv, ci->defined_class, ci->argc, argv, ci->blockptr);
 
Index: ruby_2_1/test/ruby/test_settracefunc.rb
===================================================================
--- ruby_2_1/test/ruby/test_settracefunc.rb	(revision 45927)
+++ ruby_2_1/test/ruby/test_settracefunc.rb	(revision 45928)
@@ -1066,4 +1066,38 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_settracefunc.rb#L1066
       :b_return
     ], events)
   end
+  class C9759
+    define_method(:foo){
+      raise
+    }
+  end
+
+  def test_define_method_on_exception
+    events = []
+    obj = C9759.new
+    TracePoint.new(:call, :return){|tp|
+      next unless target_thread?
+      events << [tp.event, tp.method_id]
+    }.enable{
+      obj.foo rescue nil
+    }
+    assert_equal([[:call, :foo], [:return, :foo]], events, 'Bug #9759')
+
+    events = []
+    begin
+      set_trace_func(lambda{|event, file, lineno, mid, binding, klass|
+        next unless target_thread?
+        case event
+        when 'call', 'return'
+          events << [event, mid]
+        end
+      })
+      obj.foo rescue nil
+      set_trace_func(nil)
+
+      assert_equal([['call', :foo], ['return', :foo]], events, 'Bug #9759')
+    ensure
+    end
+
+  end
 end

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45758-45759


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

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