Use GetArena() instead of GetOwningArena() #1

PiperOrigin-RevId: 573311752
pull/14381/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 7eef3c906a
commit b458835fd6
  1. 4
      src/google/protobuf/arena_unittest.cc
  2. 12
      src/google/protobuf/compiler/cpp/message.cc
  3. 12
      src/google/protobuf/compiler/java/java_features.pb.h
  4. 48
      src/google/protobuf/compiler/plugin.pb.h
  5. 12
      src/google/protobuf/cpp_features.pb.h
  6. 384
      src/google/protobuf/descriptor.pb.h
  7. 5
      src/google/protobuf/extension_set.cc
  8. 22
      src/google/protobuf/generated_message_reflection.cc
  9. 4
      src/google/protobuf/generated_message_tctable_lite.cc

@ -723,7 +723,7 @@ TEST(ArenaTest, SetAllocatedAcrossArenasWithReflection) {
#if GTEST_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(
r->SetAllocatedMessage(arena1_message, arena2_submessage, msg_field),
"GetOwningArena");
"GetArena");
#endif
EXPECT_NE(arena2_submessage,
arena1_message->mutable_optional_nested_message());
@ -736,7 +736,7 @@ TEST(ArenaTest, SetAllocatedAcrossArenasWithReflection) {
#if GTEST_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(
r->SetAllocatedMessage(heap_message, arena1_submessage, msg_field),
"GetOwningArena");
"GetArena");
#endif
EXPECT_NE(arena1_submessage, heap_message->mutable_optional_nested_message());
delete heap_message;

@ -1297,9 +1297,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
"}\n"
"inline $classname$& operator=($classname$&& from) noexcept {\n"
" if (this == &from) return *this;\n"
" if (GetOwningArena() == from.GetOwningArena()\n"
" if (GetArena() == from.GetArena()\n"
"#ifdef PROTOBUF_FORCE_COPY_IN_MOVE\n"
" && GetOwningArena() != nullptr\n"
" && GetArena() != nullptr\n"
"#endif // !PROTOBUF_FORCE_COPY_IN_MOVE\n"
" ) {\n"
" InternalSwap(&from);\n"
@ -1459,10 +1459,10 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
"inline void Swap($classname$* other) {\n"
" if (other == this) return;\n"
"#ifdef PROTOBUF_FORCE_COPY_IN_SWAP\n"
" if (GetOwningArena() != nullptr &&\n"
" GetOwningArena() == other->GetOwningArena()) {\n "
" if (GetArena() != nullptr &&\n"
" GetArena() == other->GetArena()) {\n "
"#else // PROTOBUF_FORCE_COPY_IN_SWAP\n"
" if (GetOwningArena() == other->GetOwningArena()) {\n"
" if (GetArena() == other->GetArena()) {\n"
"#endif // !PROTOBUF_FORCE_COPY_IN_SWAP\n"
" InternalSwap(other);\n"
" } else {\n"
@ -1471,7 +1471,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
"}\n"
"void UnsafeArenaSwap($classname$* other) {\n"
" if (other == this) return;\n"
" $DCHK$(GetOwningArena() == other->GetOwningArena());\n"
" $DCHK$(GetArena() == other->GetArena());\n"
" InternalSwap(other);\n"
"}\n");

