diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-28 08:18:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-28 08:18:42 +0000 |
commit | 98273af3f7d0ea445a18d39f1e359c74b0cfb045 () | |
tree | d6da61778ee977817e8a2eb28b92c7a8e2d48130 | |
parent | dbffdff1e7eaf77711b3638e7734d1597d32d016 (diff) |
enum.c: limit size
* enum.c (enum_each_slice, enum_each_cons): limit elements size by the enumerator size. suggested by Hans Mackowiak <hanmac AT gmx.de> at [ruby-core:68335] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | enum.c | 20 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 16 |
3 files changed, 42 insertions, 0 deletions
@@ -1,3 +1,9 @@ Sat Feb 28 15:44:20 2015 Nobuyoshi Nakada <[email protected]> * vm_dump.c (rb_vm_bugreport): get rid of making new strings @@ -314,6 +314,24 @@ enum_size(VALUE self, VALUE args, VALUE eobj) return (r == Qundef) ? Qnil : r; } /* * call-seq: * enum.find_all { |obj| block } -> array @@ -2187,6 +2205,7 @@ enum_each_slice(VALUE obj, VALUE n) if (size <= 0) rb_raise(rb_eArgError, "invalid slice size"); RETURN_SIZED_ENUMERATOR(obj, 1, &n, enum_each_slice_size); ary = rb_ary_new2(size); arity = rb_block_arity(); memo = NEW_MEMO(ary, dont_recycle_block_arg(arity), size); @@ -2264,6 +2283,7 @@ enum_each_cons(VALUE obj, VALUE n) if (size <= 0) rb_raise(rb_eArgError, "invalid size"); RETURN_SIZED_ENUMERATOR(obj, 1, &n, enum_each_cons_size); arity = rb_block_arity(); memo = NEW_MEMO(rb_ary_new2(size), dont_recycle_block_arg(arity), size); rb_block_call(obj, id_each, 0, 0, each_cons_i, (VALUE)memo); @@ -348,6 +348,14 @@ class TestEnumerable < Test::Unit::TestCase ary.clear (1..10).each_slice(3, &lambda {|a, *| ary << a}) assert_equal([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]], ary, bug9749) end def test_each_cons @@ -359,6 +367,14 @@ class TestEnumerable < Test::Unit::TestCase ary.clear (1..5).each_cons(3, &lambda {|a, *| ary << a}) assert_equal([[1, 2, 3], [2, 3, 4], [3, 4, 5]], ary, bug9749) end def test_zip |