summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-06-19 14:02:56 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-06-19 14:33:00 +0200
commiteb9594bb25aef4ac9f90d6a83c6dd5003a7f4750 (patch)
tree53aaed9465f4a966b91f69df991a8c696e739770 /searchlib
parentfb0d8859042570a15e0477f1ba6adf638b01db0f (diff)
Use locale insensitive strtod and strtof.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/expression/resultnodes.cpp17
-rw-r--r--searchlib/src/vespa/searchlib/features/queryfeature.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/fef/indexproperties.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/fef/rank_program.cpp9
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/plugin/query.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/test_features.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/query/queryterm.cpp3
10 files changed, 40 insertions, 41 deletions
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> &params)
{
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); }
};