From 2726e7a6ebd72eec6f66abe4ced3c88983f20b8e Mon Sep 17 00:00:00 2001 From: "liujisi@google.com" Date: Fri, 3 Dec 2010 09:12:33 +0000 Subject: [PATCH] Fix issues: 166 167 172 175 181 188 192 194 195. --- .../google/protobuf/MessageLiteOrBuilder.java | 4 +- m4/acx_pthread.m4 | 6 ++- python/google/protobuf/message.py | 3 ++ src/Makefile.am | 1 - .../compiler/command_line_interface.cc | 4 +- .../protobuf/compiler/cpp/cpp_unittest.cc | 16 ++++---- src/google/protobuf/descriptor_database.cc | 4 +- src/google/protobuf/repeated_field.h | 6 +-- src/google/protobuf/stubs/common.h | 15 ++++--- src/google/protobuf/stubs/hash.cc | 41 ------------------- src/google/protobuf/wire_format_lite_inl.h | 2 +- 11 files changed, 35 insertions(+), 67 deletions(-) delete mode 100644 src/google/protobuf/stubs/hash.cc diff --git a/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java b/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java index a2a7448a9b..7cc72e9cb5 100644 --- a/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +++ b/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java @@ -38,7 +38,9 @@ package com.google.protobuf; */ public interface MessageLiteOrBuilder { /** - * Get an instance of the type with all fields set to their default values. + * Get an instance of the type with no fields set. Because no fields are set, + * all getters for singular fields will return default values and repeated + * fields will appear empty. * This may or may not be a singleton. This differs from the * {@code getDefaultInstance()} method of generated message classes in that * this method is an abstract method of the {@code MessageLite} interface diff --git a/m4/acx_pthread.m4 b/m4/acx_pthread.m4 index 2cf20de144..cb1a4bbe4d 100644 --- a/m4/acx_pthread.m4 +++ b/m4/acx_pthread.m4 @@ -272,9 +272,11 @@ if test "x$acx_pthread_ok" = xyes; then AC_TRY_LINK(,, , [done=yes]) if test "x$done" = xyes ; then - AC_MSG_RESULT([no]) - else AC_MSG_RESULT([yes]) + done="no" + else + AC_MSG_RESULT([no]) + done="yes" fi fi diff --git a/python/google/protobuf/message.py b/python/google/protobuf/message.py index 54cf35ea6b..6f19f85f4f 100755 --- a/python/google/protobuf/message.py +++ b/python/google/protobuf/message.py @@ -226,6 +226,9 @@ class Message(object): raise NotImplementedError def HasField(self, field_name): + """Checks if a certain field is set for the message. Note if the + field_name is not defined in the message descriptor, ValueError will be + raised.""" raise NotImplementedError def ClearField(self, field_name): diff --git a/src/Makefile.am b/src/Makefile.am index 92bbe8cc43..606e857bb1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,7 +81,6 @@ libprotobuf_lite_la_LDFLAGS = -version-info 6:0:0 -export-dynamic -no-undefined libprotobuf_lite_la_SOURCES = \ google/protobuf/stubs/common.cc \ google/protobuf/stubs/once.cc \ - google/protobuf/stubs/hash.cc \ google/protobuf/stubs/hash.h \ google/protobuf/stubs/map-util.h \ google/protobuf/stubs/stl_util-inl.h \ diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 9e9849cfb0..1c76994bdc 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -781,7 +781,7 @@ bool CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { // If no --proto_path was given, use the current working directory. if (proto_path_.empty()) { - proto_path_.push_back(make_pair("", ".")); + proto_path_.push_back(make_pair("", ".")); } // Check some errror cases. @@ -910,7 +910,7 @@ bool CommandLineInterface::InterpretArgument(const string& name, cerr << disk_path << ": warning: directory does not exist." << endl; } - proto_path_.push_back(make_pair(virtual_path, disk_path)); + proto_path_.push_back(make_pair(virtual_path, disk_path)); } } else if (name == "-o" || name == "--descriptor_set_out") { diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc index 41ba5e43c3..a950583ef2 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -853,14 +853,14 @@ TEST(GeneratedEnumTest, MinAndMax) { EXPECT_EQ(12589235, unittest::TestSparseEnum_ARRAYSIZE); // Make sure we can take the address of _MIN, _MAX and _ARRAYSIZE. - void* nullptr = 0; // NULL may be integer-type, not pointer-type. - EXPECT_NE(nullptr, &unittest::TestAllTypes::NestedEnum_MIN); - EXPECT_NE(nullptr, &unittest::TestAllTypes::NestedEnum_MAX); - EXPECT_NE(nullptr, &unittest::TestAllTypes::NestedEnum_ARRAYSIZE); - - EXPECT_NE(nullptr, &unittest::ForeignEnum_MIN); - EXPECT_NE(nullptr, &unittest::ForeignEnum_MAX); - EXPECT_NE(nullptr, &unittest::ForeignEnum_ARRAYSIZE); + void* null_pointer = 0; // NULL may be integer-type, not pointer-type. + EXPECT_NE(null_pointer, &unittest::TestAllTypes::NestedEnum_MIN); + EXPECT_NE(null_pointer, &unittest::TestAllTypes::NestedEnum_MAX); + EXPECT_NE(null_pointer, &unittest::TestAllTypes::NestedEnum_ARRAYSIZE); + + EXPECT_NE(null_pointer, &unittest::ForeignEnum_MIN); + EXPECT_NE(null_pointer, &unittest::ForeignEnum_MAX); + EXPECT_NE(null_pointer, &unittest::ForeignEnum_ARRAYSIZE); // Make sure we can use _MIN, _MAX and _ARRAYSIZE as switch cases. switch (unittest::SPARSE_A) { diff --git a/src/google/protobuf/descriptor_database.cc b/src/google/protobuf/descriptor_database.cc index 95708d948e..23e48a67f5 100644 --- a/src/google/protobuf/descriptor_database.cc +++ b/src/google/protobuf/descriptor_database.cc @@ -101,7 +101,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex::AddSymbol( if (iter == by_symbol_.end()) { // Apparently the map is currently empty. Just insert and be done with it. - by_symbol_.insert(make_pair(name, value)); + by_symbol_.insert(typename map::value_type(name, value)); return true; } @@ -128,7 +128,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex::AddSymbol( // Insert the new symbol using the iterator as a hint, the new entry will // appear immediately before the one the iterator is pointing at. - by_symbol_.insert(iter, make_pair(name, value)); + by_symbol_.insert(iter, typename map::value_type(name, value)); return true; } diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index ae96107a5b..f380e7c0d9 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -1199,7 +1199,7 @@ template class RepeatedFieldBackInsertIterator } private: - RepeatedField* const field_; + RepeatedField* field_; }; // A back inserter for RepeatedPtrField objects. @@ -1230,7 +1230,7 @@ template class RepeatedPtrFieldBackInsertIterator } private: - RepeatedPtrField* const field_; + RepeatedPtrField* field_; }; // A back inserter for RepeatedPtrFields that inserts by transfering ownership @@ -1259,7 +1259,7 @@ template class AllocatedRepeatedPtrFieldBackInsertIterator } private: - RepeatedPtrField* const field_; + RepeatedPtrField* field_; }; } // namespace internal diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 749e6e9d41..0b4df8a95f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -71,8 +71,6 @@ namespace std {} namespace google { namespace protobuf { -using namespace std; // Don't do this at home, kids. - #undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS #define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ TypeName(const TypeName&); \ @@ -126,7 +124,7 @@ void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, const char* filename); // Converts a numeric version number to a string. -string LIBPROTOBUF_EXPORT VersionString(int version); +std::string LIBPROTOBUF_EXPORT VersionString(int version); } // namespace internal @@ -369,6 +367,7 @@ struct CompileAssert { typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \ msg[bool(expr) ? 1 : -1] + // Implementation details of COMPILE_ASSERT: // // - COMPILE_ASSERT works by defining an array type that has -1 @@ -636,7 +635,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogMessage(LogLevel level, const char* filename, int line); ~LogMessage(); - LogMessage& operator<<(const string& value); + LogMessage& operator<<(const std::string& value); LogMessage& operator<<(const char* value); LogMessage& operator<<(char value); LogMessage& operator<<(int value); @@ -652,7 +651,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogLevel level_; const char* filename_; int line_; - string message_; + std::string message_; }; // Used to make the entire "LOG(BLAH) << etc." expression have a void return @@ -731,7 +730,7 @@ class LIBPROTOBUF_EXPORT LogFinisher { #endif // !NDEBUG typedef void LogHandler(LogLevel level, const char* filename, int line, - const string& message); + const std::string& message); // The protobuf library sometimes writes warning and error messages to // stderr. These messages are primarily useful for developers, but may @@ -1173,6 +1172,10 @@ LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); } // namespace internal +// This is at the end of the file instead of the beginning to work around a bug +// in some versions of MSVC. +using namespace std; // Don't do this at home, kids. + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/hash.cc b/src/google/protobuf/stubs/hash.cc deleted file mode 100644 index 9eaf4a1ee2..0000000000 --- a/src/google/protobuf/stubs/hash.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) - -#include - -namespace google { -namespace protobuf { - -// Nothing needed here right now. - -} // namespace protobuf -} // namespace google diff --git a/src/google/protobuf/wire_format_lite_inl.h b/src/google/protobuf/wire_format_lite_inl.h index a461a6cad8..103b0bd0ca 100644 --- a/src/google/protobuf/wire_format_lite_inl.h +++ b/src/google/protobuf/wire_format_lite_inl.h @@ -222,7 +222,7 @@ inline const uint8* WireFormatLite::ReadPrimitiveFromArray< } template -inline bool WireFormatLite::ReadRepeatedPrimitive(int tag_size, +inline bool WireFormatLite::ReadRepeatedPrimitive(int, // tag_size, unused. uint32 tag, io::CodedInputStream* input, RepeatedField* values) {