diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-19 14:02:56 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-19 14:33:00 +0200 |
commit | eb9594bb25aef4ac9f90d6a83c6dd5003a7f4750 (patch) | |
tree | 53aaed9465f4a966b91f69df991a8c696e739770 /vespalib/src | |
parent | fb0d8859042570a15e0477f1ba6adf638b01db0f (diff) |
Use locale insensitive strtod and strtof.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/tests/executor/stress_test.cpp | 3 | ||||
-rw-r--r-- | vespalib/src/tests/random/friendfinder.cpp | 7 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/data/slime/json_format.cpp | 10 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/locale/c.cpp | 6 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/locale/c.h | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/asciistream.cpp | 13 |
6 files changed, 23 insertions, 17 deletions
diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index d4edf2483e8..aa5d9d53955 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/threadstackexecutor.h> +#include <vespa/vespalib/locale/c.h> #include <cmath> using namespace vespalib; @@ -96,7 +97,7 @@ Test::Main() TEST_DONE(); } uint32_t threads = atoi(_argv[1]); - double ms_per_task = strtod(_argv[2], 0); + double ms_per_task = locale::c::strtod(_argv[2], 0); uint32_t tasks = atoi(_argv[3]); fprintf(stderr, "threads : %u\n", threads); fprintf(stderr, "ms per task: %g\n", ms_per_task); diff --git a/vespalib/src/tests/random/friendfinder.cpp b/vespalib/src/tests/random/friendfinder.cpp index bc0931462a9..b7a1ed4712b 100644 --- a/vespalib/src/tests/random/friendfinder.cpp +++ b/vespalib/src/tests/random/friendfinder.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/util/random.h> #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/locale/c.h> #include <cmath> #include <vector> @@ -12,10 +13,10 @@ int main(int argc, char **argv) double lstddev = std::log(2.0); if (argc > 2) { - lstddev = std::log(strtod(argv[--argc], NULL)); - logmean = std::log(strtod(argv[--argc], NULL)); + lstddev = std::log(vespalib::locale::c::strtod(argv[--argc], NULL)); + logmean = std::log(vespalib::locale::c::strtod(argv[--argc], NULL)); } else if (argc > 1) { - logmean = std::log(strtod(argv[--argc], NULL)); + logmean = std::log(vespalib::locale::c::strtod(argv[--argc], NULL)); } fprintf(stderr, "100 typical friendlist sizes: "); diff --git a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp index 141ab81a059..856f9f654c2 100644 --- a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp @@ -4,13 +4,12 @@ #include "json_format.h" #include "inserter.h" #include "slime.h" -#include <errno.h> +#include <vespa/vespalib/data/memory_input.h> +#include <vespa/vespalib/locale/c.h> #include <cmath> #include <sstream> -#include <vespa/vespalib/data/memory_input.h> -namespace vespalib { -namespace slime { +namespace vespalib::slime { namespace { @@ -455,7 +454,7 @@ insertNumber(Inserter &inserter, bool isLong, const vespalib::string & value, ch errorCode = errno; inserter.insertLong(val); } else { - double val = strtod(value.c_str(), endp); + double val = locale::c::strtod(value.c_str(), endp); errorCode = errno; inserter.insertDouble(val); } @@ -505,4 +504,3 @@ JsonFormat::decode(const Memory &memory, Slime &slime) } } // namespace vespalib::slime -} // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/locale/c.cpp b/vespalib/src/vespa/vespalib/locale/c.cpp index 4d29ddc3b64..af228ce55c3 100644 --- a/vespalib/src/vespa/vespalib/locale/c.cpp +++ b/vespalib/src/vespa/vespalib/locale/c.cpp @@ -2,7 +2,7 @@ #include "c.h" #include "locale.h" -#include <stdlib.h> +#include <cstdlib> namespace vespalib::locale::c { @@ -16,5 +16,9 @@ double strtod(const char *startp, char **endp) { return strtod_l(startp, endp, _G_C_Locale.get()); } +float strtof(const char *startp, char **endp) { + return strtof_l(startp, endp, _G_C_Locale.get()); +} + } diff --git a/vespalib/src/vespa/vespalib/locale/c.h b/vespalib/src/vespa/vespalib/locale/c.h index a81e8daf745..a3587b64f55 100644 --- a/vespalib/src/vespa/vespalib/locale/c.h +++ b/vespalib/src/vespa/vespalib/locale/c.h @@ -5,6 +5,7 @@ namespace vespalib::locale::c { double strtod(const char *nptr, char **endptr); +float strtof(const char *nptr, char **endptr); } diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index 2eff3a745a7..8d3ff1d77dc 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -1,13 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/stllike/asciistream.h> +#include "asciistream.h" #include <vespa/vespalib/util/stringfmt.h> -#include <algorithm> -#include <limits> -#include <stdexcept> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/memory.h> +#include <vespa/vespalib/locale/c.h> #include <vespa/fastos/file.h> +#include <algorithm> +#include <limits> +#include <stdexcept> namespace vespalib { @@ -141,7 +142,7 @@ int getValue(double & val, const char *buf) { char *ebuf; errno = 0; - val = strtod(buf, &ebuf); + val = locale::c::strtod(buf, &ebuf); if ((errno != 0) || (buf == ebuf)) { throwInputError(errno, "double", buf); } @@ -152,7 +153,7 @@ int getValue(float & val, const char *buf) { char *ebuf; errno = 0; - val = strtof(buf, &ebuf); + val = locale::c::strtof(buf, &ebuf); if ((errno != 0) || (buf == ebuf)) { throwInputError(errno, "float", buf); } |