ruby-changes:31696
From: nobu <ko1@a...>
Date: Fri, 22 Nov 2013 12:44:06 +0900 (JST)
Subject: [ruby-changes:31696] nobu:r43775 (trunk): util.c: ignore too long fraction part
nobu 2013-11-22 12:43:56 +0900 (Fri, 22 Nov 2013) New Revision: 43775 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43775 Log: util.c: ignore too long fraction part * util.c (ruby_strtod): ignore too long fraction part, which does not affect the result. Modified files: trunk/ChangeLog trunk/test/ruby/test_float.rb trunk/util.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43774) +++ ChangeLog (revision 43775) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Nov 22 12:43:52 2013 Nobuyoshi Nakada <nobu@r...> + + * util.c (ruby_strtod): ignore too long fraction part, which does not + affect the result. + Fri Nov 22 12:17:14 2013 Nobuyoshi Nakada <nobu@r...> * ext/openssl/lib/openssl/buffering.rb (OpenSSL::Buffering#initialize): Index: util.c =================================================================== --- util.c (revision 43774) +++ util.c (revision 43775) @@ -716,6 +716,11 @@ extern void *MALLOC(size_t); https://github.com/ruby/ruby/blob/trunk/util.c#L716 #else #define MALLOC malloc #endif +#ifdef FREE +extern void FREE(void*); +#else +#define FREE free +#endif #ifndef Omit_Private_Memory #ifndef PRIVATE_MEM @@ -1006,7 +1011,7 @@ Balloc(int k) https://github.com/ruby/ruby/blob/trunk/util.c#L1011 #endif ACQUIRE_DTOA_LOCK(0); - if ((rv = freelist[k]) != 0) { + if (k <= Kmax && (rv = freelist[k]) != 0) { freelist[k] = rv->next; } else { @@ -1016,7 +1021,7 @@ Balloc(int k) https://github.com/ruby/ruby/blob/trunk/util.c#L1021 #else len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) /sizeof(double); - if (pmem_next - private_mem + len <= PRIVATE_mem) { + if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { rv = (Bigint*)pmem_next; pmem_next += len; } @@ -1035,6 +1040,10 @@ static void https://github.com/ruby/ruby/blob/trunk/util.c#L1040 Bfree(Bigint *v) { if (v) { + if (v->k > Kmax) { + FREE(v); + return; + } ACQUIRE_DTOA_LOCK(0); v->next = freelist[v->k]; freelist[v->k] = v; @@ -2098,6 +2107,7 @@ break2: https://github.com/ruby/ruby/blob/trunk/util.c#L2107 for (; c >= '0' && c <= '9'; c = *++s) { have_dig: nz++; + if (nf > DBL_DIG * 2) continue; if (c -= '0') { nf += nz; for (i = 1; i < nz; i++) Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 43774) +++ test/ruby/test_float.rb (revision 43775) @@ -613,4 +613,10 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L613 # always not flonum assert_raise(TypeError) { a = Float::INFINITY; def a.foo; end } end + + def test_long_string + assert_separately([], <<-'end;') + assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9) + end; + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/