aboutsummaryrefslogtreecommitdiff
path: root/src/google
diff options
context:
space:
mode:
Diffstat (limited to 'src/google')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc142
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_generator.h2
-rw-r--r--src/google/protobuf/compiler/java/java_message.cc20
-rw-r--r--src/google/protobuf/compiler/java/java_message_lite.cc14
-rw-r--r--src/google/protobuf/map.h13
-rw-r--r--src/google/protobuf/map_field_inl.h34
-rw-r--r--src/google/protobuf/repeated_field.h1
-rw-r--r--src/google/protobuf/stubs/hash.h5
-rw-r--r--src/google/protobuf/stubs/port.h2
-rw-r--r--src/google/protobuf/unittest.proto4
10 files changed, 204 insertions, 33 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
new file mode 100644
index 00000000..c1f90e41
--- /dev/null
+++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
@@ -0,0 +1,142 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// 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.
+
+// This test insures that
+// csharp/src/Google.Protobuf/Reflection/Descriptor.cs match exactly
+// what would be generated by the protocol compiler. The file is not
+// generated automatically at build time.
+//
+// If this test fails, run the script
+// "generate_descriptor_proto.sh" and add
+// csharp/src/Google.Protobuf/Reflection/Descriptor.cs to your changelist.
+
+#include <map>
+
+#include <google/protobuf/compiler/csharp/csharp_generator.h>
+#include <google/protobuf/compiler/importer.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/stl_util.h>
+#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/substitute.h>
+
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/googletest.h>
+#include <gtest/gtest.h>
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace csharp {
+
+namespace {
+
+class MockErrorCollector : public MultiFileErrorCollector {
+ public:
+ MockErrorCollector() {}
+ ~MockErrorCollector() {}
+
+ string text_;
+
+ // implements ErrorCollector ---------------------------------------
+ void AddError(const string& filename, int line, int column,
+ const string& message) {
+ strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n",
+ filename, line, column, message);
+ }
+};
+
+class MockGeneratorContext : public GeneratorContext {
+ public:
+ MockGeneratorContext() {}
+ ~MockGeneratorContext() {
+ STLDeleteValues(&files_);
+ }
+
+ void ExpectFileMatches(const string& virtual_filename,
+ const string& physical_filename) {
+ string* expected_contents = FindPtrOrNull(files_, virtual_filename);
+ ASSERT_TRUE(expected_contents != NULL)
+ << "Generator failed to generate file: " << virtual_filename;
+
+ string actual_contents;
+ GOOGLE_CHECK_OK(
+ File::GetContents(TestSourceDir() + "/" + physical_filename,
+ &actual_contents, true));
+ EXPECT_TRUE(actual_contents == *expected_contents)
+ << physical_filename << " needs to be regenerated. Please run "
+ "generate_descriptor_proto.sh. Then add this file "
+ "to your CL.";
+ }
+
+ // implements GeneratorContext --------------------------------------
+
+ virtual io::ZeroCopyOutputStream* Open(const string& filename) {
+ string** map_slot = &files_[filename];
+ delete *map_slot;
+ *map_slot = new string;
+
+ return new io::StringOutputStream(*map_slot);
+ }
+
+ private:
+ std::map<string, string*> files_;
+};
+
+TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
+ MockErrorCollector error_collector;
+ DiskSourceTree source_tree;
+ source_tree.MapPath("", TestSourceDir());
+ Importer importer(&source_tree, &error_collector);
+ const FileDescriptor* proto_file =
+ importer.Import("google/protobuf/descriptor.proto");
+ EXPECT_EQ("", error_collector.text_);
+ ASSERT_TRUE(proto_file != NULL);
+
+ Generator generator;
+ MockGeneratorContext context;
+ string error;
+ string parameter = "base_namespace=Google.Protobuf";
+ ASSERT_TRUE(generator.Generate(proto_file, parameter,
+ &context, &error));
+
+ context.ExpectFileMatches(
+ "Reflection/Descriptor.cs",
+ "../csharp/src/Google.Protobuf/Reflection/Descriptor.cs");
+}
+
+} // namespace
+
+} // namespace csharp
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.h b/src/google/protobuf/compiler/csharp/csharp_generator.h
index fd41d852..c8b19529 100644
--- a/src/google/protobuf/compiler/csharp/csharp_generator.h
+++ b/src/google/protobuf/compiler/csharp/csharp_generator.h
@@ -48,6 +48,7 @@ namespace csharp {
// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT Generator
: public google::protobuf::compiler::CodeGenerator {
+public:
virtual bool Generate(
const FileDescriptor* file,
const string& parameter,
@@ -61,4 +62,3 @@ class LIBPROTOC_EXPORT Generator
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__
-
diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc
index df4db463..652c5d78 100644
--- a/src/google/protobuf/compiler/java/java_message.cc
+++ b/src/google/protobuf/compiler/java/java_message.cc
@@ -253,18 +253,22 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessage$ver$.\n"
" ExtendableMessageOrBuilder<$classname$> {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "", "ver", GeneratedCodeVersionSuffix());
} else {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageOrBuilder {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
@@ -304,6 +308,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["ver"] = GeneratedCodeVersionSuffix();
+ variables["deprecation"] = descriptor_->options().deprecated()
+ ? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
@@ -312,8 +318,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
// The builder_type stores the super type name of the nested Builder class.
string builder_type;
if (descriptor_->extension_range_count() > 0) {
- printer->Print(variables,
- "public $static$final class $classname$ extends\n");
+ printer->Print(
+ variables,
+ "$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_);
printer->Print(
variables,
@@ -326,8 +333,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix());
} else {
- printer->Print(variables,
- "public $static$final class $classname$ extends\n");
+ printer->Print(
+ variables,
+ "$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_);
printer->Print(variables,
" com.google.protobuf.GeneratedMessage$ver$ implements\n"
diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc
index 048d5892..9720cacf 100644
--- a/src/google/protobuf/compiler/java/java_message_lite.cc
+++ b/src/google/protobuf/compiler/java/java_message_lite.cc
@@ -124,19 +124,23 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends \n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends \n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessageLite.\n"
" ExtendableMessageOrBuilder<\n"
" $classname$, $classname$.Builder> {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
} else {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageLiteOrBuilder {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
@@ -174,6 +178,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
+ variables["deprecation"] = descriptor_->options().deprecated()
+ ? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
@@ -184,7 +190,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
string builder_type;
if (descriptor_->extension_range_count() > 0) {
printer->Print(variables,
- "public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
@@ -194,7 +200,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_));
} else {
printer->Print(variables,
- "public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h
index 6458714e..61a23897 100644
--- a/src/google/protobuf/map.h
+++ b/src/google/protobuf/map.h
@@ -592,7 +592,7 @@ class Map {
MapAllocator(const MapAllocator<X>& allocator)
: arena_(allocator.arena()) {}
- pointer allocate(size_type n, const_pointer hint = 0) {
+ pointer allocate(size_type n, const void* hint = 0) {
// If arena is not given, malloc needs to be called which doesn't
// construct element object.
if (arena_ == NULL) {
@@ -1726,12 +1726,19 @@ struct hash<google::protobuf::MapKey> {
break;
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
return hash<string>()(map_key.GetStringValue());
+#if defined(GOOGLE_PROTOBUF_HAVE_64BIT_HASH)
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
return hash< ::google::protobuf::int64>()(map_key.GetInt64Value());
- case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
- return hash< ::google::protobuf::int32>()(map_key.GetInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value());
+#else
+ case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
+ case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
+ GOOGLE_LOG(FATAL) << "Unsupported on this platform.";
+ break;
+#endif
+ case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
+ return hash< ::google::protobuf::int32>()(map_key.GetInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h
index 01c9b89a..2d84b0a3 100644
--- a/src/google/protobuf/map_field_inl.h
+++ b/src/google/protobuf/map_field_inl.h
@@ -339,9 +339,9 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Swap(
MapFieldLiteType* other) {
MapField* down_other = down_cast<MapField*>(other);
- std::swap(MapFieldBase::repeated_field_, down_other->repeated_field_);
+ std::swap(this->MapFieldBase::repeated_field_, down_other->repeated_field_);
MapFieldLiteType::Swap(other);
- std::swap(MapFieldBase::state_, down_other->state_);
+ std::swap(this->MapFieldBase::state_, down_other->state_);
}
template <typename Key, typename T,
@@ -352,7 +352,7 @@ void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetEntryDescriptor(
const Descriptor** descriptor) {
- MapFieldBase::entry_descriptor_ = descriptor;
+ this->MapFieldBase::entry_descriptor_ = descriptor;
}
template <typename Key, typename T,
@@ -362,7 +362,7 @@ template <typename Key, typename T,
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetAssignDescriptorCallback(void (*callback)()) {
- MapFieldBase::assign_descriptor_callback_ = callback;
+ this->MapFieldBase::assign_descriptor_callback_ = callback;
}
template <typename Key, typename T,
@@ -392,19 +392,19 @@ template <typename Key, typename T,
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SyncRepeatedFieldWithMapNoLock() const {
- if (MapFieldBase::repeated_field_ == NULL) {
- if (MapFieldBase::arena_ == NULL) {
- MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
+ if (this->MapFieldBase::repeated_field_ == NULL) {
+ if (this->MapFieldBase::arena_ == NULL) {
+ this->MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
} else {
- MapFieldBase::repeated_field_ =
+ this->MapFieldBase::repeated_field_ =
Arena::CreateMessage<RepeatedPtrField<Message> >(
- MapFieldBase::arena_);
+ this->MapFieldBase::arena_);
}
}
const Map<Key, T>& map = GetInternalMap();
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
- MapFieldBase::repeated_field_);
+ this->MapFieldBase::repeated_field_);
repeated_field->Clear();
@@ -413,7 +413,7 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
InitDefaultEntryOnce();
GOOGLE_CHECK(default_entry_ != NULL);
EntryType* new_entry =
- down_cast<EntryType*>(default_entry_->New(MapFieldBase::arena_));
+ down_cast<EntryType*>(default_entry_->New(this->MapFieldBase::arena_));
repeated_field->AddAllocated(new_entry);
(*new_entry->mutable_key()) = it->first;
(*new_entry->mutable_value()) = it->second;
@@ -430,8 +430,8 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
Map<Key, T>* map = const_cast<MapField*>(this)->MutableInternalMap();
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
- MapFieldBase::repeated_field_);
- GOOGLE_CHECK(MapFieldBase::repeated_field_ != NULL);
+ this->MapFieldBase::repeated_field_);
+ GOOGLE_CHECK(this->MapFieldBase::repeated_field_ != NULL);
map->clear();
for (typename RepeatedPtrField<EntryType>::iterator it =
repeated_field->begin(); it != repeated_field->end(); ++it) {
@@ -452,8 +452,8 @@ int
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SpaceUsedExcludingSelfNoLock() const {
int size = 0;
- if (MapFieldBase::repeated_field_ != NULL) {
- size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
+ if (this->MapFieldBase::repeated_field_ != NULL) {
+ size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
}
Map<Key, T>* map = const_cast<MapField*>(this)->MutableInternalMap();
size += sizeof(*map);
@@ -475,10 +475,10 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
const {
if (default_entry_ == NULL) {
MapFieldBase::InitMetadataOnce();
- GOOGLE_CHECK(*MapFieldBase::entry_descriptor_ != NULL);
+ GOOGLE_CHECK(*this->MapFieldBase::entry_descriptor_ != NULL);
default_entry_ = down_cast<const EntryType*>(
MessageFactory::generated_factory()->GetPrototype(
- *MapFieldBase::entry_descriptor_));
+ *this->MapFieldBase::entry_descriptor_));
}
}
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h
index 4e5bcf51..db5893b5 100644
--- a/src/google/protobuf/repeated_field.h
+++ b/src/google/protobuf/repeated_field.h
@@ -1487,7 +1487,6 @@ inline void RepeatedPtrFieldBase::Add(
typename TypeHandler::Type* result =
TypeHandler::New(arena_, std::move(value));
rep_->elements[current_size_++] = result;
- return result;
}
#endif
diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h
index bf0b88b4..be998b29 100644
--- a/src/google/protobuf/stubs/hash.h
+++ b/src/google/protobuf/stubs/hash.h
@@ -40,6 +40,7 @@
#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1
#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1
+#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1
// Use C++11 unordered_{map|set} if available.
#if ((_LIBCPP_STD_VER >= 11) || \
@@ -92,6 +93,10 @@
# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
# endif
+# if __GNUC__ == 4 && __GNUC__MINOR__ <= 1
+# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH
+# endif
+
// Version checks for MSC.
// Apparently Microsoft decided to move hash_map *back* to the std namespace in
// MSVC 2010:
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h
index d37e8130..6f0633c4 100644
--- a/src/google/protobuf/stubs/port.h
+++ b/src/google/protobuf/stubs/port.h
@@ -358,7 +358,7 @@ class Bits {
#endif
}
- static uint64 Log2FloorNonZero64(uint64 n) {
+ static uint32 Log2FloorNonZero64(uint64 n) {
#if defined(__GNUC__)
return 63 ^ __builtin_clzll(n);
#else
diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto
index 96289cc5..188a4f47 100644
--- a/src/google/protobuf/unittest.proto
+++ b/src/google/protobuf/unittest.proto
@@ -191,6 +191,10 @@ message TestDeprecatedFields {
optional int32 deprecated_int32 = 1 [deprecated=true];
}
+message TestDeprecatedMessage {
+ option deprecated = true;
+}
+
// Define these after TestAllTypes to make sure the compiler can handle
// that.
message ForeignMessage {