Bug #5832

意図しないブロック渡しが行われる

Added by Kazuki Tsujimoto over 3 years ago. Updated almost 3 years ago.

[ruby-dev:45071]
Status:Closed
Priority:Normal
Assignee:Kazuki Tsujimoto
ruby -v:ruby 2.0.0dev (2012-01-01 trunk 34167) [x86_64-linux] Backport:

Description

=begin
辻本です。

invoke_block_from_cの呼び出しの際に渡していたブロックが
VM loopから続けて呼び出される別のメソッドにも渡されてしまうケースがあります。

$ ./ruby -ve "
require 'pp'
require 'pathname'

class <<File
alias realpath_orig realpath

def realpath(args)
yield if block_given?
realpath_orig(
args)
end
end

pathname = Pathname.new('.')
Class.new do
define_method(:foo) {
pathname.realpath
}
end.new.foo { pp caller }
"
ruby 2.0.0dev (2012-01-01 trunk 34167) [x86_64-linux]
["-e:9:in realpath'",
"-e:17:in
realpath'",
"-e:17:in block (2 levels) in <main>'",
"-e:19:in
'"]

blockptrはフレームに積まれることになるので、
passed_blockに代入する行は単純に削除してしまって良いと思います。

diff --git a/vm.c b/vm.c
index 2f38eee..3ea190f 100644
--- a/vm.c
+++ b/vm.c
@@ -597,7 +597,6 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
iseq->local_size - arg_size);
ncfp->me = th->passed_me;
th->passed_me = 0;
- th->passed_block = blockptr;

if (cref) {
    th->cfp->dfp[-1] = (VALUE)cref;

=end

Associated revisions

Revision 36685
Added by Kazuki Tsujimoto almost 3 years ago

  • vm.c (invoke_block_from_c): fix unintentional block passing. [Bug #5832]

Revision 36685
Added by Kazuki Tsujimoto almost 3 years ago

  • vm.c (invoke_block_from_c): fix unintentional block passing. [Bug #5832]

History

#1 Updated by Koichi Sasada about 3 years ago

見落としていてすみません.

良さそうに見えるので,テストが通れば,テストを追加してコミット頂けませんか.

#2 Updated by Kazuki Tsujimoto almost 3 years ago

  • Assignee changed from Koichi Sasada to Kazuki Tsujimoto

レビューありがとうございました。
対応しておきます。

#3 Updated by Kazuki Tsujimoto almost 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r36685.
Kazuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm.c (invoke_block_from_c): fix unintentional block passing. [Bug #5832]

Also available in: Atom PDF