mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
enum.c: Fixnum only
* enum.c (limit_by_enum_size, enum_size_over_p): check only against Fixnum size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
98273af3f7
commit
fe6cf485e6
2 changed files with 17 additions and 5 deletions
10
enum.c
10
enum.c
|
@ -319,17 +319,17 @@ limit_by_enum_size(VALUE obj, long n)
|
||||||
{
|
{
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
VALUE size = rb_check_funcall(obj, id_size, 0, 0);
|
VALUE size = rb_check_funcall(obj, id_size, 0, 0);
|
||||||
if (size == Qundef) return n;
|
if (!FIXNUM_P(size)) return n;
|
||||||
limit = NUM2ULONG(size);
|
limit = FIX2ULONG(size);
|
||||||
return ((unsigned long)n > limit) ? limit : n;
|
return ((unsigned long)n > limit) ? (long)limit : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
enum_size_over_p(VALUE obj, long n)
|
enum_size_over_p(VALUE obj, long n)
|
||||||
{
|
{
|
||||||
VALUE size = rb_check_funcall(obj, id_size, 0, 0);
|
VALUE size = rb_check_funcall(obj, id_size, 0, 0);
|
||||||
if (size == Qundef) return 0;
|
if (!FIXNUM_P(size)) return 0;
|
||||||
return ((unsigned long)n > NUM2ULONG(size));
|
return ((unsigned long)n > FIX2ULONG(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -483,6 +483,18 @@ EOS
|
||||||
assert_equal Enumerator::Lazy, [].lazy.slice_when{}.class, bug7507
|
assert_equal Enumerator::Lazy, [].lazy.slice_when{}.class, bug7507
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_each_cons_limit
|
||||||
|
n = 1 << 120
|
||||||
|
assert_equal([1, 2], (1..n).lazy.each_cons(2).first)
|
||||||
|
assert_equal([[1, 2], [2, 3]], (1..n).lazy.each_cons(2).first(2))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_each_slice_limit
|
||||||
|
n = 1 << 120
|
||||||
|
assert_equal([1, 2], (1..n).lazy.each_slice(2).first)
|
||||||
|
assert_equal([[1, 2], [3, 4]], (1..n).lazy.each_slice(2).first(2))
|
||||||
|
end
|
||||||
|
|
||||||
def test_no_warnings
|
def test_no_warnings
|
||||||
le = (1..3).lazy
|
le = (1..3).lazy
|
||||||
assert_warning("") {le.zip([4,5,6]).force}
|
assert_warning("") {le.zip([4,5,6]).force}
|
||||||
|
|
Loading…
Add table
Reference in a new issue