* array.c (rb_ary_product): Test for reentry

* test/ruby/test_array.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2010-04-02 22:25:49 +00:00
parent 7cf6ecd9de
commit d0a98a0e90
2 changed files with 20 additions and 0 deletions

View File

@ -4117,6 +4117,9 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
/* put it on the result array */ /* put it on the result array */
if(NIL_P(result)) { if(NIL_P(result)) {
rb_yield(subarray); rb_yield(subarray);
if (RBASIC(t0)->klass) {
rb_raise(rb_eRuntimeError, "product reentered");
}
} }
else { else {
rb_ary_push(result, subarray); rb_ary_push(result, subarray);

View File

@ -780,6 +780,23 @@ class TestArray < Test::Unit::TestCase
assert_match(/reentered/, e.message) assert_match(/reentered/, e.message)
end end
def test_product_with_callcc
respond_to?(:callcc, true) or require 'continuation'
n = 1000
cont = nil
ary = [1,2,3]
begin
ary.product {
callcc {|k| cont = k} unless cont
}
rescue => e
end
n -= 1
cont.call if 0 < n
assert_instance_of(RuntimeError, e)
assert_match(/reentered/, e.message)
end
def test_combination_with_callcc def test_combination_with_callcc
respond_to?(:callcc, true) or require 'continuation' respond_to?(:callcc, true) or require 'continuation'
n = 1000 n = 1000