yarv-dev:741
From: Minero Aoki <aamine loveruby.net>
Date: Wed, 28 Dec 2005 18:36:53 +0900 (JST)
Subject: [yarv-dev:741] open> Hash + Wrapper + Passing Method as block parameter
青木です。
以下のプログラムで SEGV します。
~/c/yarv % cat and-and-method.rb
class BlockWrapper
def initialize(block)
@block = block
end
def call
@block.call
end
end
def register(&block)
# h[BlockWrapper.new(block)] = 1
@h[1] = BlockWrapper.new(block)
end
def m
puts 'THRU'
end
def call
@h[1].call
end
@h = {}
GC.always
register(&method(:m))
GC.start
#call
~/c/yarv % ./miniruby -v and-and-method.rb
ruby 1.9.0 (2005-11-18) [x86_64-linux]
YARVCore 0.3.3 (rev: 336) [opts: ]
zsh: 25219 segmentation fault (core dumped) ./miniruby -v and-and-method.rb
なお、以下の条件がすべて揃わないと落ちません。
* Method オブジェクトを & で渡す
* それをさらに &block で受ける
* その block をラッパーオブジェクトでラップしてハッシュに入れる
* そのあいだ GC.always しておく
* 最後に GC.start
make ext で落ちる問題と同じく iseq が関係しているようです。
また、call を書くか書かないかどうかだけでも落ちかたが変わり、
そのときは次のようにスタックダンプが表示されます。
~/c/yarv % ./miniruby and-and-method.rb
DBG> : "and-and-method.rb:17:in `puts'"
DBG> : "and-and-method.rb:17:in `m'"
DBG> : "and-and-method.rb:7:in `call'"
DBG> : "and-and-method.rb:7:in `call'"
DBG> : "and-and-method.rb:21:in `call'"
DBG> : "and-and-method.rb:28:in `<main>'"
-- stack frame ------------
0x2a95ee2010 (0000): 00000001
0x2a95ee2018 (0001): 00000004
0x2a95ee2020 (0002): 00000001
0x2a95ee2028 (0003): 2a95ede408
0x2a95ee2030 (0004): 00000004
0x2a95ee2038 (0005): 00000001
0x2a95ee2040 (0006): 2a95eb0738
0x2a95ee2048 (0007): 00000004
0x2a95ee2050 (0008): 00000001
0x2a95ee2058 (0009): 2a95eb0760
0x2a95ee2060 (0010): 00000001
0x2a95ee2068 (0011): 00672aa1
0x2a95ee2070 (0012): 00000001
0x2a95ee2078 (0013): 00000004
0x2a95ee2080 (0014): 00000001
0x2a95ee2088 (0015): 2a95ede408
0x2a95ee2090 (0016): 2a95eb06c0
0x2a95ee2098 (0017): 00000001
0x2a95ee20a0 (0018): 00000001 <- lfp <- dfp
-- control frame ----------
c:0011 p:-001 s:0019 b:0019 l:0018 d:0018 CFUNC i:write s: -
c:0010 p:-001 s:0018 b:0018 l:0017 d:0017 CFUNC i:puts s: -
c:0009 p:0009 s:0015 b:0015 l:0014 d:0014 METHOD i:m s: -
c:0008 p:-001 s:0012 b:0013 l:0012 d:0012 FINISH i:- s: -
c:0007 p:-001 s:0012 b:0012 l:-054 d:0011 IFUNC i:- s: -
c:0006 p:-001 s:0011 b:0011 l:0010 d:0010 CFUNC i:call s: -
c:0005 p:0008 s:0009 b:0009 l:0008 d:0008 METHOD i:call s: -
c:0004 p:0016 s:0006 b:0006 l:0005 d:0005 METHOD i:call s: -
c:0003 p:0072 s:0003 b:0003 l:0002 d:0002 TOP i:<main> s: -
c:0002 p:-001 s:0001 b:0001 l:0000 d:0000 FINISH i:- s: -
c:0001 p:-001 s:0000 b:-001 l:0000 d:0000 ------ i:- s: -
---------------------------
[BUG] Segmentation fault
ruby 1.9.0 (2005-11-18) [x86_64-linux]
zsh: 25225 abort (core dumped) ./miniruby and-and-method.rb
--
青木峰郎
--
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml
-> 741 2005-12-28 18:36 [aamine loveruby.net ] open> Hash + Wrapper + Passing Method as block parameter 749 2005-12-29 03:10 ┗[aamine loveruby.net ] close> Re: Hash + Wrapper + Passing Method as block parameter