[前][次][番号順一覧][スレッド一覧]

ruby-changes:32665

From: usa <ko1@a...>
Date: Wed, 29 Jan 2014 14:24:36 +0900 (JST)
Subject: [ruby-changes:32665] usa:r44744 (ruby_1_9_3): merge revision(s) 39594, 39596: [Backport #8010]

usa	2014-01-29 14:24:28 +0900 (Wed, 29 Jan 2014)

  New Revision: 44744

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44744

  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_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/enumerator.c
    branches/ruby_1_9_3/internal.h
    branches/ruby_1_9_3/numeric.c
    branches/ruby_1_9_3/test/ruby/test_enumerator.rb
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 44743)
+++ ruby_1_9_3/ChangeLog	(revision 44744)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Wed Jan 29 14:20:11 2014  Eric Hodel  <drbrain@s...>
+
+	* enumerator.c (enumerator_with_index):  Restore handling of a nil memo
+	  from r39594.
+
 Wed Jan 29 14:08:54 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/win32.h (rb_infinity_float): suppress overflow in
Index: ruby_1_9_3/enumerator.c
===================================================================
--- ruby_1_9_3/enumerator.c	(revision 44743)
+++ ruby_1_9_3/enumerator.c	(revision 44744)
@@ -368,11 +368,9 @@ enumerator_each(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/enumerator.c#L368
 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);
@@ -399,7 +397,10 @@ enumerator_with_index(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/enumerator.c#L397
 
     rb_scan_args(argc, argv, "01", &memo);
     RETURN_ENUMERATOR(obj, argc, argv);
-    memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo);
+    if (NIL_P(memo))
+	memo = INT2FIX(0);
+    else
+	memo = rb_to_int(memo);
     return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
 }
 
Index: ruby_1_9_3/numeric.c
===================================================================
--- ruby_1_9_3/numeric.c	(revision 44743)
+++ ruby_1_9_3/numeric.c	(revision 44744)
@@ -2173,8 +2173,8 @@ fix_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/numeric.c#L2173
  *     (-1).next   #=> 0
  */
 
-static VALUE
-int_succ(VALUE num)
+VALUE
+rb_int_succ(VALUE num)
 {
     if (FIXNUM_P(num)) {
 	long i = FIX2LONG(num) + 1;
@@ -2183,6 +2183,8 @@ int_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/numeric.c#L2183
     return rb_funcall(num, '+', 1, INT2FIX(1));
 }
 
+#define int_succ rb_int_succ
+
 /*
  *  call-seq:
  *     int.pred  ->  integer
@@ -2193,8 +2195,8 @@ int_succ(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/numeric.c#L2195
  *     (-1).pred   #=> -2
  */
 
-static VALUE
-int_pred(VALUE num)
+VALUE
+rb_int_pred(VALUE num)
 {
     if (FIXNUM_P(num)) {
 	long i = FIX2LONG(num) - 1;
@@ -2203,6 +2205,8 @@ int_pred(VALUE num) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/numeric.c#L2205
     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_1_9_3/internal.h
===================================================================
--- ruby_1_9_3/internal.h	(revision 44743)
+++ ruby_1_9_3/internal.h	(revision 44744)
@@ -138,6 +138,8 @@ void Init_newline(void); https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/internal.h#L138
 int rb_num_to_uint(VALUE val, unsigned int *ret);
 int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
 double ruby_float_mod(double x, double y);
+VALUE rb_int_succ(VALUE num);
+VALUE rb_int_pred(VALUE num);
 
 /* object.c */
 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 44743)
+++ ruby_1_9_3/version.h	(revision 44744)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 498
+#define RUBY_PATCHLEVEL 499
 
 #define RUBY_RELEASE_DATE "2014-01-29"
 #define RUBY_RELEASE_YEAR 2014
Index: ruby_1_9_3/test/ruby/test_enumerator.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_enumerator.rb	(revision 44743)
+++ ruby_1_9_3/test/ruby/test_enumerator.rb	(revision 44744)
@@ -97,6 +97,14 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_enumerator.rb#L97
     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_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39594,39596


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]