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

ruby-changes:44038

From: ktsj <ko1@a...>
Date: Thu, 8 Sep 2016 17:56:41 +0900 (JST)
Subject: [ruby-changes:44038] ktsj:r56111 (trunk): * array.c (flatten): use rb_obj_class instead of rb_class_of

ktsj	2016-09-08 17:56:30 +0900 (Thu, 08 Sep 2016)

  New Revision: 56111

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56111

  Log:
    * array.c (flatten): use rb_obj_class instead of rb_class_of
      because rb_class_of may return a singleton class.
      [ruby-dev:49781] [Bug #12738]

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/test/ruby/test_array.rb
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 56110)
+++ test/ruby/test_array.rb	(revision 56111)
@@ -813,6 +813,15 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L813
     assert_nothing_raised(RuntimeError, bug10748) {a.flatten(1)}
   end
 
+  def test_flattern_singleton_class
+    bug12738 = '[ruby-dev:49781] [Bug #12738]'
+    a = [[0]]
+    class << a
+      def m; end
+    end
+    assert_raise(NoMethodError, bug12738) { a.flatten.m }
+  end
+
   def test_flatten!
     a1 = @cls[ 1, 2, 3]
     a2 = @cls[ 5, 6 ]
@@ -850,6 +859,15 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L859
     assert_nothing_raised(RuntimeError, bug10748) {a.flatten!(1)}
   end
 
+  def test_flattern_singleton_class!
+    bug12738 = '[ruby-dev:49781] [Bug #12738]'
+    a = [[0]]
+    class << a
+      def m; end
+    end
+    assert_nothing_raised(NameError, bug12738) { a.flatten!.m }
+  end
+
   def test_flatten_with_callcc
     need_continuation
     o = Object.new
Index: array.c
===================================================================
--- array.c	(revision 56110)
+++ array.c	(revision 56111)
@@ -4583,7 +4583,7 @@ flatten(VALUE ary, int level, int *modif https://github.com/ruby/ruby/blob/trunk/array.c#L4583
 
     st_free_table(memo);
 
-    RBASIC_SET_CLASS(result, rb_class_of(ary));
+    RBASIC_SET_CLASS(result, rb_obj_class(ary));
     return result;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56110)
+++ ChangeLog	(revision 56111)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep  8 17:47:18 2016  Kazuki Tsujimoto  <kazuki@c...>
+
+	* array.c (flatten): use rb_obj_class instead of rb_class_of
+	  because rb_class_of may return a singleton class.
+	  [ruby-dev:49781] [Bug #12738]
+
 Thu Sep  8 17:40:15 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* tool/rbinstall.rb (gem): use the bindir of each gemspec instead

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

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