diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
commit | 6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3 (patch) | |
tree | e575738adf52d24b883cca5e8928a5ded31caba1 /src/google/protobuf/generated_message_util.h | |
parent | e7746f487cb9cca685ffb1b3d7dccc5554b618a4 (diff) | |
download | protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.gz protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.bz2 protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.zip |
Down-integrate from google3.
Diffstat (limited to 'src/google/protobuf/generated_message_util.h')
-rw-r--r-- | src/google/protobuf/generated_message_util.h | 81 |
1 files changed, 38 insertions, 43 deletions
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 <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> -#include <google/protobuf/stubs/once.h> // Add direct dep on port for pb.cc #include <google/protobuf/has_bits.h> #include <google/protobuf/implicit_weak_message.h> #include <google/protobuf/map_entry_lite.h> #include <google/protobuf/message_lite.h> +#include <google/protobuf/stubs/once.h> // Add direct dep on port for pb.cc +#include <google/protobuf/port.h> #include <google/protobuf/wire_format_lite.h> -namespace google { +#include <google/protobuf/port_def.inc> +#ifdef SWIG +#error "You cannot SWIG proto headers" +#endif + +#if GOOGLE_PROTOBUF_ENABLE_MOMI_PARSER +#include <google/protobuf/parse_context.h> +#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<const char*>( \ - &reinterpret_cast<const TYPE*>(16)->FIELD) - \ - reinterpret_cast<const char*>(16)) +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ + static_cast< ::google::protobuf::uint32>(reinterpret_cast<const char*>( \ + &reinterpret_cast<const TYPE*>(16)->FIELD) - \ + reinterpret_cast<const char*>(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<some message type>. 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 <class Type> bool AllAreInitialized(const Type& t) { // This version operates on MessageLite to avoid introducing a dependency on the // concrete message type. template <class T> -bool AllAreInitializedWeak(const ::google::protobuf::RepeatedPtrField<T>& t) { +bool AllAreInitializedWeak(const RepeatedPtrField<T>& t) { for (int i = t.size(); --i >= 0;) { - if (!reinterpret_cast<const ::google::protobuf::internal::RepeatedPtrFieldBase&>(t) - .Get<::google::protobuf::internal::ImplicitWeakTypeHandler<T> >(i) + if (!reinterpret_cast<const RepeatedPtrFieldBase&>(t) + .Get<ImplicitWeakTypeHandler<T> >(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<const uint8*>(&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<const uint8*>(&msg); @@ -262,8 +256,7 @@ struct CompareMapKey { template <typename MapFieldType, const SerializationTable* table> 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<typename MapFieldType::EntryTypeTrait> 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<int> 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<int> visit_status; }; +#else + std::atomic<int> 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 <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ |