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

ruby-changes:40960

From: normal <ko1@a...>
Date: Fri, 11 Dec 2015 18:15:31 +0900 (JST)
Subject: [ruby-changes:40960] normal:r53039 (trunk): insns.def (opt_case_dispatch): avoid converting Infinity

normal	2015-12-11 18:15:14 +0900 (Fri, 11 Dec 2015)

  New Revision: 53039

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

  Log:
    insns.def (opt_case_dispatch): avoid converting Infinity
    
    Infinity cannot be written as an optimizable literal,
    so it can never match a key in a CDHASH.
    Avoid converting it to prevent FloatDomainError.
    
    * insns.def (opt_case_dispatch): avoid converting Infinity
    * test/ruby/test_optimization.rb (test_opt_case_dispatch_inf): new
      [ruby-dev:49423] [Bug #11804]

  Modified files:
    trunk/ChangeLog
    trunk/insns.def
    trunk/test/ruby/test_optimization.rb
Index: insns.def
===================================================================
--- insns.def	(revision 53038)
+++ insns.def	(revision 53039)
@@ -1262,7 +1262,7 @@ opt_case_dispatch https://github.com/ruby/ruby/blob/trunk/insns.def#L1262
     switch(TYPE(key)) {
       case T_FLOAT: {
 	double ival;
-	if (modf(RFLOAT_VALUE(key), &ival) == 0.0) {
+	if (modf(RFLOAT_VALUE(key), &ival) == 0.0 && !isinf(ival)) {
 	    key = FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
 	}
       }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53038)
+++ ChangeLog	(revision 53039)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 11 17:59:05 2015  Eric Wong  <e@8...>
+
+	* insns.def (opt_case_dispatch): avoid converting Infinity
+	* test/ruby/test_optimization.rb (test_opt_case_dispatch_inf): new
+	  [ruby-dev:49423] [Bug #11804]'
+
 Fri Dec 11 16:48:57 2015  Eric Wong  <e@8...>
 
 	* hash.c (rb_num_hash_start): avoid pathological behavior
Index: test/ruby/test_optimization.rb
===================================================================
--- test/ruby/test_optimization.rb	(revision 53038)
+++ test/ruby/test_optimization.rb	(revision 53039)
@@ -362,4 +362,15 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L362
       assert_redefine_method(k, '===', "assert_equal(#{v.inspect} === 0, 0)")
     end
   end
+
+  def test_opt_case_dispatch_inf
+    inf = 1.0/0.0
+    result = case inf
+             when 1 then 1
+             when 0 then 0
+             else
+               inf.to_i rescue nil
+             end
+    assert_nil result, '[ruby-dev:49423] [Bug #11804]'
+  end
 end

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

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