Project

General

Profile

Actions

Bug #9105

closed

callcc による不整合(例:Hash)

Added by tarui (Masaya Tarui) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 2.1.0dev (2013-11-11 trunk 43647) [x86_64-linux]
[ruby-dev:47803]

Description

=begin
以下のコードを実行すると、
equire 'continuation'
h = {1=>2,3=>4}
c = nil
f = false
h.each { callcc {|c2| c = c2 } }
unless f
f = true
c.call
end
h.each {|i| h.delete(1); p i}

以下のような結果になります。

[1, 2]
[false, false]
test.rb:10:in each': hash modified during iteration (RuntimeError) from test.rb:10:in '

[false, false]自体はst_foreach_checkで全く機能していない
/* call func with error notice */
retval = (*func)(0, 0, arg, 1);
を消せばいいのですが、
RuntimeErrorが発生するのはcallccによりhash_foreach_ensureの実行が2重に行われて、
RHASH_ITER_LEV(hash)の管理が破綻してしまっている為です。

他の所でも容易に起こりうると思うのですが、未調査です。
&そもそもどう対処すべきでしょう?

=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #14472: `File::open` closes the file too early when used with callccRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0