ruby-changes:31881
From: nagachika <ko1@a...>
Date: Mon, 2 Dec 2013 23:29:47 +0900 (JST)
Subject: [ruby-changes:31881] nagachika:r43960 (ruby_2_0_0): merge revision(s) 39594, 39596: [Backport #8010]
nagachika 2013-12-02 23:29:37 +0900 (Mon, 02 Dec 2013) New Revision: 43960 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43960 Log: merge revision(s) 39594,39596: [Backport #8010] * enumerator.c (enumerator_with_index_i): allow Bignum as offset, to get rid of conversion exception and integer overflow. [ruby-dev:47131] [Bug #8010] * enumerator.c (enumerator_with_index): Restore handling of a nil memo from r39594. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/enumerator.c branches/ruby_2_0_0/internal.h branches/ruby_2_0_0/numeric.c branches/ruby_2_0_0/test/ruby/test_enumerator.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 43959) +++ ruby_2_0_0/ChangeLog (revision 43960) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Mon Dec 2 23:16:50 2013 Eric Hodel <drbrain@s...> + + * enumerator.c (enumerator_with_index): Restore handling of a nil memo + from r39594. + Mon Dec 2 22:53:05 2013 Nobuyoshi Nakada <nobu@r...> * file.c (rb_readlink): fix buffer overflow on a long symlink. since Index: ruby_2_0_0/enumerator.c =================================================================== --- ruby_2_0_0/enumerator.c (revision 43959) +++ ruby_2_0_0/enumerator.c (revision 43960) @@ -460,11 +460,9 @@ enumerator_each(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/enumerator.c#L460 static VALUE enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv) { - VALUE idx; VALUE *memo = (VALUE *)m; - - idx = INT2FIX(*memo); - ++*memo; + VALUE idx = *memo; + *memo = rb_int_succ(idx); if (argc <= 1) return rb_yield_values(2, val, idx); @@ -494,7 +492,8 @@ enumerator_with_index(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/enumerator.c#L492 rb_scan_args(argc, argv, "01", &memo); RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size); - memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo); + if (NIL_P(memo)) + memo = INT2NUM(0); return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo); } Index: ruby_2_0_0/numeric.c =================================================================== --- ruby_2_0_0/numeric.c (revision 43959) +++ ruby_2_0_0/numeric.c (revision 43960) @@ -2383,8 +2383,8 @@ fix_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L2383 * (-1).next #=> 0 */ -static VALUE -int_succ(VALUE num) +VALUE +rb_int_succ(VALUE num) { if (FIXNUM_P(num)) { long i = FIX2LONG(num) + 1; @@ -2393,6 +2393,8 @@ int_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L2393 return rb_funcall(num, '+', 1, INT2FIX(1)); } +#define int_succ rb_int_succ + /* * call-seq: * int.pred -> integer @@ -2403,8 +2405,8 @@ int_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L2405 * (-1).pred #=> -2 */ -static VALUE -int_pred(VALUE num) +VALUE +rb_int_pred(VALUE num) { if (FIXNUM_P(num)) { long i = FIX2LONG(num) - 1; @@ -2413,6 +2415,8 @@ int_pred(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L2415 return rb_funcall(num, '-', 1, INT2FIX(1)); } +#define int_pred rb_int_pred + VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc) { Index: ruby_2_0_0/internal.h =================================================================== --- ruby_2_0_0/internal.h (revision 43959) +++ ruby_2_0_0/internal.h (revision 43960) @@ -178,6 +178,8 @@ VALUE num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/internal.h#L178 int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl); double ruby_float_mod(double x, double y); int rb_num_negative_p(VALUE); +VALUE rb_int_succ(VALUE num); +VALUE rb_int_pred(VALUE num); /* object.c */ VALUE rb_obj_equal(VALUE obj1, VALUE obj2); Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 43959) +++ ruby_2_0_0/version.h (revision 43960) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-12-02" -#define RUBY_PATCHLEVEL 355 +#define RUBY_PATCHLEVEL 356 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 12 Index: ruby_2_0_0/test/ruby/test_enumerator.rb =================================================================== --- ruby_2_0_0/test/ruby/test_enumerator.rb (revision 43959) +++ ruby_2_0_0/test/ruby/test_enumerator.rb (revision 43960) @@ -104,6 +104,14 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_enumerator.rb#L104 assert_equal([[1,5],[2,6],[3,7]], @obj.to_enum(:foo, 1, 2, 3).with_index(5).to_a) end + def test_with_index_large_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + s = 1 << (8*1.size-2) + assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + s <<= 1 + 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_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r39594,39596 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/