ruby-changes:5032
From: nobu <ko1@a...>
Date: Thu, 22 May 2008 14:21:16 +0900 (JST)
Subject: [ruby-changes:5032] nobu - Ruby:r16525 (ruby_1_8, trunk): * array.c (flatten): check if reentered.
nobu 2008-05-22 14:20:59 +0900 (Thu, 22 May 2008)
New Revision: 16525
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/array.c
branches/ruby_1_8/test/ruby/test_array.rb
trunk/test/ruby/test_array.rb
Log:
* array.c (flatten): check if reentered. [ruby-dev:34798]
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16525&r2=16524&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/array.c?r1=16525&r2=16524&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/ruby/test_array.rb?r1=16525&r2=16524&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_array.rb?r1=16525&r2=16524&diff_format=u
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb (revision 16524)
+++ test/ruby/test_array.rb (revision 16525)
@@ -727,7 +727,7 @@
end
def test_flatten_with_callcc
- respond_to?(:callcc) or require 'continuation'
+ respond_to?(:callcc, true) or require 'continuation'
o = Object.new
def o.to_ary() callcc {|k| @cont = k; [1,2,3]} end
begin
@@ -1148,7 +1148,7 @@
end
def test_sort_with_callcc
- respond_to?(:callcc) or require 'continuation'
+ respond_to?(:callcc, true) or require 'continuation'
n = 1000
cont = nil
ary = (1..100).to_a
Index: ruby_1_8/array.c
===================================================================
--- ruby_1_8/array.c (revision 16524)
+++ ruby_1_8/array.c (revision 16525)
@@ -3107,8 +3107,8 @@
st_table *memo;
st_data_t id;
- stack = rb_ary_new();
- result = ary_new(rb_class_of(ary), RARRAY_LEN(ary));
+ stack = ary_new(0, ARY_DEFAULT_SIZE);
+ result = ary_new(0, RARRAY_LEN(ary));
memo = st_init_numtable();
st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
*modified = 0;
@@ -3117,6 +3117,9 @@
while (i < RARRAY(ary)->len) {
elt = RARRAY(ary)->ptr[i++];
tmp = rb_check_array_type(elt);
+ if (RBASIC(result)->klass) {
+ rb_raise(rb_eRuntimeError, "flatten reentered");
+ }
if (NIL_P(tmp) || (level >= 0 && RARRAY(stack)->len / 2 >= level)) {
rb_ary_push(result, elt);
}
@@ -3146,6 +3149,7 @@
st_free_table(memo);
+ RBASIC(result)->klass = rb_class_of(ary);
return result;
}
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16524)
+++ ruby_1_8/ChangeLog (revision 16525)
@@ -1,3 +1,7 @@
+Thu May 22 14:20:54 2008 Nobuyoshi Nakada <nobu@r...>
+
+ * array.c (flatten): check if reentered. [ruby-dev:34798]
+
Thu May 22 08:28:49 2008 Yukihiro Matsumoto <matz@r...>
* array.c (flatten): free memo hash table before raising exception.
Index: ruby_1_8/test/ruby/test_array.rb
===================================================================
--- ruby_1_8/test/ruby/test_array.rb (revision 16524)
+++ ruby_1_8/test/ruby/test_array.rb (revision 16525)
@@ -717,6 +717,20 @@
@cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten)
end
+ def test_flatten_with_callcc
+ respond_to?(:callcc, true) or require 'continuation'
+ o = Object.new
+ def o.to_ary() callcc {|k| @cont = k; [1,2,3]} end
+ begin
+ assert_equal([10, 20, 1, 2, 3, 30, 1, 2, 3, 40], [10, 20, o, 30, o, 40].flatten)
+ rescue => e
+ else
+ o.instance_eval {@cont}.call
+ end
+ assert_instance_of(RuntimeError, e, '[ruby-dev:34798]')
+ assert_match(/reentered/, e.message, '[ruby-dev:34798]')
+ end
+
def test_hash
a1 = @cls[ 'cat', 'dog' ]
a2 = @cls[ 'cat', 'dog' ]
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/