mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
89288e30bf
commit
d65bc80d3f
3 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Fri Dec 11 17:59:05 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* 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@80x24.org>
|
||||
|
||||
* hash.c (rb_num_hash_start): avoid pathological behavior
|
||||
|
|
|
@ -1262,7 +1262,7 @@ opt_case_dispatch
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,4 +362,15 @@ class TestRubyOptimization < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue