Project

General

Profile

Bug #13705

[PATCH] `cfp consistency error' occurs when raising exception in bmethod call event

Added by ktsj (Kazuki Tsujimoto) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-07-02 master 59246) [x86_64-linux]
[ruby-dev:50162]

Description

bmethodのcallイベントの中でキャッチされない例外を起こすとcfp consistency errorになります。

define_method(:m) {}

tp = TracePoint.new(:call) do
  raise ''
end

tap do
  tap do
    begin
      tp.enable
      m
    rescue
    end
  end
end

invoke_bmethodでFINISHフラグが立ったフレームを積んでからvm_execを呼び出すまでの間に
EXEC_EVENT_HOOKを呼んでいるのが原因です。

EXEC_EVENT_HOOKの呼び出し後にフレームを積むよう修正すると互換性に影響するので
FINISHフラグの設定をvm_execの直前に遅延させるのがよさそうです。

diff --git a/vm.c b/vm.c
index 6ff1d23..d0c11c8 100644
--- a/vm.c
+++ b/vm.c
@@ -986,7 +986,7 @@ invoke_bmethod(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct
     int arg_size = iseq->body->param.size;
     VALUE ret;

-    vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_BMETHOD, self,
+    vm_push_frame(th, iseq, type | VM_FRAME_FLAG_BMETHOD, self,
          VM_GUARDED_PREV_EP(captured->ep),
          (VALUE)me,
          iseq->body->iseq_encoded + opt_pc,
@@ -996,6 +996,7 @@ invoke_bmethod(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct

     RUBY_DTRACE_METHOD_ENTRY_HOOK(th, me->owner, me->def->original_id);
     EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil);
+    VM_ENV_FLAGS_SET(th->ec.cfp->ep, VM_FRAME_FLAG_FINISH);
     ret = vm_exec(th);
     EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret);
     RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->owner, me->def->original_id);

Associated revisions

Revision 698f2db2
Added by ktsj (Kazuki Tsujimoto) over 1 year ago

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

  • vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec. [ruby-dev:50162] [Bug #13705]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59956
Added by ktsj (Kazuki Tsujimoto) over 1 year ago

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

  • vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec. [ruby-dev:50162] [Bug #13705]

Revision 59956
Added by ktsj (Kazuki Tsujimoto) over 1 year ago

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

  • vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec. [ruby-dev:50162] [Bug #13705]

Revision 59956
Added by ktsj (Kazuki Tsujimoto) over 1 year ago

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

  • vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec. [ruby-dev:50162] [Bug #13705]

Revision c2eabd83
Added by nagachika (Tomoyuki Chikanaga) about 1 year ago

merge revision(s) 59956: [Backport #13705]

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

* vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec.
  [ruby-dev:50162] [Bug #13705]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62651
Added by nagachika (Tomoyuki Chikanaga) about 1 year ago

merge revision(s) 59956: [Backport #13705]

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

* vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec.
  [ruby-dev:50162] [Bug #13705]

Revision 2fd7044e
Added by usa (Usaku NAKAMURA) about 1 year ago

merge revision(s) 59956: [Backport #13705]

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

* vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec.
  [ruby-dev:50162] [Bug #13705]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62815
Added by usa (Usaku NAKAMURA) about 1 year ago

merge revision(s) 59956: [Backport #13705]

vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

* vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec.
  [ruby-dev:50162] [Bug #13705]

History

#1

Updated by ktsj (Kazuki Tsujimoto) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59956.


vm.c: fix `cfp consistency error' which occurs
when raising exception in bmethod call event

  • vm.c (invoke_bmethod): set FINISH flag just before calling vm_exec. [ruby-dev:50162] [Bug #13705]

Updated by nagachika (Tomoyuki Chikanaga) about 1 year ago

  • Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r62651 merged revision(s) 59956.

Updated by usa (Usaku NAKAMURA) about 1 year ago

  • Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: DONE to 2.2: WONTFIX, 2.3: DONE, 2.4: DONE

ruby_2_3 r62815 merged revision(s) 59956.

Also available in: Atom PDF