mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 10:03:59 +02:00
merge revision(s) 42040,42041,42047: [Backport #8654]
* array.c (rb_ary_count): iterate items appropriately. [Bug #8654] * array.c (rb_ary_count): check length to avoid SEGV while iterating. Remove other pointer loop when arg is given. * test/ruby/test_array.rb (test_count): add test for bug. [ruby-core:56072] [Bug #8654] * test/ruby/test_array.rb (test_count): add a test case for #count with an argument. See Bug #8654. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f4811c7e2b
commit
0a57e6c975
4 changed files with 49 additions and 8 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
||||||
|
Thu Oct 10 00:58:39 2013 Benoit Daloze <eregontp@gmail.com>
|
||||||
|
|
||||||
|
* test/ruby/test_array.rb (test_count): add a test case for #count
|
||||||
|
with an argument. See Bug #8654.
|
||||||
|
|
||||||
|
Thu Oct 10 00:58:39 2013 Benoit Daloze <eregontp@gmail.com>
|
||||||
|
|
||||||
|
* array.c (rb_ary_count): check length to avoid SEGV
|
||||||
|
while iterating. Remove other pointer loop when arg is given.
|
||||||
|
|
||||||
|
* test/ruby/test_array.rb (test_count): add test for bug.
|
||||||
|
[ruby-core:56072] [Bug #8654]
|
||||||
|
|
||||||
|
Thu Oct 10 00:58:39 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||||
|
|
||||||
|
* array.c (rb_ary_count): iterate items appropriately.
|
||||||
|
[Bug #8654]
|
||||||
|
|
||||||
Thu Oct 10 00:44:28 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Oct 10 00:44:28 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* process.c (rb_fork_internal): remove cloexec setting on pipes
|
* process.c (rb_fork_internal): remove cloexec setting on pipes
|
||||||
|
|
15
array.c
15
array.c
|
@ -4113,27 +4113,28 @@ rb_ary_compact(VALUE ary)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_ary_count(int argc, VALUE *argv, VALUE ary)
|
rb_ary_count(int argc, VALUE *argv, VALUE ary)
|
||||||
{
|
{
|
||||||
long n = 0;
|
long i, n = 0;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
VALUE *p, *pend;
|
VALUE v;
|
||||||
|
|
||||||
if (!rb_block_given_p())
|
if (!rb_block_given_p())
|
||||||
return LONG2NUM(RARRAY_LEN(ary));
|
return LONG2NUM(RARRAY_LEN(ary));
|
||||||
|
|
||||||
for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||||
if (RTEST(rb_yield(*p))) n++;
|
v = RARRAY_PTR(ary)[i];
|
||||||
|
if (RTEST(rb_yield(v))) n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE obj, *p, *pend;
|
VALUE obj;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "1", &obj);
|
rb_scan_args(argc, argv, "1", &obj);
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
rb_warn("given block not used");
|
rb_warn("given block not used");
|
||||||
}
|
}
|
||||||
for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
||||||
if (rb_equal(*p, obj)) n++;
|
if (rb_equal(RARRAY_PTR(ary)[i], obj)) n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -576,6 +576,28 @@ class TestArray < Test::Unit::TestCase
|
||||||
assert_equal(3, a.count {|x| x % 2 == 1 })
|
assert_equal(3, a.count {|x| x % 2 == 1 })
|
||||||
assert_equal(2, a.count(1) {|x| x % 2 == 1 })
|
assert_equal(2, a.count(1) {|x| x % 2 == 1 })
|
||||||
assert_raise(ArgumentError) { a.count(0, 1) }
|
assert_raise(ArgumentError) { a.count(0, 1) }
|
||||||
|
|
||||||
|
bug8654 = '[ruby-core:56072]'
|
||||||
|
assert_in_out_err [], <<-EOS, ["0"], [], bug8654
|
||||||
|
a1 = []
|
||||||
|
a2 = Array.new(100) { |i| i }
|
||||||
|
r = a2.count do |i|
|
||||||
|
p i
|
||||||
|
a2.replace(a1) if i == 0
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
assert_in_out_err [], <<-EOS, ["[]", "0"], [], bug8654
|
||||||
|
ARY = Array.new(100) { |i| i }
|
||||||
|
class Fixnum
|
||||||
|
def == other
|
||||||
|
ARY.replace([]) if self.equal?(0)
|
||||||
|
p ARY
|
||||||
|
self.equal?(other)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
p ARY.count(42)
|
||||||
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete
|
def test_delete
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.0.0"
|
#define RUBY_VERSION "2.0.0"
|
||||||
#define RUBY_RELEASE_DATE "2013-10-10"
|
#define RUBY_RELEASE_DATE "2013-10-10"
|
||||||
#define RUBY_PATCHLEVEL 331
|
#define RUBY_PATCHLEVEL 332
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2013
|
#define RUBY_RELEASE_YEAR 2013
|
||||||
#define RUBY_RELEASE_MONTH 10
|
#define RUBY_RELEASE_MONTH 10
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue