From 6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 8 Aug 2018 17:00:41 -0700 Subject: Down-integrate from google3. --- src/google/protobuf/generated_message_util.h | 81 +++++++++++++--------------- 1 file changed, 38 insertions(+), 43 deletions(-) (limited to 'src/google/protobuf/generated_message_util.h') diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 76b81242..23d1009e 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -46,15 +46,26 @@ #include #include -#include // Add direct dep on port for pb.cc #include #include #include #include +#include // Add direct dep on port for pb.cc +#include #include -namespace google { +#include +#ifdef SWIG +#error "You cannot SWIG proto headers" +#endif + +#if GOOGLE_PROTOBUF_ENABLE_MOMI_PARSER +#include +#endif + + +namespace google { namespace protobuf { class Arena; @@ -64,18 +75,6 @@ namespace io { class CodedInputStream; } namespace internal { -// Annotation for the compiler to emit a deprecation message if a field marked -// with option 'deprecated=true' is used in the code, or for other things in -// generated code which are deprecated. -// -// For internal use in the pb.cc files, deprecation warnings are suppressed -// there. -#undef DEPRECATED_PROTOBUF_FIELD -#define PROTOBUF_DEPRECATED - -#define GOOGLE_PROTOBUF_DEPRECATED_ATTR - - // Returns the offset of the given field within the given aggregate type. // This is equivalent to the ANSI C offsetof() macro. However, according // to the C++ standard, offsetof() only works on POD types, and GCC @@ -88,7 +87,7 @@ namespace internal { // For Clang we use __builtin_offsetof() and suppress the warning, // to avoid Control Flow Integrity and UBSan vptr sanitizers from // crashing while trying to validate the invalid reinterpet_casts. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ __builtin_offsetof(TYPE, FIELD) \ @@ -98,25 +97,21 @@ namespace internal { // just use zero, GCC complains about dereferencing a NULL pointer. We // choose 16 rather than some other number just in case the compiler would // be confused by an unaligned pointer. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - static_cast< ::google::protobuf::uint32>( \ - reinterpret_cast( \ - &reinterpret_cast(16)->FIELD) - \ - reinterpret_cast(16)) +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ + static_cast< ::google::protobuf::uint32>(reinterpret_cast( \ + &reinterpret_cast(16)->FIELD) - \ + reinterpret_cast(16)) #endif -// Constants for special floating point values. -LIBPROTOBUF_EXPORT double Infinity(); -LIBPROTOBUF_EXPORT double NaN(); - LIBPROTOBUF_EXPORT void InitProtobufDefaults(); // This used by proto1 -inline const std::string& GetEmptyString() { +LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { InitProtobufDefaults(); return GetEmptyStringAlreadyInited(); } + // True if IsInitialized() is true for all elements of t. Type is expected // to be a RepeatedPtrField. It's useful to have this // helper here to keep the protobuf compiler from ever having to emit loops in @@ -133,10 +128,10 @@ template bool AllAreInitialized(const Type& t) { // This version operates on MessageLite to avoid introducing a dependency on the // concrete message type. template -bool AllAreInitializedWeak(const ::google::protobuf::RepeatedPtrField& t) { +bool AllAreInitializedWeak(const RepeatedPtrField& t) { for (int i = t.size(); --i >= 0;) { - if (!reinterpret_cast(t) - .Get<::google::protobuf::internal::ImplicitWeakTypeHandler >(i) + if (!reinterpret_cast(t) + .Get >(i) .IsInitialized()) { return false; } @@ -191,14 +186,13 @@ inline bool IsOneofPresent(const void* base, uint32 offset, uint32 tag) { typedef void (*SpecialSerializer)(const uint8* base, uint32 offset, uint32 tag, uint32 has_offset, - ::google::protobuf::io::CodedOutputStream* output); + io::CodedOutputStream* output); LIBPROTOBUF_EXPORT void ExtensionSerializer(const uint8* base, uint32 offset, uint32 tag, - uint32 has_offset, - ::google::protobuf::io::CodedOutputStream* output); + uint32 has_offset, io::CodedOutputStream* output); LIBPROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base, uint32 offset, uint32 tag, uint32 has_offset, - ::google::protobuf::io::CodedOutputStream* output); + io::CodedOutputStream* output); struct SerializationTable { int num_fields; @@ -206,11 +200,11 @@ struct SerializationTable { }; LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table, - int32 num_fields, ::google::protobuf::io::CodedOutputStream* output); + int32 num_fields, io::CodedOutputStream* output); -inline void TableSerialize(const ::google::protobuf::MessageLite& msg, +inline void TableSerialize(const MessageLite& msg, const SerializationTable* table, - ::google::protobuf::io::CodedOutputStream* output) { + io::CodedOutputStream* output) { const FieldMetadata* field_table = table->field_table; int num_fields = table->num_fields - 1; const uint8* base = reinterpret_cast(&msg); @@ -227,7 +221,7 @@ uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table, int32 num_fields, bool is_deterministic, uint8* buffer); -inline uint8* TableSerializeToArray(const ::google::protobuf::MessageLite& msg, +inline uint8* TableSerializeToArray(const MessageLite& msg, const SerializationTable* table, bool is_deterministic, uint8* buffer) { const uint8* base = reinterpret_cast(&msg); @@ -262,8 +256,7 @@ struct CompareMapKey { template void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag, - uint32 has_offset, - ::google::protobuf::io::CodedOutputStream* output) { + uint32 has_offset, io::CodedOutputStream* output) { typedef MapEntryHelper Entry; typedef typename MapFieldType::MapType::const_iterator Iter; @@ -340,15 +333,15 @@ struct LIBPROTOBUF_EXPORT SCCInfoBase { kRunning = 1, kUninitialized = -1, // initial state }; -#ifndef _MSC_VER - std::atomic visit_status; -#else +#if defined(_MSC_VER) && !defined(__clang__) // MSVC doesnt make std::atomic constant initialized. This union trick // makes it so. union { int visit_status_to_make_linker_init; std::atomic visit_status; }; +#else + std::atomic visit_status; #endif int num_deps; void (*init_func)(); @@ -380,12 +373,14 @@ inline void OnShutdownDestroyMessage(const void* ptr) { OnShutdownRun(DestroyMessage, ptr); } // Destroy the string (call string destructor) -inline void OnShutdownDestroyString(const std::string* ptr) { +inline void OnShutdownDestroyString(const ::std::string* ptr) { OnShutdownRun(DestroyString, ptr); } } // namespace internal } // namespace protobuf - } // namespace google + +#include + #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ -- cgit v1.2.3