Replace PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION macro with constexpr function for easier maintenance.

No semantic change expected.

PiperOrigin-RevId: 675981595
pull/18369/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 4c923285a3
commit 26df3c0e8b
  1. 7
      src/google/protobuf/compiler/cpp/message.cc
  2. 4
      src/google/protobuf/port.h
  3. 4
      src/google/protobuf/port_def.inc
  4. 1
      src/google/protobuf/port_undef.inc

@ -3276,10 +3276,9 @@ void MessageGenerator::GenerateArenaEnabledCopyConstructor(io::Printer* p) {
auto force_allocation = [&] {
if (ShouldForceAllocationOnConstruction(descriptor_, options_)) {
p->Emit(R"cc(
//~ force alignment
#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
$mutable_unknown_fields$;
#endif // PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
if ($pbi$::DebugHardenForceAllocationOnConstruction()) {
$mutable_unknown_fields$;
}
)cc");
}
};

@ -281,6 +281,10 @@ constexpr bool DebugHardenForceCopyInMove() {
return false;
}
constexpr bool DebugHardenForceAllocationOnConstruction() {
return false;
}
constexpr bool DebugHardenFuzzMessageSpaceUsedLong() {
return false;
}

@ -398,10 +398,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#define PROTOBUF_RESTRICT
#endif
#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
#error PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION was previously defined
#endif
// Specify memory alignment for structs, classes, etc.
// Use like:
// class PROTOBUF_ALIGNAS(16) MyClass { ... }

@ -41,7 +41,6 @@
#undef PROTOC_EXPORT
#undef PROTOBUF_NODISCARD
#undef PROTOBUF_RESTRICT
#undef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
#undef PROTOBUF_UNUSED
#undef PROTOBUF_ASSUME
#undef PROTOBUF_DEPRECATE_AND_INLINE

Loading…
Cancel
Save