* 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:
parent
7cf6ecd9de
commit
d0a98a0e90
3
array.c
3
array.c
@ -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);
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user