diff options
| author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-12 16:02:08 +0000 |
|---|---|---|
| committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-12 16:02:08 +0000 |
| commit | de13975790da4c6928c253e915444932a25fdb7f (patch) | |
| tree | cc829ae64576e5a9a1313070ffc3d57454ce6311 | |
| parent | c27bd84806454f4627d8957a87b6186da1aab089 (diff) | |
merge revision(s) 39722: [Backport #9178]
* enumerator.c (enumerator_with_index): try to convert given offset to
integer. fix bug introduced in r39594.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | enumerator.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_enumerator.rb | 12 | ||||
| -rw-r--r-- | version.h | 6 |
4 files changed, 23 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Fri Dec 13 00:23:01 2013 NARUSE, Yui <naruse@ruby-lang.org> + + * enumerator.c (enumerator_with_index): try to convert given offset to + integer. fix bug introduced in r39594. + Mon Dec 2 23:31:00 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> * enumerator.c (enumerator_with_index): should not store local variable diff --git a/enumerator.c b/enumerator.c index e20a612358..4ba0ac6f12 100644 --- a/enumerator.c +++ b/enumerator.c @@ -493,7 +493,9 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj) rb_scan_args(argc, argv, "01", &memo); RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size); if (NIL_P(memo)) - memo = INT2NUM(0); + memo = INT2FIX(0); + else + memo = rb_to_int(memo); return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0)); } diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 9e2502a965..b249a525a2 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -112,6 +112,18 @@ class TestEnumerator < Test::Unit::TestCase assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) end + def test_with_index_nonnum_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + s = Object.new + def s.to_int; 1 end + assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + end + + def test_with_index_string_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a } + end + def test_with_index_dangling_memo bug9178 = '[ruby-core:58692] [Bug #9178]' assert_separately([], <<-"end;") @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.0.0" -#define RUBY_RELEASE_DATE "2013-12-02" -#define RUBY_PATCHLEVEL 357 +#define RUBY_RELEASE_DATE "2013-12-13" +#define RUBY_PATCHLEVEL 358 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 2 +#define RUBY_RELEASE_DAY 13 #include "ruby/version.h" |
