Skip to content

Commit 0574167

Browse files
committed
Fix #9947: make the ABI identical between debug and non-debug builds
1 parent 8be7304 commit 0574167

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/google/protobuf/message_lite.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,14 @@ void GenericTypeHandler<std::string>::Merge(const std::string& from,
521521
*to = from;
522522
}
523523

524-
// Non-inline implementations of InternalMetadata routines
525-
#if defined(NDEBUG) || defined(_MSC_VER)
526-
// for opt and MSVC builds, the destructor is defined in the header.
527-
#else
524+
// Non-inline implementations of InternalMetadata destructor
528525
// This is moved out of the header because the GOOGLE_DCHECK produces a lot of code.
529-
InternalMetadata::~InternalMetadata() {
526+
void InternalMetadata::CheckedDestruct() {
530527
if (HasMessageOwnedArenaTag()) {
531528
GOOGLE_DCHECK(!HasUnknownFieldsTag());
532529
delete reinterpret_cast<Arena*>(ptr_ - kMessageOwnedArenaTagMask);
533530
}
534531
}
535-
#endif
536532

537533
// Non-inline variants of std::string specializations for
538534
// various InternalMetadata routines.

src/google/protobuf/metadata_lite.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ class PROTOBUF_EXPORT InternalMetadata {
7777
GOOGLE_DCHECK(!is_message_owned || arena != nullptr);
7878
}
7979

80-
#if defined(NDEBUG) || defined(_MSC_VER)
80+
// To keep the ABI identical between debug and non-debug builds,
81+
// the destructor is always defined here even though it may delegate
82+
// to a non-inline private method.
83+
// (see https://github.com/protocolbuffers/protobuf/issues/9947)
8184
~InternalMetadata() {
85+
#if defined(NDEBUG) || defined(_MSC_VER)
8286
if (HasMessageOwnedArenaTag()) {
8387
delete reinterpret_cast<Arena*>(ptr_ - kMessageOwnedArenaTagMask);
8488
}
85-
}
8689
#else
87-
~InternalMetadata();
90+
CheckedDestruct();
8891
#endif
92+
}
8993

9094
template <typename T>
9195
void Delete() {
@@ -264,6 +268,9 @@ class PROTOBUF_EXPORT InternalMetadata {
264268
PROTOBUF_NOINLINE void DoSwap(T* other) {
265269
mutable_unknown_fields<T>()->Swap(other);
266270
}
271+
272+
// Private helper with debug checks for ~InternalMetadata()
273+
void CheckedDestruct();
267274
};
268275

269276
// String Template specializations.

0 commit comments

Comments
 (0)