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

ruby-changes:46090

From: nagachika <ko1@a...>
Date: Tue, 28 Mar 2017 00:38:05 +0900 (JST)
Subject: [ruby-changes:46090] nagachika:r58161 (ruby_2_3): merge revision(s) 58077: [Backport #13358]

nagachika	2017-03-28 00:37:55 +0900 (Tue, 28 Mar 2017)

  New Revision: 58161

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

  Log:
    merge revision(s) 58077: [Backport #13358]
    
    ostruct.rb: fix OpenStruct.allocate
    
    * lib/ostruct.rb (OpenStruct.allocate): initialize an instance
      variable directly, without calling `intialize` method which may
      be overridden in a subclass.  [ruby-core:80292] [Bug #13358]

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/lib/ostruct.rb
    branches/ruby_2_3/test/ostruct/test_ostruct.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 58160)
+++ ruby_2_3/version.h	(revision 58161)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.3"
 #define RUBY_RELEASE_DATE "2017-03-28"
-#define RUBY_PATCHLEVEL 270
+#define RUBY_PATCHLEVEL 271
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_3/lib/ostruct.rb
===================================================================
--- ruby_2_3/lib/ostruct.rb	(revision 58160)
+++ ruby_2_3/lib/ostruct.rb	(revision 58161)
@@ -73,7 +73,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/ostruct.rb#L73
 class OpenStruct
   # :nodoc:
   class << self
-    alias allocate new
+    def allocate
+      (x = super).instance_variable_set(:@table, {})
+      x
+    end
   end
 
   #
Index: ruby_2_3/test/ostruct/test_ostruct.rb
===================================================================
--- ruby_2_3/test/ostruct/test_ostruct.rb	(revision 58160)
+++ ruby_2_3/test/ostruct/test_ostruct.rb	(revision 58161)
@@ -181,4 +181,13 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ostruct/test_ostruct.rb#L181
     os.foo = 44
     assert_equal(43, os.foo)
   end
+
+  def test_allocate_subclass
+    bug = '[ruby-core:80292] [Bug #13358] allocate should not call initialize'
+    c = Class.new(OpenStruct) {
+      def initialize(x,y={})super(y);end
+    }
+    os = assert_nothing_raised(ArgumentError, bug) {c.allocate}
+    assert_instance_of(c, os)
+  end
 end

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r58077


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

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