@ -125,9 +125,9 @@ class PROTOC_EXPORT JavaFeatures final :
}
inline JavaFeatures& operator=(JavaFeatures&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -171,10 +171,10 @@ class PROTOC_EXPORT JavaFeatures final :
inline void Swap(JavaFeatures* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -183,7 +183,7 @@ class PROTOC_EXPORT JavaFeatures final :
}
void UnsafeArenaSwap(JavaFeatures* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}

@ -142,9 +142,9 @@ class PROTOC_EXPORT Version final :
}
inline Version& operator=(Version&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -188,10 +188,10 @@ class PROTOC_EXPORT Version final :
inline void Swap(Version* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -200,7 +200,7 @@ class PROTOC_EXPORT Version final :
}
void UnsafeArenaSwap(Version* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@ -364,9 +364,9 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final :
}
inline CodeGeneratorResponse_File& operator=(CodeGeneratorResponse_File&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -410,10 +410,10 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final :
inline void Swap(CodeGeneratorResponse_File* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -422,7 +422,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final :
}
void UnsafeArenaSwap(CodeGeneratorResponse_File* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@ -602,9 +602,9 @@ class PROTOC_EXPORT CodeGeneratorResponse final :
}
inline CodeGeneratorResponse& operator=(CodeGeneratorResponse&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -648,10 +648,10 @@ class PROTOC_EXPORT CodeGeneratorResponse final :
inline void Swap(CodeGeneratorResponse* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -660,7 +660,7 @@ class PROTOC_EXPORT CodeGeneratorResponse final :
}
void UnsafeArenaSwap(CodeGeneratorResponse* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@ -841,9 +841,9 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
}
inline CodeGeneratorRequest& operator=(CodeGeneratorRequest&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -887,10 +887,10 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
inline void Swap(CodeGeneratorRequest* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -899,7 +899,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
}
void UnsafeArenaSwap(CodeGeneratorRequest* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}

@ -94,9 +94,9 @@ class PROTOBUF_EXPORT CppFeatures final :
}
inline CppFeatures& operator=(CppFeatures&& from) noexcept {
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()
if (GetArena() == from.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetOwningArena() != nullptr
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from);
@ -140,10 +140,10 @@ class PROTOBUF_EXPORT CppFeatures final :
inline void Swap(CppFeatures* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
if (GetArena() != nullptr &&
GetArena() == other->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
if (GetArena() == other->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
@ -152,7 +152,7 @@ class PROTOBUF_EXPORT CppFeatures final :
}
void UnsafeArenaSwap(CppFeatures* other) {
if (other == this) return;
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
ABSL_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}

File diff suppressed because it is too large Load Diff

@ -626,9 +626,8 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
ClearExtension(number);
return;
}
ABSL_DCHECK(message->GetOwningArena() == nullptr ||
message->GetOwningArena() == arena_);
Arena* message_arena = message->GetOwningArena();
ABSL_DCHECK(message->GetArena() == nullptr || message->GetArena() == arena_);
Arena* message_arena = message->GetArena();
Extension* extension;
if (MaybeNewExtension(number, descriptor, &extension)) {
extension->type = type;

@ -1064,16 +1064,16 @@ void Reflection::Swap(Message* message1, Message* message2) const {
// Check that both messages are in the same arena (or both on the heap). We
// need to copy all data if not, due to ownership semantics.
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (message1->GetOwningArena() == nullptr ||
message1->GetOwningArena() != message2->GetOwningArena()) {
if (message1->GetArena() == nullptr ||
message1->GetArena() != message2->GetArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (message1->GetOwningArena() != message2->GetOwningArena()) {
if (message1->GetArena() != message2->GetArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
// One of the two is guaranteed to have an arena. Switch things around
// to guarantee that message1 has an arena.
Arena* arena = message1->GetOwningArena();
Arena* arena = message1->GetArena();
if (arena == nullptr) {
arena = message2->GetOwningArena();
arena = message2->GetArena();
std::swap(message1, message2); // Swapping names for pointers!
}
@ -1203,7 +1203,7 @@ bool Reflection::HasField(const Message& message,
}
void Reflection::UnsafeArenaSwap(Message* lhs, Message* rhs) const {
ABSL_DCHECK_EQ(lhs->GetOwningArena(), rhs->GetOwningArena());
ABSL_DCHECK_EQ(lhs->GetArena(), rhs->GetArena());
InternalSwap(lhs, rhs);
}
@ -2311,17 +2311,15 @@ void Reflection::UnsafeArenaSetAllocatedMessage(
void Reflection::SetAllocatedMessage(Message* message, Message* sub_message,
const FieldDescriptor* field) const {
ABSL_DCHECK(sub_message == nullptr ||
sub_message->GetOwningArena() == nullptr ||
sub_message->GetOwningArena() == message->GetArena());
ABSL_DCHECK(sub_message == nullptr || sub_message->GetArena() == nullptr ||
sub_message->GetArena() == message->GetArena());
// If message and sub-message are in different memory ownership domains
// (different arenas, or one is on heap and one is not), then we may need to
// do a copy.
if (sub_message != nullptr &&
sub_message->GetOwningArena() != message->GetArena()) {
if (sub_message->GetOwningArena() == nullptr &&
message->GetArena() != nullptr) {
sub_message->GetArena() != message->GetArena()) {
if (sub_message->GetArena() == nullptr && message->GetArena() != nullptr) {
// Case 1: parent is on an arena and child is heap-allocated. We can add
// the child to the arena's Own() list to free on arena destruction, then
// set our pointer.

@ -1557,7 +1557,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedString(
}
};
auto* arena = field.GetOwningArena();
auto* arena = field.GetArena();
SerialArena* serial_arena;
if (PROTOBUF_PREDICT_TRUE(arena != nullptr &&
arena->impl_.GetSerialArenaFast(&serial_arena) &&
@ -2260,7 +2260,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpRepeatedString(
const char* ptr2 = ptr;
uint32_t next_tag;
auto* arena = field.GetOwningArena();
auto* arena = field.GetArena();
SerialArena* serial_arena;
if (PROTOBUF_PREDICT_TRUE(
arena != nullptr &&

Loading…
Cancel
Save