From 7ccb251be68fc44a1a42c14d2bb403462d0f5ca2 Mon Sep 17 00:00:00 2001 From: Garret Kelly Date: Mon, 5 Jun 2017 15:57:31 -0400 Subject: Remove unused output_file variable from js_embed The js_embed tool outputs to stdout, so the output_file variable is unnecessary and unused. --- src/google/protobuf/compiler/js/embed.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc index a725b62e..f0f946e5 100644 --- a/src/google/protobuf/compiler/js/embed.cc +++ b/src/google/protobuf/compiler/js/embed.cc @@ -34,8 +34,6 @@ #include #include -const char output_file[] = "well_known_types_embed.cc"; - static bool AsciiIsPrint(unsigned char c) { return c >= 32 && c < 127; } -- cgit v1.2.3 From 3ba21cd5f724528ab8792c05bda6e06ceb557bff Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 17 Jan 2018 16:05:47 -0800 Subject: Add support for libc++ on Windows. This disables a couple of workarounds which are only necessary with MSVC's standard library and cause problems with libc++. --- src/google/protobuf/arena.h | 2 +- src/google/protobuf/stubs/hash.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index f3cdedac..b500b3be 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -40,7 +40,7 @@ #if LANG_CXX11 #include #endif -#if defined(_MSC_VER) && !_HAS_EXCEPTIONS +#if defined(_MSC_VER) && !defined(_LIBCPP_STD_VER) && !_HAS_EXCEPTIONS // Work around bugs in MSVC header when _HAS_EXCEPTIONS=0. #include #include diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 218cd948..ec1f9810 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -235,7 +235,8 @@ class hash_set : public std::set { HashFcn hash_function() const { return HashFcn(); } }; -#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) +#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) && \ + !(defined(_LIBCPP_STD_VER) && _LIBCPP_STD_VER >= 11) template struct hash : public GOOGLE_PROTOBUF_HASH_COMPARE { -- cgit v1.2.3 From 02452db72510ca383b7710054a6fba4651ea6a31 Mon Sep 17 00:00:00 2001 From: Alexey Malov Date: Fri, 19 Jan 2018 13:40:12 +0300 Subject: The JsonParseOptions::ignore_unknown_fields option behavior treats unrecognized string values in enum fields as default ones. --- src/google/protobuf/util/internal/datapiece.cc | 7 ++- src/google/protobuf/util/internal/datapiece.h | 3 +- src/google/protobuf/util/internal/proto_writer.cc | 8 ++-- src/google/protobuf/util/internal/proto_writer.h | 2 +- src/google/protobuf/util/json_util_test.cc | 58 +++++++++++++++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 213c2c40..eb54faa4 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -272,7 +272,8 @@ StatusOr DataPiece::ToBytes() const { } StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, - bool use_lower_camel_for_enums) const { + bool use_lower_camel_for_enums, + bool ignore_unknown_enum_values) const { if (type_ == TYPE_NULL) return google::protobuf::NULL_VALUE; if (type_ == TYPE_STRING) { @@ -305,6 +306,10 @@ StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, value = FindEnumValueByNameWithoutUnderscoreOrNull(enum_type, enum_name); if (value != NULL) return value->number(); } + + // If ignore_unknown_enum_values is true an unknown enum value is treated + // as the default + if (ignore_unknown_enum_values) return enum_type->enumvalue(0).number(); } else { // We don't need to check whether the value is actually declared in the // enum because we preserve unknown enum values as well. diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h index 83516d09..95b133da 100644 --- a/src/google/protobuf/util/internal/datapiece.h +++ b/src/google/protobuf/util/internal/datapiece.h @@ -164,7 +164,8 @@ class LIBPROTOBUF_EXPORT DataPiece { // If the value is not a string, attempts to convert to a 32-bit integer. // If none of these succeeds, returns a conversion error status. util::StatusOr ToEnum(const google::protobuf::Enum* enum_type, - bool use_lower_camel_for_enums) const; + bool use_lower_camel_for_enums, + bool ignore_unknown_enum_values) const; private: // Disallow implicit constructor. diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 8bebf2ab..a61ed2d2 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -267,8 +267,9 @@ inline Status WriteString(int field_number, const DataPiece& data, inline Status WriteEnum(int field_number, const DataPiece& data, const google::protobuf::Enum* enum_type, CodedOutputStream* stream, - bool use_lower_camel_for_enums) { - StatusOr e = data.ToEnum(enum_type, use_lower_camel_for_enums); + bool use_lower_camel_for_enums, + bool ignore_unknown_values) { + StatusOr e = data.ToEnum(enum_type, use_lower_camel_for_enums, ignore_unknown_values); if (e.ok()) { WireFormatLite::WriteEnum(field_number, e.ValueOrDie(), stream); } @@ -665,7 +666,8 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField( case google::protobuf::Field_Kind_TYPE_ENUM: { status = WriteEnum(field.number(), data, typeinfo_->GetEnumByTypeUrl(field.type_url()), - stream_.get(), use_lower_camel_for_enums_); + stream_.get(), use_lower_camel_for_enums_, + ignore_unknown_fields_); break; } default: // TYPE_GROUP or TYPE_MESSAGE diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index 0db8485c..9e3bbfeb 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -309,7 +309,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // Indicates whether we finished writing root message completely. bool done_; - // If true, don't report unknown field names to the listener. + // If true, don't report unknown field names and enum values to the listener. bool ignore_unknown_fields_; // If true, check if enum name in camel case or without underscore matches the diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 5b714bb1..3a43ca1c 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -333,6 +333,64 @@ TEST_F(JsonUtilTest, TestDynamicMessage) { EXPECT_EQ(ToJson(generated, options), ToJson(*message, options)); } +TEST_F(JsonUtilTest, TestParsingUnknownEnumsAs0) { + TestMessage m; + { + JsonParseOptions options; + ASSERT_FALSE(options.ignore_unknown_fields); + string input = + "{\n" + " \"enum_value\":\"UNKNOWN_VALUE\"\n" + "}"; + m.set_enum_value(proto3::BAR); + EXPECT_FALSE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::BAR, m.enum_value()); // Keep previous value + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + EXPECT_EQ(0, m.enum_value()); // Unknown enum value must be decoded as 0 + } + // Integer values are read as usual + { + JsonParseOptions options; + string input = + "{\n" + " \"enum_value\":12345\n" + "}"; + m.set_enum_value(proto3::BAR); + EXPECT_TRUE(FromJson(input, &m, options)); + ASSERT_EQ(12345, m.enum_value()); + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + EXPECT_EQ(12345, m.enum_value()); + } + + // Trying to pass an object as an enum field value is always treated as an error + { + JsonParseOptions options; + string input = + "{\n" + " \"enum_value\":{}\n" + "}"; + options.ignore_unknown_fields = true; + EXPECT_FALSE(FromJson(input, &m, options)); + options.ignore_unknown_fields = false; + EXPECT_FALSE(FromJson(input, &m, options)); + } + // Trying to pass an array as an enum field value is always treated as an error + { + JsonParseOptions options; + string input = + "{\n" + " \"enum_value\":[]\n" + "}"; + EXPECT_FALSE(FromJson(input, &m, options)); + options.ignore_unknown_fields = true; + EXPECT_FALSE(FromJson(input, &m, options)); + } +} + typedef std::pair Segment; // A ZeroCopyOutputStream that writes to multiple buffers. class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { -- cgit v1.2.3 From af3813cd7337c622df067914cfa22732c08d6067 Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Tue, 20 Feb 2018 17:16:33 -0500 Subject: Rename a shadowed variable. Shadowed variables can cause readability issues. Ensure a shadowed variable isn't used in header files which may be used in a dependent project that explicitly disables them. --- src/google/protobuf/map_entry_lite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index dc6ec917..bbfb9c15 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -354,9 +354,9 @@ class MapEntryImpl : public Base { // We could use memcmp here, but we don't bother. The tag is one byte. GOOGLE_COMPILE_ASSERT(kTagSize == 1, tag_size_error); if (size > 0 && *reinterpret_cast(data) == kValueTag) { - typename Map::size_type size = map_->size(); + typename Map::size_type map_size = map_->size(); value_ptr_ = &(*map_)[key_]; - if (GOOGLE_PREDICT_TRUE(size != map_->size())) { + if (GOOGLE_PREDICT_TRUE(map_size != map_->size())) { // We created a new key-value pair. Fill in the value. typedef typename MapIf::type T; -- cgit v1.2.3 From 724f0be33d0eb42055ebe81ce0c8c7bf88ea666c Mon Sep 17 00:00:00 2001 From: John Millikin Date: Sat, 24 Feb 2018 11:34:40 -0800 Subject: Move `compiler/plugin.pb.cc` to libprotobuf with the other WKT sources. This lets all values of `WELL_KNOWN_PROTOS` be treated the same with regard to Bazel's protobuf blacklisting. --- BUILD | 2 +- cmake/libprotobuf.cmake | 1 + cmake/libprotoc.cmake | 1 - src/Makefile.am | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/BUILD b/BUILD index b786ff64..88d8b807 100644 --- a/BUILD +++ b/BUILD @@ -121,6 +121,7 @@ cc_library( "src/google/protobuf/api.pb.cc", "src/google/protobuf/compiler/importer.cc", "src/google/protobuf/compiler/parser.cc", + "src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/descriptor.cc", "src/google/protobuf/descriptor.pb.cc", "src/google/protobuf/descriptor_database.cc", @@ -378,7 +379,6 @@ cc_library( "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc", "src/google/protobuf/compiler/php/php_generator.cc", "src/google/protobuf/compiler/plugin.cc", - "src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/compiler/python/python_generator.cc", "src/google/protobuf/compiler/ruby/ruby_generator.cc", "src/google/protobuf/compiler/subprocess.cc", diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 65d05c19..173d2ab9 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -4,6 +4,7 @@ set(libprotobuf_files ${protobuf_source_dir}/src/google/protobuf/api.pb.cc ${protobuf_source_dir}/src/google/protobuf/compiler/importer.cc ${protobuf_source_dir}/src/google/protobuf/compiler/parser.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc ${protobuf_source_dir}/src/google/protobuf/descriptor.cc ${protobuf_source_dir}/src/google/protobuf/descriptor.pb.cc ${protobuf_source_dir}/src/google/protobuf/descriptor_database.cc diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 5f6d078c..dbf52daf 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -88,7 +88,6 @@ set(libprotoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc ${protobuf_source_dir}/src/google/protobuf/compiler/php/php_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc - ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc diff --git a/src/Makefile.am b/src/Makefile.am index af2db52f..6eac2e15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -278,6 +278,7 @@ libprotobuf_la_SOURCES = \ google/protobuf/io/zero_copy_stream_impl.cc \ google/protobuf/compiler/importer.cc \ google/protobuf/compiler/parser.cc \ + google/protobuf/compiler/plugin.pb.cc \ google/protobuf/util/delimited_message_util.cc \ google/protobuf/util/field_comparator.cc \ google/protobuf/util/field_mask_util.cc \ @@ -333,7 +334,6 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/code_generator.cc \ google/protobuf/compiler/command_line_interface.cc \ google/protobuf/compiler/plugin.cc \ - google/protobuf/compiler/plugin.pb.cc \ google/protobuf/compiler/subprocess.cc \ google/protobuf/compiler/subprocess.h \ google/protobuf/compiler/zip_writer.cc \ -- cgit v1.2.3 From fd595fcc93c949d6501a24f213633e007e93fb0c Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Thu, 1 Mar 2018 16:36:05 -0800 Subject: Revert "Move `compiler/plugin.pb.cc` to libprotobuf with the other WKT sources." This reverts commit 724f0be33d0eb42055ebe81ce0c8c7bf88ea666c. --- BUILD | 2 +- cmake/libprotobuf.cmake | 1 - cmake/libprotoc.cmake | 1 + src/Makefile.am | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/BUILD b/BUILD index ee81c759..7de6f407 100644 --- a/BUILD +++ b/BUILD @@ -121,7 +121,6 @@ cc_library( "src/google/protobuf/api.pb.cc", "src/google/protobuf/compiler/importer.cc", "src/google/protobuf/compiler/parser.cc", - "src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/descriptor.cc", "src/google/protobuf/descriptor.pb.cc", "src/google/protobuf/descriptor_database.cc", @@ -379,6 +378,7 @@ cc_library( "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc", "src/google/protobuf/compiler/php/php_generator.cc", "src/google/protobuf/compiler/plugin.cc", + "src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/compiler/python/python_generator.cc", "src/google/protobuf/compiler/ruby/ruby_generator.cc", "src/google/protobuf/compiler/subprocess.cc", diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 173d2ab9..65d05c19 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -4,7 +4,6 @@ set(libprotobuf_files ${protobuf_source_dir}/src/google/protobuf/api.pb.cc ${protobuf_source_dir}/src/google/protobuf/compiler/importer.cc ${protobuf_source_dir}/src/google/protobuf/compiler/parser.cc - ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc ${protobuf_source_dir}/src/google/protobuf/descriptor.cc ${protobuf_source_dir}/src/google/protobuf/descriptor.pb.cc ${protobuf_source_dir}/src/google/protobuf/descriptor_database.cc diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index dbf52daf..5f6d078c 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -88,6 +88,7 @@ set(libprotoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc ${protobuf_source_dir}/src/google/protobuf/compiler/php/php_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc diff --git a/src/Makefile.am b/src/Makefile.am index 6eac2e15..af2db52f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -278,7 +278,6 @@ libprotobuf_la_SOURCES = \ google/protobuf/io/zero_copy_stream_impl.cc \ google/protobuf/compiler/importer.cc \ google/protobuf/compiler/parser.cc \ - google/protobuf/compiler/plugin.pb.cc \ google/protobuf/util/delimited_message_util.cc \ google/protobuf/util/field_comparator.cc \ google/protobuf/util/field_mask_util.cc \ @@ -334,6 +333,7 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/code_generator.cc \ google/protobuf/compiler/command_line_interface.cc \ google/protobuf/compiler/plugin.cc \ + google/protobuf/compiler/plugin.pb.cc \ google/protobuf/compiler/subprocess.cc \ google/protobuf/compiler/subprocess.h \ google/protobuf/compiler/zip_writer.cc \ -- cgit v1.2.3