Merge pull request #10271 from pitrou/fix-9947-abi-ndebug

Fix #9947: make the ABI identical between debug and non-debug builds
pull/10276/head
Matt Fowles Kulukundis 2 years ago committed by GitHub
commit 5b1c63e531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/google/protobuf/message_lite.cc
  2. 13
      src/google/protobuf/metadata_lite.h

@ -521,18 +521,14 @@ void GenericTypeHandler<std::string>::Merge(const std::string& from,
*to = from;
}
// Non-inline implementations of InternalMetadata routines
#if defined(NDEBUG) || defined(_MSC_VER)
// for opt and MSVC builds, the destructor is defined in the header.
#else
// Non-inline implementations of InternalMetadata destructor
// This is moved out of the header because the GOOGLE_DCHECK produces a lot of code.
InternalMetadata::~InternalMetadata() {
void InternalMetadata::CheckedDestruct() {
if (HasMessageOwnedArenaTag()) {
GOOGLE_DCHECK(!HasUnknownFieldsTag());
delete reinterpret_cast<Arena*>(ptr_ - kMessageOwnedArenaTagMask);
}
}
#endif
// Non-inline variants of std::string specializations for
// various InternalMetadata routines.

@ -77,15 +77,19 @@ class PROTOBUF_EXPORT InternalMetadata {
GOOGLE_DCHECK(!is_message_owned || arena != nullptr);
}
#if defined(NDEBUG) || defined(_MSC_VER)
// To keep the ABI identical between debug and non-debug builds,
// the destructor is always defined here even though it may delegate
// to a non-inline private method.
// (see https://github.com/protocolbuffers/protobuf/issues/9947)
~InternalMetadata() {
#if defined(NDEBUG) || defined(_MSC_VER)
if (HasMessageOwnedArenaTag()) {
delete reinterpret_cast<Arena*>(ptr_ - kMessageOwnedArenaTagMask);
}
}
#else
~InternalMetadata();
CheckedDestruct();
#endif
}
template <typename T>
void Delete() {
@ -264,6 +268,9 @@ class PROTOBUF_EXPORT InternalMetadata {
PROTOBUF_NOINLINE void DoSwap(T* other) {
mutable_unknown_fields<T>()->Swap(other);
}
// Private helper with debug checks for ~InternalMetadata()
void CheckedDestruct();
};
// String Template specializations.

Loading…
Cancel
Save