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

ruby-changes:30181

From: knu <ko1@a...>
Date: Mon, 29 Jul 2013 21:06:53 +0900 (JST)
Subject: [ruby-changes:30181] knu:r42233 (trunk): Add a frozenness check to Enumerator#initialize.

knu	2013-07-29 21:06:39 +0900 (Mon, 29 Jul 2013)

  New Revision: 42233

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

  Log:
    Add a frozenness check to Enumerator#initialize.
    
    * enumerator.c (enumerator_init): Add a frozenness check to
      prevent a frozen Enumerator object from being reinitialized with
      a different enumerable object.  This is the least we should do,
      and more fixes will follow. [Fixes GH-368] Patch by Kenichi
      Kamiya.

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c
    trunk/test/ruby/test_enumerator.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42232)
+++ ChangeLog	(revision 42233)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 29 20:53:24 2013  Akinori MUSHA  <knu@i...>
+
+	* enumerator.c (enumerator_init): Add a frozenness check to
+	  prevent a frozen Enumerator object from being reinitialized with
+	  a different enumerable object.  This is the least we should do,
+	  and more fixes will follow. [Fixes GH-368] Patch by Kenichi
+	  Kamiya.
+
 Mon Jul 29 20:14:24 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* hash.c (rb_hash_assoc): revert r42224. table->type->compare is
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 42232)
+++ enumerator.c	(revision 42233)
@@ -270,6 +270,7 @@ enumerator_init(VALUE enum_obj, VALUE ob https://github.com/ruby/ruby/blob/trunk/enumerator.c#L270
 {
     struct enumerator *ptr;
 
+    rb_check_frozen(enum_obj);
     TypedData_Get_Struct(enum_obj, struct enumerator, &enumerator_data_type, ptr);
 
     if (!ptr) {
Index: test/ruby/test_enumerator.rb
===================================================================
--- test/ruby/test_enumerator.rb	(revision 42232)
+++ test/ruby/test_enumerator.rb	(revision 42233)
@@ -67,6 +67,16 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enumerator.rb#L67
     assert_match 'Enumerator.new without a block is deprecated', err
     assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3))
     assert_raise(ArgumentError) { Enumerator.new }
+
+    enum = @obj.to_enum
+    assert_raise(NoMethodError) { enum.each {} }
+    enum.freeze
+    assert_raise(RuntimeError) {
+      capture_io do
+        # warning: Enumerator.new without a block is deprecated; use Object#to_enum
+        enum.__send__(:initialize, @obj, :foo)
+      end
+    }
   end
 
   def test_initialize_copy

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

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