Skip to content

Commit

Permalink
Fix protocolbuffers#9947: make the ABI identical between debug and no…
Browse files Browse the repository at this point in the history
…n-debug builds
  • Loading branch information
pitrou authored and acozzette committed Jul 19, 2022
1 parent 2404ea4 commit 101b619
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/google/protobuf/message_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,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.
Expand Down
13 changes: 10 additions & 3 deletions src/google/protobuf/metadata_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,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() {
Expand Down Expand Up @@ -261,6 +265,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.
Expand Down

0 comments on commit 101b619

Please sign in to comment.