mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (ary_reject_bang): should not remove elements which are
not yielded. [Bug #2545] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b582f2a123
commit
6343e30c14
3 changed files with 20 additions and 23 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Jul 3 13:44:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (ary_reject_bang): should not remove elements which are
|
||||||
|
not yielded. [Bug #2545]
|
||||||
|
|
||||||
Sun Jul 3 06:10:26 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sun Jul 3 06:10:26 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* thread_pthread.c (get_stack): pthread_attr_getstack() doesn't
|
* thread_pthread.c (get_stack): pthread_attr_getstack() doesn't
|
||||||
|
|
34
array.c
34
array.c
|
@ -2567,42 +2567,34 @@ static VALUE
|
||||||
ary_reject(VALUE orig, VALUE result)
|
ary_reject(VALUE orig, VALUE result)
|
||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
int rejected = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < RARRAY_LEN(orig); i++) {
|
for (i = 0; i < RARRAY_LEN(orig); i++) {
|
||||||
VALUE v = RARRAY_PTR(orig)[i];
|
VALUE v = RARRAY_PTR(orig)[i];
|
||||||
if (!RTEST(rb_yield(v))) {
|
if (!RTEST(rb_yield(v))) {
|
||||||
rb_ary_push_1(result, v);
|
rb_ary_push_1(result, v);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
rejected = 1;
|
|
||||||
}
|
}
|
||||||
}
|
return result;
|
||||||
return rejected ? result : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
ary_protecting_reject(VALUE arg)
|
|
||||||
{
|
|
||||||
VALUE *args = (VALUE *)arg;
|
|
||||||
return ary_reject(args[0], args[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ary_reject_bang(VALUE ary)
|
ary_reject_bang(VALUE ary)
|
||||||
{
|
{
|
||||||
VALUE args[2];
|
long i;
|
||||||
int state = 0;
|
VALUE result = Qnil;
|
||||||
|
|
||||||
rb_ary_modify_check(ary);
|
rb_ary_modify_check(ary);
|
||||||
args[0] = ary;
|
for (i = 0; i < RARRAY_LEN(ary); ) {
|
||||||
args[1] = rb_ary_new();
|
VALUE v = RARRAY_PTR(ary)[i];
|
||||||
if (!rb_protect(ary_protecting_reject, (VALUE)args, &state)) {
|
if (RTEST(rb_yield(v))) {
|
||||||
return Qnil;
|
rb_ary_delete_at(ary, i);
|
||||||
|
result = ary;
|
||||||
}
|
}
|
||||||
rb_ary_replace(ary, args[1]);
|
else {
|
||||||
if (state) rb_jump_tag(state);
|
i++;
|
||||||
return ary;
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -611,7 +611,7 @@ class TestArray < Test::Unit::TestCase
|
||||||
bug2545 = '[ruby-core:27366]'
|
bug2545 = '[ruby-core:27366]'
|
||||||
a = @cls[ 5, 6, 7, 8, 9, 10 ]
|
a = @cls[ 5, 6, 7, 8, 9, 10 ]
|
||||||
assert_equal(9, a.delete_if {|i| break i if i > 8; i < 7})
|
assert_equal(9, a.delete_if {|i| break i if i > 8; i < 7})
|
||||||
assert_equal(@cls[7, 8], a, bug2545)
|
assert_equal(@cls[7, 8, 9, 10], a, bug2545)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
|
@ -1096,7 +1096,7 @@ class TestArray < Test::Unit::TestCase
|
||||||
bug2545 = '[ruby-core:27366]'
|
bug2545 = '[ruby-core:27366]'
|
||||||
a = @cls[ 5, 6, 7, 8, 9, 10 ]
|
a = @cls[ 5, 6, 7, 8, 9, 10 ]
|
||||||
assert_equal(9, a.reject! {|i| break i if i > 8; i < 7})
|
assert_equal(9, a.reject! {|i| break i if i > 8; i < 7})
|
||||||
assert_equal(@cls[7, 8], a, bug2545)
|
assert_equal(@cls[7, 8, 9, 10], a, bug2545)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_replace
|
def test_replace
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue