* array.c: revert modify check during iteration.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-10-11 08:06:16 +00:00
parent 9681d8791b
commit 11674f4a3e
2 changed files with 13 additions and 26 deletions

View File

@ -14,11 +14,6 @@ Wed Oct 11 15:03:55 2006 Akinori MUSHA <knu@iDaemons.org>
recursive calls, but call initialize() when reset() is not
defined in a subclass.
Wed Oct 11 14:58:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_each): prohibit array modification during each
iteration. [ruby-core:09104]
Wed Oct 11 14:56:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/digest/sha1/sha1ossl.h: libssl 0.9.8c-3 defines no

34
array.c
View File

@ -1227,24 +1227,6 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
return ary;
}
VALUE
each_internal(VALUE ary)
{
long i;
for (i=0; i<RARRAY_LEN(ary); i++) {
rb_yield(RARRAY_PTR(ary)[i]);
}
return ary;
}
static VALUE
iter_unlock(VALUE ary)
{
FL_UNSET(ary, ARY_TMPLOCK);
return ary;
}
/*
* call-seq:
* array.each {|item| block } -> array
@ -1263,9 +1245,12 @@ iter_unlock(VALUE ary)
VALUE
rb_ary_each(VALUE ary)
{
long i;
RETURN_ENUMERATOR(ary, 0, 0);
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during each */
rb_ensure(each_internal, ary, iter_unlock, ary);
for (i=0; i<RARRAY_LEN(ary); i++) {
rb_yield(RARRAY_PTR(ary)[i]);
}
return ary;
}
@ -1638,6 +1623,13 @@ sort_internal(VALUE ary)
return ary;
}
static VALUE
sort_unlock(VALUE ary)
{
FL_UNSET(ary, ARY_TMPLOCK);
return ary;
}
/*
* call-seq:
* array.sort! -> array
@ -1660,7 +1652,7 @@ rb_ary_sort_bang(VALUE ary)
rb_ary_modify(ary);
if (RARRAY_LEN(ary) > 1) {
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
rb_ensure(sort_internal, ary, iter_unlock, ary);
rb_ensure(sort_internal, ary, sort_unlock, ary);
}
return ary;
}