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 | |
parent | fb0d8859042570a15e0477f1ba6adf638b01db0f (diff) |
Use locale insensitive strtod and strtof.
25 files changed, 88 insertions, 83 deletions
diff --git a/config/src/vespa/config/configgen/value_converter.cpp b/config/src/vespa/config/configgen/value_converter.cpp index 81883319e9d..4241b5354fd 100644 --- a/config/src/vespa/config/configgen/value_converter.cpp +++ b/config/src/vespa/config/configgen/value_converter.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/config/common/exceptions.h> #include "value_converter.h" +#include <vespa/config/common/exceptions.h> +#include <vespa/vespalib/locale/c.h> using namespace vespalib; using namespace vespalib::slime; @@ -34,7 +35,7 @@ double convertValue(const ::vespalib::slime::Inspector & __inspector) { switch (__inspector.type().getId()) { case LONG::ID: return static_cast<double>(__inspector.asLong()); case DOUBLE::ID: return static_cast<double>(__inspector.asDouble()); - case STRING::ID: return static_cast<double>(strtod(__inspector.asString().make_string().c_str(), 0)); + case STRING::ID: return static_cast<double>(vespalib::locale::c::strtod(__inspector.asString().make_string().c_str(), 0)); } throw InvalidConfigException("Expected double, but got incompatible config type " + __inspector.type().getId()); } diff --git a/document/src/vespa/document/select/parser.cpp b/document/src/vespa/document/select/parser.cpp index 8975c3e511c..ceaf0b0c438 100644 --- a/document/src/vespa/document/select/parser.cpp +++ b/document/src/vespa/document/select/parser.cpp @@ -13,6 +13,7 @@ #include <vespa/document/base/exceptions.h> #include <vespa/document/util/stringutil.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/locale/c.h> #include <boost/spirit/include/classic_chset.hpp> #include <boost/spirit/include/classic_core.hpp> #include <boost/spirit/include/classic_escape_char.hpp> @@ -706,7 +707,7 @@ parseNumberValue(DocSelectionGrammar& grammar, tree_node<T>& node) { } if (sval.find('.') != vespalib::string::npos) { char* endptr; - double val = strtod(sval.c_str(), &endptr); + double val = vespalib::locale::c::strtod(sval.c_str(), &endptr); if (*endptr == '\0') { return std::unique_ptr<ValueNode>(new FloatValueNode(val)); } diff --git a/eval/src/vespa/eval/eval/function.cpp b/eval/src/vespa/eval/eval/function.cpp index e045985e297..cb3d157c06f 100644 --- a/eval/src/vespa/eval/eval/function.cpp +++ b/eval/src/vespa/eval/eval/function.cpp @@ -7,11 +7,11 @@ #include "call_nodes.h" #include "delete_node.h" #include "aggr.h" +#include <vespa/vespalib/locale/c.h> #include <cctype> #include <map> -namespace vespalib { -namespace eval { +namespace vespalib::eval { using nodes::Node_UP; using nodes::Operator_UP; @@ -417,7 +417,7 @@ void parse_number(ParseContext &ctx) { } } char *end = nullptr; - double value = strtod(str.c_str(), &end); + double value = vespalib::locale::c::strtod(str.c_str(), &end); if (!str.empty() && end == str.data() + str.size()) { ctx.push_expression(Node_UP(new nodes::Number(value))); } else { @@ -906,5 +906,4 @@ Function::unwrap(vespalib::stringref input, //----------------------------------------------------------------------------- -} // namespace vespalib::eval -} // namespace vespalib +} diff --git a/fnet/src/examples/frt/rpc/rpc_invoke.cpp b/fnet/src/examples/frt/rpc/rpc_invoke.cpp index b23e316e5cd..ea34ffa6905 100644 --- a/fnet/src/examples/frt/rpc/rpc_invoke.cpp +++ b/fnet/src/examples/frt/rpc/rpc_invoke.cpp @@ -2,6 +2,7 @@ #include <vespa/fnet/frt/frt.h> #include <vespa/fastos/app.h> +#include <vespa/vespalib/locale/c.h> #include <vespa/log/log.h> LOG_SETUP("vespa-rpc-invoke"); @@ -29,10 +30,10 @@ private: req->GetParams()->AddInt64(strtoll(value, nullptr, 0)); break; case 'f': - req->GetParams()->AddFloat(strtod(value, nullptr)); + req->GetParams()->AddFloat(vespalib::locale::c::strtod(value, nullptr)); break; case 'd': - req->GetParams()->AddDouble(strtod(value, nullptr)); + req->GetParams()->AddDouble(vespalib::locale::c::strtod(value, nullptr)); break; case 's': req->GetParams()->AddString(value); diff --git a/juniper/src/vespa/juniper/config.cpp b/juniper/src/vespa/juniper/config.cpp index 7edbcb073dd..bd0dfe6c9b1 100644 --- a/juniper/src/vespa/juniper/config.cpp +++ b/juniper/src/vespa/juniper/config.cpp @@ -1,5 +1,4 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/* $Id$ */ #include "config.h" #include "IJuniperProperties.h" @@ -7,6 +6,7 @@ #include "juniperdebug.h" #define _NEED_SUMMARY_CONFIG_IMPL #include "SummaryConfig.h" +#include <vespa/vespalib/locale/c.h> namespace juniper { @@ -38,9 +38,8 @@ Config::Config(const char* config_name, Juniper & juniper) : size_t max_match_candidates = atoi(GetProp("matcher.max_match_candidates", "1000")); const char* seps = GetProp("dynsum.separators", separators.c_str()); const unsigned char* cons = - reinterpret_cast<const unsigned char*>(GetProp("dynsum.connectors", - separators.c_str())); - double proximity_factor = strtod(GetProp("proximity.factor", "0.25"), NULL); + reinterpret_cast<const unsigned char*>(GetProp("dynsum.connectors", separators.c_str())); + double proximity_factor = vespalib::locale::c::strtod(GetProp("proximity.factor", "0.25"), NULL); // Silently convert to something sensible if (proximity_factor > 1E8 || proximity_factor < 0) proximity_factor = 0.25; diff --git a/logd/src/logd/forward.cpp b/logd/src/logd/forward.cpp index 99e778a379c..66031ba2539 100644 --- a/logd/src/logd/forward.cpp +++ b/logd/src/logd/forward.cpp @@ -3,6 +3,7 @@ #include "forward.h" #include "errhandle.h" #include <vespa/vespalib/component/vtag.h> +#include <vespa/vespalib/locale/c.h> #include <unistd.h> #include <vespa/log/log.h> @@ -80,7 +81,7 @@ Forwarder::parseline(const char *linestart, const char *lineend) return false; } char *eod; - double logtime = strtod(fieldstart, &eod); + double logtime = vespalib::locale::c::strtod(fieldstart, &eod); if (eod != tab) { int fflen = tab - linestart; LOG(spam, "bad logline first field not strtod parsable: %.*s", diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp index eaa8232966b..5ba936b5f52 100644 --- a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp +++ b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp @@ -6,6 +6,7 @@ #include <vespa/document/fieldvalue/fieldvalue.h> #include <vespa/searchlib/util/fileutil.hpp> #include <vespa/searchlib/query/queryterm.h> +#include <vespa/vespalib/locale/c.h> #include <vespa/vespalib/util/array.hpp> #include <vespa/log/log.h> @@ -148,18 +149,23 @@ uint32_t StringAttribute::get(DocId doc, WeightedFloat * v, uint32_t sz) const WeightedConstChar * s = new WeightedConstChar[sz]; uint32_t n = static_cast<const AttributeVector *>(this)->get(doc, s, sz); for(uint32_t i(0),m(std::min(n,sz)); i<m; i++) { - v[i] = WeightedFloat(strtod(s[i].getValue(), NULL), s[i].getWeight()); + v[i] = WeightedFloat(vespalib::locale::c::strtod(s[i].getValue(), NULL), s[i].getWeight()); } delete [] s; return n; } +double +StringAttribute::getFloat(DocId doc) const { + return vespalib::locale::c::strtod(get(doc), NULL); +} + uint32_t StringAttribute::get(DocId doc, double * v, uint32_t sz) const { const char ** s = new const char *[sz]; uint32_t n = static_cast<const AttributeVector *>(this)->get(doc, s, sz); for(uint32_t i(0),m(std::min(n,sz)); i<m; i++) { - v[i] = strtod(s[i], NULL); + v[i] = vespalib::locale::c::strtod(s[i], NULL); } delete [] s; return n; diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h index 185c43d7393..5e0847f3039 100644 --- a/searchlib/src/vespa/searchlib/attribute/stringbase.h +++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h @@ -84,7 +84,7 @@ private: virtual void fixupEnumRefCounts(const EnumVector &enumHist); largeint_t getInt(DocId doc) const override { return strtoll(get(doc), NULL, 0); } - double getFloat(DocId doc) const override { return strtod(get(doc), NULL); } + double getFloat(DocId doc) const override; const char * getString(DocId doc, char * v, size_t sz) const override { (void) v; (void) sz; return get(doc); } long onSerializeForAscendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override; diff --git a/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp b/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp index 25ef3ce676e..a2679643784 100644 --- a/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp +++ b/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp @@ -5,6 +5,7 @@ #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/vespalib/encoding/base64.h> +#include <vespa/vespalib/locale/c.h> #include <vespa/log/log.h> LOG_SETUP(".searchlib.documentfieldnode"); @@ -257,7 +258,7 @@ class String2ResultNode : public ResultNode public: String2ResultNode(const vespalib::string & s) : _s(s) { } int64_t onGetInteger(size_t index) const override { (void) index; return strtoul(_s.c_str(), NULL, 0); } - double onGetFloat(size_t index) const override { (void) index; return strtod(_s.c_str(), NULL); } + double onGetFloat(size_t index) const override { (void) index; return vespalib::locale::c::strtod(_s.c_str(), NULL); } ConstBufferRef onGetString(size_t index, BufferRef buf) const override { (void) index; (void) buf; return ConstBufferRef(_s.c_str(), _s.size()); } private: String2ResultNode * clone() const override { return new String2ResultNode(_s); } diff --git a/searchlib/src/vespa/searchlib/expression/resultnodes.cpp b/searchlib/src/vespa/searchlib/expression/resultnodes.cpp index d2465727eae..a8a27f89d82 100644 --- a/searchlib/src/vespa/searchlib/expression/resultnodes.cpp +++ b/searchlib/src/vespa/searchlib/expression/resultnodes.cpp @@ -1,11 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/searchlib/expression/integerresultnode.h> -#include <vespa/searchlib/expression/floatresultnode.h> -#include <vespa/searchlib/expression/stringresultnode.h> -#include <vespa/searchlib/expression/rawresultnode.h> -#include <vespa/searchlib/expression/enumresultnode.h> -#include <vespa/searchlib/expression/nullresultnode.h> -#include <vespa/searchlib/expression/positiveinfinityresultnode.h> +#include "integerresultnode.h" +#include "floatresultnode.h" +#include "stringresultnode.h" +#include "rawresultnode.h" +#include "enumresultnode.h" +#include "nullresultnode.h" +#include "positiveinfinityresultnode.h" +#include <vespa/vespalib/locale/c.h> #include <cmath> #include <vespa/vespalib/objects/visit.hpp> #include <vespa/vespalib/objects/serializer.hpp> @@ -148,7 +149,7 @@ int PositiveInfinityResultNode::onCmp(const Identifiable & b) const } int64_t StringResultNode::onGetInteger(size_t index) const { (void) index; return strtoll(_value.c_str(), NULL, 0); } -double StringResultNode::onGetFloat(size_t index) const { (void) index; return strtod(_value.c_str(), NULL); } +double StringResultNode::onGetFloat(size_t index) const { (void) index; return vespalib::locale::c::strtod(_value.c_str(), NULL); } Serializer & StringResultNode::onSerialize(Serializer & os) const { os << _value; diff --git a/searchlib/src/vespa/searchlib/features/queryfeature.cpp b/searchlib/src/vespa/searchlib/features/queryfeature.cpp index 10a6f5811cd..271861d472c 100644 --- a/searchlib/src/vespa/searchlib/features/queryfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/queryfeature.cpp @@ -14,7 +14,7 @@ #include <vespa/eval/tensor/tensor_mapper.h> #include <vespa/eval/tensor/serialization/typed_binary_format.h> #include <vespa/eval/eval/value_type.h> -#include <memory> +#include <vespa/vespalib/locale/c.h> using namespace search::fef; using namespace search::fef::indexproperties; @@ -41,7 +41,7 @@ namespace { feature_t asFeature(const vespalib::string &str) { char *end; errno = 0; - double val = strtod(str.c_str(), &end); + double val = vespalib::locale::c::strtod(str.c_str(), &end); if (errno != 0 || *end != '\0') { // not happy if (str.size() > 0 && str[0] == '\'') { val = vespalib::hash_code(str.substr(1)); diff --git a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp index 72118be3f09..4e971bcc484 100644 --- a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp +++ b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp @@ -2,10 +2,9 @@ #include "indexproperties.h" #include "properties.h" +#include <vespa/vespalib/locale/c.h> -namespace search { -namespace fef { -namespace indexproperties { +namespace search::fef::indexproperties { namespace { @@ -40,7 +39,7 @@ lookupDouble(const Properties &props, const vespalib::string &name, double defau { Property p = props.lookup(name); if (p.found()) { - return strtod(p.get().c_str(), NULL); + return vespalib::locale::c::strtod(p.get().c_str(), NULL); } return defaultValue; } @@ -444,6 +443,4 @@ QueryFeature::set(Properties &props, const vespalib::string &queryFeatureName, c } // namespace type -} // namespace indexproperties -} // namespace fef -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/fef/rank_program.cpp b/searchlib/src/vespa/searchlib/fef/rank_program.cpp index 7081dd493d5..431ff798c83 100644 --- a/searchlib/src/vespa/searchlib/fef/rank_program.cpp +++ b/searchlib/src/vespa/searchlib/fef/rank_program.cpp @@ -2,11 +2,11 @@ #include "rank_program.h" #include "featureoverrider.h" +#include <vespa/vespalib/locale/c.h> using vespalib::Stash; -namespace search { -namespace fef { +namespace search::fef { using MappedValues = std::map<const NumberOrObject *, LazyValue>; using ValueSet = std::set<const NumberOrObject *>; @@ -40,7 +40,7 @@ struct OverrideVisitor : public IPropertiesVisitor { auto pos = feature_map.find(key); if (pos != feature_map.end()) { - overrides.push_back(Override(pos->second, strtod(values.get().c_str(), nullptr))); + overrides.push_back(Override(pos->second, vespalib::locale::c::strtod(values.get().c_str(), nullptr))); } } }; @@ -230,5 +230,4 @@ RankProgram::get_all_features(bool unbox_seeds) const return resolve(_resolver->getFeatureMap(), unbox_seeds); } -} // namespace fef -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/fef/test/plugin/query.cpp b/searchlib/src/vespa/searchlib/fef/test/plugin/query.cpp index 3ae52ee521b..4b4b10c4d25 100644 --- a/searchlib/src/vespa/searchlib/fef/test/plugin/query.cpp +++ b/searchlib/src/vespa/searchlib/fef/test/plugin/query.cpp @@ -3,11 +3,10 @@ #include "query.h" #include <vespa/searchlib/features/valuefeature.h> #include <vespa/searchlib/fef/properties.h> +#include <vespa/vespalib/locale/c.h> #include <sstream> -namespace search { -namespace fef { -namespace test { +namespace search::fef::test { QueryBlueprint::QueryBlueprint() : Blueprint("test_query"), @@ -33,10 +32,8 @@ QueryBlueprint::createExecutor(const IQueryEnvironment &queryEnv, vespalib::Stas { std::vector<feature_t> values; std::string val = queryEnv.getProperties().lookup(_key).get("0.0"); - values.push_back(strtod(val.data(), NULL)); + values.push_back(vespalib::locale::c::strtod(val.data(), NULL)); return stash.create<search::features::ValueExecutor>(values); } -} // namespace test -} // namespace fef -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/fef/test/test_features.cpp b/searchlib/src/vespa/searchlib/fef/test/test_features.cpp index a39f9c5ff4d..f924acd65de 100644 --- a/searchlib/src/vespa/searchlib/fef/test/test_features.cpp +++ b/searchlib/src/vespa/searchlib/fef/test/test_features.cpp @@ -2,13 +2,12 @@ #include <vespa/vespalib/testkit/test_kit.h> #include "test_features.h" +#include <vespa/vespalib/locale/c.h> using vespalib::eval::DoubleValue; using vespalib::eval::ValueType; -namespace search { -namespace fef { -namespace test { +namespace search::fef::test { //----------------------------------------------------------------------------- @@ -22,7 +21,7 @@ bool ImpureValueBlueprint::setup(const IIndexEnvironment &, const std::vector<vespalib::string> ¶ms) { ASSERT_EQUAL(1u, params.size()); - value = strtod(params[0].c_str(), nullptr); + value = vespalib::locale::c::strtod(params[0].c_str(), nullptr); describeOutput("out", "the impure value"); return true; } @@ -108,6 +107,4 @@ TrackingBlueprint::createExecutor(const IQueryEnvironment &, vespalib::Stash &st //----------------------------------------------------------------------------- -} // namespace test -} // namespace fef -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/query/queryterm.cpp b/searchlib/src/vespa/searchlib/query/queryterm.cpp index a5c8bb9f66b..694988ef74e 100644 --- a/searchlib/src/vespa/searchlib/query/queryterm.cpp +++ b/searchlib/src/vespa/searchlib/query/queryterm.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/objects/visit.h> #include <vespa/vespalib/text/utf8.h> #include <vespa/vespalib/util/classname.h> +#include <vespa/vespalib/locale/c.h> #include <cmath> namespace { @@ -311,7 +312,7 @@ struct IntDecoder { }; struct DoubleDecoder { - static double fromstr(const char * v, char ** end) { return strtod(v, end); } + static double fromstr(const char * v, char ** end) { return vespalib::locale::c::strtod(v, end); } static double nearestDownwd(double n, double min) { return std::nextafterf(n, min); } static double nearestUpward(double n, double max) { return std::nextafterf(n, max); } }; diff --git a/storage/src/vespa/storage/tools/storage-cmd.cpp b/storage/src/vespa/storage/tools/storage-cmd.cpp index 5c430fd6e4d..564574627a7 100644 --- a/storage/src/vespa/storage/tools/storage-cmd.cpp +++ b/storage/src/vespa/storage/tools/storage-cmd.cpp @@ -2,6 +2,7 @@ #include <vespa/fnet/frt/frt.h> #include <vespa/slobrok/sbmirror.h> #include <vespa/fastos/app.h> +#include <vespa/vespalib/locale/c.h> #include <vespa/log/log.h> LOG_SETUP("vespa-storage-cmd"); @@ -29,10 +30,10 @@ private: req->GetParams()->AddInt64(strtoll(value, NULL, 0)); break; case 'f': - req->GetParams()->AddFloat(strtod(value, NULL)); + req->GetParams()->AddFloat(vespalib::locale::c::strtod(value, NULL)); break; case 'd': - req->GetParams()->AddDouble(strtod(value, NULL)); + req->GetParams()->AddDouble(vespalib::locale::c::strtod(value, NULL)); break; case 's': req->GetParams()->AddString(value); diff --git a/vbench/src/vbench/http/benchmark_headers.h b/vbench/src/vbench/http/benchmark_headers.h index cb975d73071..92c4a05271b 100644 --- a/vbench/src/vbench/http/benchmark_headers.h +++ b/vbench/src/vbench/http/benchmark_headers.h @@ -4,6 +4,7 @@ #pragma once #include <vbench/core/string.h> +#include <vespa/vespalib/locale/c.h> namespace vbench { @@ -21,7 +22,7 @@ struct BenchmarkHeaders void set(const string &string_value) { char *end; errno = 0; - double val = strtod(string_value.c_str(), &end); + double val = vespalib::locale::c::strtod(string_value.c_str(), &end); if (errno == 0 && *end == '\0') { value = val; is_set = true; 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); } diff --git a/vespalog/src/vespa/log/llparser.cpp b/vespalog/src/vespa/log/llparser.cpp index 28d3a6e25b8..d239f291c9f 100644 --- a/vespalog/src/vespa/log/llparser.cpp +++ b/vespalog/src/vespa/log/llparser.cpp @@ -1,15 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <sys/time.h> #include "log-target.h" #include "llparser.h" #include "internal.h" +#include <cstdlib> +#include <unistd.h> +#include <sys/time.h> namespace ns_log { |