diff options
author | Adam Cozzette <acozzette@google.com> | 2016-11-17 16:48:38 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-11-17 16:59:59 -0800 |
commit | 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (patch) | |
tree | 0276f81f8848a05d84cd7e287b43d665e30f04e3 /src/google/protobuf/util/internal | |
parent | e28286fa05d8327fd6c5aa70cfb3be558f0932b8 (diff) |
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/util/internal')
16 files changed, 117 insertions, 75 deletions
diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index eeb55c6b..213c2c40 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -94,19 +94,24 @@ StatusOr<To> FloatingPointToIntConvertAndCheck(From before) { } // For conversion between double and float only. -template <typename To, typename From> -StatusOr<To> FloatingPointConvertAndCheck(From before) { - if (MathLimits<From>::IsNaN(before)) { - return std::numeric_limits<To>::quiet_NaN(); - } +StatusOr<double> FloatToDouble(float before) { + // Casting float to double should just work as double has more precision + // than float. + return static_cast<double>(before); +} - To after = static_cast<To>(before); - if (MathUtil::AlmostEquals<To>(after, before)) { - return after; +StatusOr<float> DoubleToFloat(double before) { + if (MathLimits<double>::IsNaN(before)) { + return std::numeric_limits<float>::quiet_NaN(); + } else if (!MathLimits<double>::IsFinite(before)) { + // Converting a double +inf/-inf to float should just work. + return static_cast<float>(before); + } else if (before > std::numeric_limits<float>::max() || + before < -std::numeric_limits<float>::max()) { + // Double value outside of the range of float. + return InvalidArgument(DoubleAsString(before)); } else { - return InvalidArgument(::google::protobuf::internal::is_same<From, double>::value - ? DoubleAsString(before) - : FloatAsString(before)); + return static_cast<float>(before); } } @@ -162,20 +167,27 @@ StatusOr<uint64> DataPiece::ToUint64() const { StatusOr<double> DataPiece::ToDouble() const { if (type_ == TYPE_FLOAT) { - return FloatingPointConvertAndCheck<double, float>(float_); + return FloatToDouble(float_); } if (type_ == TYPE_STRING) { if (str_ == "Infinity") return std::numeric_limits<double>::infinity(); if (str_ == "-Infinity") return -std::numeric_limits<double>::infinity(); if (str_ == "NaN") return std::numeric_limits<double>::quiet_NaN(); - return StringToNumber<double>(safe_strtod); + StatusOr<double> value = StringToNumber<double>(safe_strtod); + if (value.ok() && !MathLimits<double>::IsFinite(value.ValueOrDie())) { + // safe_strtod converts out-of-range values to +inf/-inf, but we want + // to report them as errors. + return InvalidArgument(StrCat("\"", str_, "\"")); + } else { + return value; + } } return GenericConvert<double>(); } StatusOr<float> DataPiece::ToFloat() const { if (type_ == TYPE_DOUBLE) { - return FloatingPointConvertAndCheck<float, double>(double_); + return DoubleToFloat(double_); } if (type_ == TYPE_STRING) { if (str_ == "Infinity") return std::numeric_limits<float>::infinity(); diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc index ac1ed9ab..1772219a 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -190,7 +190,7 @@ void DefaultValueObjectWriter::RegisterFieldScrubCallBack( DefaultValueObjectWriter::Node::Node( const string& name, const google::protobuf::Type* type, NodeKind kind, - const DataPiece& data, bool is_placeholder, const vector<string>& path, + const DataPiece& data, bool is_placeholder, const std::vector<string>& path, bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback) : name_(name), type_(type), @@ -310,7 +310,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( // This code is checking if the field to be added to the tree should be // scrubbed or not by calling the field_scrub_callback_ callback function. - vector<string> path; + std::vector<string> path; if (!path_.empty()) { path.insert(path.begin(), path_.begin(), path_.end()); } @@ -466,7 +466,7 @@ DataPiece DefaultValueObjectWriter::CreateDefaultDataPieceForField( DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( StringPiece name) { if (current_ == NULL) { - vector<string> path; + std::vector<string> path; root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(), false, path, suppress_empty_list_, field_scrub_callback_.get())); @@ -514,7 +514,7 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::EndObject() { DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( StringPiece name) { if (current_ == NULL) { - vector<string> path; + std::vector<string> path; root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(), false, path, suppress_empty_list_, field_scrub_callback_.get())); diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h index 5f3b25f3..dc4551c9 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -139,8 +139,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { class LIBPROTOBUF_EXPORT Node { public: Node(const string& name, const google::protobuf::Type* type, NodeKind kind, - const DataPiece& data, bool is_placeholder, const vector<string>& path, - bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback); + const DataPiece& data, bool is_placeholder, + const std::vector<string>& path, bool suppress_empty_list, + FieldScrubCallBack* field_scrub_callback); virtual ~Node() { for (int i = 0; i < children_.size(); ++i) { delete children_[i]; @@ -166,7 +167,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // Accessors const string& name() const { return name_; } - const vector<string>& path() const { return path_; } + const std::vector<string>& path() const { return path_; } const google::protobuf::Type* type() const { return type_; } @@ -255,7 +256,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // google::protobuf::Type of the root message type. const google::protobuf::Type& type_; // Holds copies of strings passed to RenderString. - vector<string*> string_values_; + std::vector<string*> string_values_; // The current Node. Owned by its parents. Node* current_; diff --git a/src/google/protobuf/util/internal/field_mask_utility.cc b/src/google/protobuf/util/internal/field_mask_utility.cc index f0e8fc88..53b90fb0 100644 --- a/src/google/protobuf/util/internal/field_mask_utility.cc +++ b/src/google/protobuf/util/internal/field_mask_utility.cc @@ -112,7 +112,7 @@ string ConvertFieldMaskPath(const StringPiece path, util::Status DecodeCompactFieldMaskPaths(StringPiece paths, PathSinkCallback path_sink) { - stack<string> prefix; + std::stack<string> prefix; int length = paths.length(); int previous_position = 0; bool in_map_key = false; diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc index a8d48eff..2af4ad90 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/src/google/protobuf/util/internal/json_stream_parser.cc @@ -45,6 +45,8 @@ #include <google/protobuf/util/internal/object_writer.h> #include <google/protobuf/util/internal/json_escaping.h> #include <google/protobuf/stubs/strutil.h> +#include <google/protobuf/stubs/mathlimits.h> + namespace google { namespace protobuf { @@ -108,7 +110,8 @@ JsonStreamParser::JsonStreamParser(ObjectWriter* ow) string_open_(0), chunk_storage_(), coerce_to_utf8_(false), - allow_empty_null_(false) { + allow_empty_null_(false), + loose_float_number_conversion_(false) { // Initialize the stack with a single value to be parsed. stack_.push(VALUE); } @@ -532,6 +535,10 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { if (!safe_strtod(number, &result->double_val)) { return ReportFailure("Unable to parse number."); } + if (!loose_float_number_conversion_ && + !MathLimits<double>::IsFinite(result->double_val)) { + return ReportFailure("Number exceeds the range of double."); + } result->type = NumberResult::DOUBLE; p_.remove_prefix(index); return util::Status::OK; diff --git a/src/google/protobuf/util/internal/json_stream_parser.h b/src/google/protobuf/util/internal/json_stream_parser.h index 78b35cc2..6b9d46ee 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.h +++ b/src/google/protobuf/util/internal/json_stream_parser.h @@ -255,6 +255,9 @@ class LIBPROTOBUF_EXPORT JsonStreamParser { // value. bool allow_empty_null_; + // Whether allows out-of-range floating point numbers or reject them. + bool loose_float_number_conversion_; + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonStreamParser); }; diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index eaa7e045..ca71ff24 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -89,7 +89,8 @@ class JsonStreamParserTest : public ::testing::Test { virtual ~JsonStreamParserTest() {} util::Status RunTest(StringPiece json, int split, bool coerce_utf8 = false, - bool allow_empty_null = false) { + bool allow_empty_null = false, + bool loose_float_number_conversion = false) { JsonStreamParser parser(&mock_); // Special case for split == length, test parsing one character at a time. @@ -120,9 +121,10 @@ class JsonStreamParserTest : public ::testing::Test { } void DoTest(StringPiece json, int split, bool coerce_utf8 = false, - bool allow_empty_null = false) { - util::Status result = - RunTest(json, split, coerce_utf8, allow_empty_null); + bool allow_empty_null = false, + bool loose_float_number_conversion = false) { + util::Status result = RunTest(json, split, coerce_utf8, allow_empty_null, + loose_float_number_conversion); if (!result.ok()) { GOOGLE_LOG(WARNING) << result; } @@ -142,7 +144,7 @@ class JsonStreamParserTest : public ::testing::Test { #ifndef _MSC_VER // TODO(xiaofeng): We have to disable InSequence check for MSVC because it // causes stack overflow due to its use of a linked list that is desctructed - // recursively. + // recursively. ::testing::InSequence in_sequence_; #endif // !_MSC_VER MockObjectWriter mock_; @@ -322,8 +324,7 @@ TEST_F(JsonStreamParserTest, ObjectKeyTypes) { // - array containing primitive values (true, false, null, num, string) TEST_F(JsonStreamParserTest, ArrayPrimitiveValues) { - StringPiece str = - "[true, false, null, 'one', \"two\"]"; + StringPiece str = "[true, false, null, 'one', \"two\"]"; for (int i = 0; i <= str.length(); ++i) { ow_.StartList("") ->RenderBool("", true) @@ -710,17 +711,19 @@ TEST_F(JsonStreamParserTest, NegativeNumberTooBig) { } } -/* -TODO(sven): Fail parsing when parsing a double that is too large. - TEST_F(JsonStreamParserTest, DoubleTooBig) { - StringPiece str = "[184464073709551232321616.45]"; + StringPiece str = "[1.89769e+308]"; for (int i = 0; i <= str.length(); ++i) { ow_.StartList(""); - DoErrorTest(str, i, "Unable to parse number"); + DoErrorTest(str, i, "Number exceeds the range of double."); + } + str = "[-1.89769e+308]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Number exceeds the range of double."); } } -*/ + // invalid bare backslash. TEST_F(JsonStreamParserTest, UnfinishedEscape) { diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 4dcf4c3b..8bebf2ab 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -354,7 +354,7 @@ ProtoWriter::ProtoElement* ProtoWriter::ProtoElement::pop() { if (!proto3_) { // Calls the registered error listener for any required field(s) not yet // seen. - for (set<const google::protobuf::Field*>::iterator it = + for (std::set<const google::protobuf::Field*>::iterator it = required_fields_.begin(); it != required_fields_.end(); ++it) { ow_->MissingField((*it)->name()); diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 150f3cf1..554757d0 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -85,7 +85,7 @@ const google::protobuf::EnumValue* FindEnumValueByNumber( const google::protobuf::Enum& tech_enum, int number); // Utility function to format nanos. -const string FormatNanos(uint32 nanos); +const string FormatNanos(uint32 nanos, bool with_trailing_zeros); StatusOr<string> MapKeyDefaultValueAsString( const google::protobuf::Field& field) { @@ -122,7 +122,8 @@ ProtoStreamObjectSource::ProtoStreamObjectSource( use_lower_camel_for_enums_(false), recursion_depth_(0), max_recursion_depth_(kDefaultMaxRecursionDepth), - render_unknown_fields_(false) { + render_unknown_fields_(false), + add_trailing_zeros_for_timestamp_and_duration_(false) { GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL."; } @@ -136,7 +137,8 @@ ProtoStreamObjectSource::ProtoStreamObjectSource( use_lower_camel_for_enums_(false), recursion_depth_(0), max_recursion_depth_(kDefaultMaxRecursionDepth), - render_unknown_fields_(false) { + render_unknown_fields_(false), + add_trailing_zeros_for_timestamp_and_duration_(false) { GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL."; } @@ -318,7 +320,7 @@ Status ProtoStreamObjectSource::RenderPacked( Status ProtoStreamObjectSource::RenderTimestamp( const ProtoStreamObjectSource* os, const google::protobuf::Type& type, StringPiece field_name, ObjectWriter* ow) { - pair<int64, int32> p = os->ReadSecondsAndNanos(type); + std::pair<int64, int32> p = os->ReadSecondsAndNanos(type); int64 seconds = p.first; int32 nanos = p.second; if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) { @@ -342,7 +344,7 @@ Status ProtoStreamObjectSource::RenderTimestamp( Status ProtoStreamObjectSource::RenderDuration( const ProtoStreamObjectSource* os, const google::protobuf::Type& type, StringPiece field_name, ObjectWriter* ow) { - pair<int64, int32> p = os->ReadSecondsAndNanos(type); + std::pair<int64, int32> p = os->ReadSecondsAndNanos(type); int64 seconds = p.first; int32 nanos = p.second; if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds) { @@ -372,8 +374,10 @@ Status ProtoStreamObjectSource::RenderDuration( sign = "-"; nanos = -nanos; } - string formatted_duration = StringPrintf("%s%lld%ss", sign.c_str(), seconds, - FormatNanos(nanos).c_str()); + string formatted_duration = StringPrintf( + "%s%lld%ss", sign.c_str(), seconds, + FormatNanos(nanos, os->add_trailing_zeros_for_timestamp_and_duration_) + .c_str()); ow->RenderString(field_name, formatted_duration); return Status::OK; } @@ -1103,8 +1107,10 @@ const google::protobuf::EnumValue* FindEnumValueByNumber( // TODO(skarvaje): Look into optimizing this by not doing computation on // double. -const string FormatNanos(uint32 nanos) { - if (nanos == 0) return ""; +const string FormatNanos(uint32 nanos, bool with_trailing_zeros) { + if (nanos == 0) { + return with_trailing_zeros ? ".000" : ""; + } const char* format = (nanos % 1000 != 0) ? "%.9f" : (nanos % 1000000 != 0) ? "%.6f" : "%.3f"; diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index adecfbd3..88ca652b 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -294,6 +294,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { // Whether to render unknown fields. bool render_unknown_fields_; + // Whether to add trailing zeros for timestamp and duration. + bool add_trailing_zeros_for_timestamp_and_duration_; + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource); }; diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc index cac28a06..bf29c17a 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -101,7 +101,8 @@ class ProtostreamObjectSourceTest : helper_(GetParam()), mock_(), ow_(&mock_), - use_lower_camel_for_enums_(false) { + use_lower_camel_for_enums_(false), + add_trailing_zeros_(false) { helper_.ResetTypeInfo(Book::descriptor(), Proto3Message::descriptor()); } @@ -269,11 +270,14 @@ class ProtostreamObjectSourceTest void UseLowerCamelForEnums() { use_lower_camel_for_enums_ = true; } + void AddTrailingZeros() { add_trailing_zeros_ = true; } + testing::TypeInfoTestHelper helper_; ::testing::NiceMock<MockObjectWriter> mock_; ExpectingObjectWriter ow_; bool use_lower_camel_for_enums_; + bool add_trailing_zeros_; }; INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest, @@ -1023,6 +1027,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, TimestampDurationDefaultValue) { DoTest(out, TimestampDuration::descriptor()); } + } // namespace converter } // namespace util } // namespace protobuf diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index e7b38520..a9b15e68 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -113,13 +113,13 @@ class BaseProtoStreamObjectWriterTest listener_(), output_(new GrowingArrayByteSink(1000)), ow_() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(descriptor); ResetTypeInfo(descriptors); } explicit BaseProtoStreamObjectWriterTest( - vector<const Descriptor*> descriptors) + std::vector<const Descriptor*> descriptors) : helper_(GetParam()), listener_(), output_(new GrowingArrayByteSink(1000)), @@ -127,7 +127,7 @@ class BaseProtoStreamObjectWriterTest ResetTypeInfo(descriptors); } - void ResetTypeInfo(vector<const Descriptor*> descriptors) { + void ResetTypeInfo(std::vector<const Descriptor*> descriptors) { GOOGLE_CHECK(!descriptors.empty()) << "Must have at least one descriptor!"; helper_.ResetTypeInfo(descriptors); ow_.reset(helper_.NewProtoWriter(GetTypeUrl(descriptors[0]), output_.get(), @@ -135,7 +135,7 @@ class BaseProtoStreamObjectWriterTest } void ResetTypeInfo(const Descriptor* descriptor) { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(descriptor); ResetTypeInfo(descriptors); } @@ -1078,7 +1078,7 @@ class ProtoStreamObjectWriterTimestampDurationTest : public BaseProtoStreamObjectWriterTest { protected: ProtoStreamObjectWriterTimestampDurationTest() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(TimestampDuration::descriptor()); descriptors.push_back(google::protobuf::Timestamp::descriptor()); descriptors.push_back(google::protobuf::Duration::descriptor()); @@ -1473,7 +1473,7 @@ class ProtoStreamObjectWriterStructTest // Resets ProtoWriter with current set of options and other state. void ResetProtoWriter() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(StructType::descriptor()); descriptors.push_back(google::protobuf::Struct::descriptor()); ResetTypeInfo(descriptors); @@ -1664,7 +1664,7 @@ TEST_P(ProtoStreamObjectWriterMapTest, RepeatedMapKeyTest) { class ProtoStreamObjectWriterAnyTest : public BaseProtoStreamObjectWriterTest { protected: ProtoStreamObjectWriterAnyTest() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(AnyOut::descriptor()); descriptors.push_back(Book::descriptor()); descriptors.push_back(google::protobuf::Any::descriptor()); @@ -2308,7 +2308,7 @@ class ProtoStreamObjectWriterFieldMaskTest : public BaseProtoStreamObjectWriterTest { protected: ProtoStreamObjectWriterFieldMaskTest() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(FieldMaskTest::descriptor()); descriptors.push_back(google::protobuf::FieldMask::descriptor()); ResetTypeInfo(descriptors); @@ -2560,7 +2560,7 @@ class ProtoStreamObjectWriterWrappersTest : public BaseProtoStreamObjectWriterTest { protected: ProtoStreamObjectWriterWrappersTest() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(Int32Wrapper::descriptor()); descriptors.push_back(google::protobuf::Int32Value::descriptor()); ResetTypeInfo(descriptors); @@ -2583,7 +2583,7 @@ class ProtoStreamObjectWriterOneOfsTest : public BaseProtoStreamObjectWriterTest { protected: ProtoStreamObjectWriterOneOfsTest() { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(OneOfsRequest::descriptor()); descriptors.push_back(google::protobuf::Struct::descriptor()); ResetTypeInfo(descriptors); diff --git a/src/google/protobuf/util/internal/type_info.cc b/src/google/protobuf/util/internal/type_info.cc index 00a8ee7a..17d58475 100644 --- a/src/google/protobuf/util/internal/type_info.cc +++ b/src/google/protobuf/util/internal/type_info.cc @@ -60,7 +60,8 @@ class TypeInfoForTypeResolver : public TypeInfo { virtual util::StatusOr<const google::protobuf::Type*> ResolveTypeUrl( StringPiece type_url) const { - map<StringPiece, StatusOrType>::iterator it = cached_types_.find(type_url); + std::map<StringPiece, StatusOrType>::iterator it = + cached_types_.find(type_url); if (it != cached_types_.end()) { return it->second; } @@ -85,7 +86,8 @@ class TypeInfoForTypeResolver : public TypeInfo { virtual const google::protobuf::Enum* GetEnumByTypeUrl( StringPiece type_url) const { - map<StringPiece, StatusOrEnum>::iterator it = cached_enums_.find(type_url); + std::map<StringPiece, StatusOrEnum>::iterator it = + cached_enums_.find(type_url); if (it != cached_enums_.end()) { return it->second.ok() ? it->second.ValueOrDie() : NULL; } @@ -123,8 +125,8 @@ class TypeInfoForTypeResolver : public TypeInfo { typedef util::StatusOr<const google::protobuf::Enum*> StatusOrEnum; template <typename T> - static void DeleteCachedTypes(map<StringPiece, T>* cached_types) { - for (typename map<StringPiece, T>::iterator it = cached_types->begin(); + static void DeleteCachedTypes(std::map<StringPiece, T>* cached_types) { + for (typename std::map<StringPiece, T>::iterator it = cached_types->begin(); it != cached_types->end(); ++it) { if (it->second.ok()) { delete it->second.ValueOrDie(); @@ -151,13 +153,13 @@ class TypeInfoForTypeResolver : public TypeInfo { // Stores string values that will be referenced by StringPieces in // cached_types_, cached_enums_ and camel_case_name_table_. - mutable set<string> string_storage_; + mutable std::set<string> string_storage_; - mutable map<StringPiece, StatusOrType> cached_types_; - mutable map<StringPiece, StatusOrEnum> cached_enums_; + mutable std::map<StringPiece, StatusOrType> cached_types_; + mutable std::map<StringPiece, StatusOrEnum> cached_enums_; - mutable set<const google::protobuf::Type*> indexed_types_; - mutable map<StringPiece, StringPiece> camel_case_name_table_; + mutable std::set<const google::protobuf::Type*> indexed_types_; + mutable std::map<StringPiece, StringPiece> camel_case_name_table_; }; } // namespace diff --git a/src/google/protobuf/util/internal/type_info_test_helper.cc b/src/google/protobuf/util/internal/type_info_test_helper.cc index 49e18ed0..737ba9e4 100644 --- a/src/google/protobuf/util/internal/type_info_test_helper.cc +++ b/src/google/protobuf/util/internal/type_info_test_helper.cc @@ -55,7 +55,7 @@ namespace testing { void TypeInfoTestHelper::ResetTypeInfo( - const vector<const Descriptor*>& descriptors) { + const std::vector<const Descriptor*>& descriptors) { switch (type_) { case USE_TYPE_RESOLVER: { const DescriptorPool* pool = descriptors[0]->file()->pool(); @@ -73,14 +73,14 @@ void TypeInfoTestHelper::ResetTypeInfo( } void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor) { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(descriptor); ResetTypeInfo(descriptors); } void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor1, const Descriptor* descriptor2) { - vector<const Descriptor*> descriptors; + std::vector<const Descriptor*> descriptors; descriptors.push_back(descriptor1); descriptors.push_back(descriptor2); ResetTypeInfo(descriptors); diff --git a/src/google/protobuf/util/internal/type_info_test_helper.h b/src/google/protobuf/util/internal/type_info_test_helper.h index 1a279849..1a196715 100644 --- a/src/google/protobuf/util/internal/type_info_test_helper.h +++ b/src/google/protobuf/util/internal/type_info_test_helper.h @@ -64,7 +64,7 @@ class TypeInfoTestHelper { explicit TypeInfoTestHelper(TypeInfoSource type) : type_(type) {} // Creates a TypeInfo object for the given set of descriptors. - void ResetTypeInfo(const vector<const Descriptor*>& descriptors); + void ResetTypeInfo(const std::vector<const Descriptor*>& descriptors); // Convinent overloads. void ResetTypeInfo(const Descriptor* descriptor); diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index 9aab3481..d74c3f3a 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -30,6 +30,8 @@ #include <google/protobuf/util/internal/utility.h> +#include <algorithm> + #include <google/protobuf/stubs/callback.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> @@ -41,8 +43,6 @@ #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/mathlimits.h> -#include <algorithm> - namespace google { namespace protobuf { namespace util { @@ -324,7 +324,7 @@ string ToSnakeCase(StringPiece input) { return result; } -set<string>* well_known_types_ = NULL; +std::set<string>* well_known_types_ = NULL; GOOGLE_PROTOBUF_DECLARE_ONCE(well_known_types_init_); const char* well_known_types_name_array_[] = { "google.protobuf.Timestamp", "google.protobuf.Duration", @@ -337,7 +337,7 @@ const char* well_known_types_name_array_[] = { void DeleteWellKnownTypes() { delete well_known_types_; } void InitWellKnownTypes() { - well_known_types_ = new set<string>; + well_known_types_ = new std::set<string>; for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) { well_known_types_->insert(well_known_types_name_array_[i]); } |