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

ruby-changes:32666

From: usa <ko1@a...>
Date: Wed, 29 Jan 2014 14:39:04 +0900 (JST)
Subject: [ruby-changes:32666] usa:r44745 (ruby_1_9_3): merge revision(s) 39722, 43929: [Backport #9178]

usa	2014-01-29 14:38:58 +0900 (Wed, 29 Jan 2014)

  New Revision: 44745

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

  Log:
    merge revision(s) 39722,43929: [Backport #9178]
    
    * enumerator.c (enumerator_with_index): try to convert given offset to
      integer. fix bug introduced in r39594.
    
    * enumerator.c (enumerator_with_index): should not store local variable
      address to memoise the arguments.  it is invalidated after the return.
      [ruby-core:58692] [Bug #9178]

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/common.mk
    branches/ruby_1_9_3/enumerator.c
    branches/ruby_1_9_3/node.h
    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 44744)
+++ ruby_1_9_3/ChangeLog	(revision 44745)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Wed Jan 29 14:26:10 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* enumerator.c (enumerator_with_index): should not store local variable
+	  address to memoise the arguments.  it is invalidated after the return.
+	  [ruby-core:58692] [Bug #9178]
+
+Wed Jan 29 14:26:10 2014  NARUSE, Yui  <naruse@r...>
+
+	* enumerator.c (enumerator_with_index): try to convert given offset to
+	  integer. fix bug introduced in r39594.
+
 Wed Jan 29 14:20:11 2014  Eric Hodel  <drbrain@s...>
 
 	* enumerator.c (enumerator_with_index):  Restore handling of a nil memo
Index: ruby_1_9_3/enumerator.c
===================================================================
--- ruby_1_9_3/enumerator.c	(revision 44744)
+++ ruby_1_9_3/enumerator.c	(revision 44745)
@@ -13,6 +13,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/enumerator.c#L13
 ************************************************/
 
 #include "ruby/ruby.h"
+#include "node.h"
 
 /*
  * Document-class: Enumerator
@@ -368,9 +369,9 @@ enumerator_each(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/enumerator.c#L369
 static VALUE
 enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
 {
-    VALUE *memo = (VALUE *)m;
-    VALUE idx = *memo;
-    *memo = rb_int_succ(idx);
+    NODE *memo = (NODE *)m;
+    VALUE idx = memo->u1.value;
+    memo->u1.value = rb_int_succ(idx);
 
     if (argc <= 1)
 	return rb_yield_values(2, val, idx);
@@ -401,7 +402,7 @@ enumerator_with_index(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/enumerator.c#L402
 	memo = INT2FIX(0);
     else
 	memo = rb_to_int(memo);
-    return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
+    return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
 }
 
 /*
Index: ruby_1_9_3/common.mk
===================================================================
--- ruby_1_9_3/common.mk	(revision 44744)
+++ ruby_1_9_3/common.mk	(revision 44745)
@@ -619,7 +619,7 @@ encoding.$(OBJEXT): {$(VPATH)}encoding.c https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/common.mk#L619
   {$(VPATH)}internal.h
 enum.$(OBJEXT): {$(VPATH)}enum.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h \
   {$(VPATH)}util.h $(ID_H_INCLUDES)
-enumerator.$(OBJEXT): {$(VPATH)}enumerator.c $(RUBY_H_INCLUDES)
+enumerator.$(OBJEXT): {$(VPATH)}enumerator.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h
 error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}known_errors.inc \
   $(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) $(ENCODING_H_INCLUDES) \
   {$(VPATH)}debug.h \
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 44744)
+++ ruby_1_9_3/version.h	(revision 44745)
@@ -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 499
+#define RUBY_PATCHLEVEL 500
 
 #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 44744)
+++ ruby_1_9_3/test/ruby/test_enumerator.rb	(revision 44745)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_enumerator.rb#L1
 require 'test/unit'
+require_relative "envutil"
 
 class TestEnumerator < Test::Unit::TestCase
   def setup
@@ -105,6 +106,28 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_enumerator.rb#L106
     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_in_out_err([], <<-"end;", ["Enumerator", "[false, [1]]"], [], bug9178)
+    bug = "#{bug9178}"
+    e = [1].to_enum(:chunk).with_index {|c,i| i == 5}
+    puts e.class
+    p e.to_a[0]
+    end;
+  end
+
   def test_with_object
     obj = [0, 1]
     ret = (1..10).each.with_object(obj) {|i, memo|
Index: ruby_1_9_3/node.h
===================================================================
--- ruby_1_9_3/node.h	(revision 44744)
+++ ruby_1_9_3/node.h	(revision 44745)
@@ -447,6 +447,7 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/node.h#L447
 #define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
 #define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
 #define NEW_OPTBLOCK(a) NEW_NODE(NODE_OPTBLOCK,a,0,0)
+#define NEW_MEMO(a,b,c) NEW_NODE(NODE_MEMO,a,b,c)
 
 #if defined __GNUC__ && __GNUC__ >= 4
 #pragma GCC visibility push(default)

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39722,43929


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

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