summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-22 05:20:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-22 05:20:59 +0000
commit0ba197f08fa974727e083796d52495a307dbd880 (patch)
tree09fc1ad6548a2a68e8fa1e9d028541dc713d1484 /array.c
parenteb995e112023e7485464d0e1ce70783eaf673e8b (diff)
* array.c (flatten): check if reentered. [ruby-dev:34798]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/array.c b/array.c
index e3d92bac2d..a0b608c21d 100644
--- a/array.c
+++ b/array.c
@@ -3107,8 +3107,8 @@ flatten(ary, level, modified)
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 @@ flatten(ary, level, modified)
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 @@ flatten(ary, level, modified)
st_free_table(memo);
+ RBASIC(result)->klass = rb_class_of(ary);
return result;
}