diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-22 03:40:57 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-22 03:40:57 +0000 |
commit | 77061811ee6b618d1efd8a2ca66aec82d9077f33 (patch) | |
tree | dba0a9b6e8e3a370a436dca9c850123185eb1b81 /array.c | |
parent | db440bc6f04e7e4e4c2986a5ef17b698735e7899 (diff) | |
download | ruby-77061811ee6b618d1efd8a2ca66aec82d9077f33.tar.gz ruby-77061811ee6b618d1efd8a2ca66aec82d9077f33.tar.xz ruby-77061811ee6b618d1efd8a2ca66aec82d9077f33.zip |
* array.c (flatten): check if reentered. [ruby-dev:34798]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -2831,8 +2831,8 @@ flatten(VALUE ary, int level, int *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; @@ -2841,6 +2841,9 @@ flatten(VALUE ary, int level, int *modified) while (i < RARRAY_LEN(ary)) { elt = RARRAY_PTR(ary)[i++]; tmp = rb_check_array_type(elt); + if (RBASIC(result)->klass) { + rb_raise(rb_eRuntimeError, "flatten reentered"); + } if (NIL_P(tmp) || (level >= 0 && RARRAY_LEN(stack) / 2 >= level)) { rb_ary_push(result, elt); } @@ -2870,6 +2873,7 @@ flatten(VALUE ary, int level, int *modified) st_free_table(memo); + RBASIC(result)->klass = rb_class_of(ary); return result; } |