diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-14 17:29:32 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-14 17:29:32 +0000 |
commit | a2a32c20434807e9966e3f48375f9419134d1b55 (patch) | |
tree | 16f115d52249335124cba31e959253275af624c4 /src/google | |
parent | 8da400ed12284575895cf7d5e4425435d4e43c42 (diff) | |
download | protobuf-a2a32c20434807e9966e3f48375f9419134d1b55.tar.gz protobuf-a2a32c20434807e9966e3f48375f9419134d1b55.tar.bz2 protobuf-a2a32c20434807e9966e3f48375f9419134d1b55.zip |
Support HP C++ on Tru64.
Patch (mostly) by Vincent Choinière <Choiniere.Vincent@hydro.qc.ca>.
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_unittest.cc | 5 | ||||
-rw-r--r-- | src/google/protobuf/descriptor.cc | 18 | ||||
-rw-r--r-- | src/google/protobuf/descriptor_unittest.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/io/zero_copy_stream_impl.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/message.h | 7 | ||||
-rw-r--r-- | src/google/protobuf/repeated_field.cc | 9 | ||||
-rw-r--r-- | src/google/protobuf/repeated_field.h | 29 | ||||
-rw-r--r-- | src/google/protobuf/stubs/common.h | 6 | ||||
-rw-r--r-- | src/google/protobuf/stubs/strutil.cc | 9 | ||||
-rw-r--r-- | src/google/protobuf/stubs/strutil.h | 4 | ||||
-rw-r--r-- | src/google/protobuf/text_format_unittest.cc | 6 |
11 files changed, 82 insertions, 17 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc index 1807b595..ce7d0c88 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -67,7 +67,8 @@ namespace protobuf { namespace compiler { namespace cpp { -namespace { +// Can't use an anonymous namespace here due to brokenness of Tru64 compiler. +namespace cpp_unittest { class MockErrorCollector : public MultiFileErrorCollector { @@ -854,7 +855,7 @@ TEST_F(GeneratedServiceTest, NotImplemented) { EXPECT_TRUE(controller.called_); } -} // namespace +} // namespace cpp_unittest } // namespace cpp } // namespace compiler diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index b843a06b..882b104b 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -1175,8 +1175,13 @@ void Descriptor::CopyTo(DescriptorProto* proto) const { void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const { proto->set_name(name()); proto->set_number(number()); - proto->set_label(static_cast<FieldDescriptorProto::Label>(label())); - proto->set_type(static_cast<FieldDescriptorProto::Type>(type())); + + // Some compilers do not allow static_cast directly between two enum types, + // so we must cast to int first. + proto->set_label(static_cast<FieldDescriptorProto::Label>( + implicit_cast<int>(label()))); + proto->set_type(static_cast<FieldDescriptorProto::Type>( + implicit_cast<int>(type()))); if (is_extension()) { proto->set_extendee("."); @@ -2487,10 +2492,15 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, result->full_name_ = full_name; result->file_ = file_; result->number_ = proto.number(); - result->type_ = static_cast<FieldDescriptor::Type>(proto.type()); - result->label_ = static_cast<FieldDescriptor::Label>(proto.label()); result->is_extension_ = is_extension; + // Some compilers do not allow static_cast directly between two enum types, + // so we must cast to int first. + result->type_ = static_cast<FieldDescriptor::Type>( + implicit_cast<int>(proto.type())); + result->label_ = static_cast<FieldDescriptor::Label>( + implicit_cast<int>(proto.label())); + // Some of these may be filled in when cross-linking. result->containing_type_ = NULL; result->extension_scope_ = NULL; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index c919b80d..b7dac69a 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -53,7 +53,7 @@ namespace google { namespace protobuf { -namespace { +namespace GOOGLE_ANONYMOUS_NAMESPACE{ // Some helpers to make assembling descriptors faster. DescriptorProto* AddMessage(FileDescriptorProto* file, const string& name) { @@ -1323,7 +1323,7 @@ class MiscTest : public testing::Test { DescriptorProto* message = AddMessage(&file_proto, "TestMessage"); FieldDescriptorProto* field = AddField(message, "foo", 1, FieldDescriptorProto::LABEL_OPTIONAL, - static_cast<FieldDescriptorProto::Type>(type)); + static_cast<FieldDescriptorProto::Type>(static_cast<int>(type))); if (type == FieldDescriptor::TYPE_MESSAGE || type == FieldDescriptor::TYPE_GROUP) { diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index 10071054..04d573e1 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -42,6 +42,8 @@ #endif #include <errno.h> #include <iostream> +#include <algorithm> + #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/stl_util-inl.h> diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 65419365..cd25faa2 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -110,7 +110,14 @@ #include <vector> #include <string> + +#ifdef __DECCXX +// HP C++'s iosfwd doesn't work. +#include <iostream> +#else #include <iosfwd> +#endif + #include <google/protobuf/stubs/common.h> namespace google { diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index ca0033cb..2d5cb0a4 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc @@ -36,6 +36,12 @@ namespace google { namespace protobuf { + +// HP C++ on Tru64 can't handle the stuff below being defined out-of-line, so +// on that platform everything is defined in repeated_field.h. On other +// platforms, we want these to be out-of-line to avoid code bloat. +#if !defined(__DECCXX) || !defined(__osf__) + namespace internal { GenericRepeatedField::~GenericRepeatedField() {} @@ -50,6 +56,7 @@ void RepeatedPtrField<string>::Clear() { current_size_ = 0; } -} // namespace protobuf +#endif // !defined(__DECCXX) || !defined(__osf__) +} // namespace protobuf } // namespace google diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index c81d27ef..203aa9bf 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -69,7 +69,12 @@ namespace internal { class LIBPROTOBUF_EXPORT GenericRepeatedField { public: inline GenericRepeatedField() {} +#if defined(__DECCXX) && defined(__osf__) + // HP C++ on Tru64 has trouble when this is not defined inline. + virtual ~GenericRepeatedField() {} +#else virtual ~GenericRepeatedField(); +#endif private: // We only want GeneratedMessageReflection to see and use these, so we @@ -516,9 +521,20 @@ void RepeatedPtrField<Element>::Clear() { current_size_ = 0; } +#if defined(__DECCXX) && defined(__osf__) +// HP C++ on Tru64 has trouble when this is not defined inline. +template <> +inline void RepeatedPtrField<string>::Clear() { + for (int i = 0; i < current_size_; i++) { + elements_[i]->clear(); + } + current_size_ = 0; +} +#else // Specialization defined in repeated_field.cc. template <> void LIBPROTOBUF_EXPORT RepeatedPtrField<string>::Clear(); +#endif template <typename Element> void RepeatedPtrField<Element>::MergeFrom(const RepeatedPtrField& other) { @@ -698,9 +714,16 @@ class RepeatedPtrIterator typename internal::remove_pointer<It>::type>::type> { public: typedef RepeatedPtrIterator<It> iterator; - typedef typename iterator::reference reference; - typedef typename iterator::pointer pointer; - typedef typename iterator::difference_type difference_type; + typedef std::iterator< + std::random_access_iterator_tag, + typename internal::remove_pointer< + typename internal::remove_pointer<It>::type>::type> superclass; + + // Let the compiler know that these are type names, so we don't have to + // write "typename" in front of them everywhere. + typedef typename superclass::reference reference; + typedef typename superclass::pointer pointer; + typedef typename superclass::difference_type difference_type; RepeatedPtrIterator() : it_(NULL) {} explicit RepeatedPtrIterator(const It& it) : it_(it) {} diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 05c15d1b..858d97fa 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -40,7 +40,11 @@ #include <cstddef> #include <string> #include <string.h> -#ifndef _MSC_VER +#if defined(__osf__) +// Tru64 lacks stdint.h, but has inttypes.h which defines a superset of +// what stdint.h would define. +#include <inttypes.h> +#elif !defined(_MSC_VER) #include <stdint.h> #endif diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index d3407faf..bc417344 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -58,17 +58,22 @@ inline bool IsNaN(double value) { return value != value; } +// These are defined as macros on some platforms. #undef them so that we can +// redefine them. +#undef isxdigit +#undef isprint + // The definitions of these in ctype.h change based on locale. Since our // string manipulation is all in relation to the protocol buffer and C++ // languages, we always want to use the C locale. So, we re-define these // exactly as we want them. -static bool isxdigit(char c) { +inline bool isxdigit(char c) { return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); } -static bool isprint(char c) { +inline bool isprint(char c) { return c >= 0x20 && c <= 0x7E; } diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 984c17e8..7f6bd96f 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -42,6 +42,10 @@ namespace protobuf { #ifdef _MSC_VER #define strtoll _strtoi64 #define strtoull _strtoui64 +#elif defined(__DECCXX) && defined(__osf__) +// HP C++ on Tru64 does not have strtoll, but strtol is already 64-bit. +#define strtoll strtol +#define strtoull strtoul #endif // ---------------------------------------------------------------------- diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 97a4fb03..7610c384 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -52,7 +52,9 @@ namespace google { namespace protobuf { -namespace { + +// Can't use an anonymous namespace here due to brokenness of Tru64 compiler. +namespace text_format_unittest { inline bool IsNaN(double value) { // NaN is never equal to anything, even itself. @@ -778,7 +780,7 @@ TEST_F(TextFormatMessageSetTest, Deserialize) { EXPECT_EQ(2, descriptors.size()); } -} // namespace +} // namespace text_format_unittest } // namespace protobuf } // namespace google |