From 7eef3c906a068014dcf901a95835b8529f5776ae Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 13 Oct 2023 12:26:55 -0700 Subject: [PATCH] Assert equality between InternalGetArena() and InternalGetOwningArena(). PiperOrigin-RevId: 573291278 --- src/google/protobuf/arena.h | 8 ++++++-- src/google/protobuf/repeated_field.h | 1 + src/google/protobuf/repeated_ptr_field.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 10ce61b3c8..ffc9cb1608 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -26,7 +26,7 @@ using type_info = ::type_info; #include #endif -#include "absl/meta/type_traits.h" +#include "absl/log/absl_check.h" #include "google/protobuf/arena_align.h" #include "google/protobuf/port.h" #include "google/protobuf/serial_arena.h" @@ -461,7 +461,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // Provides access to protected GetOwningArena to generated messages. For // internal use only. template - static Arena* InternalGetOwningArena(const T* p) { + static Arena* InternalGetOwningArena(T* p) { + ABSL_DCHECK_EQ(InternalHelper::GetOwningArena(p), + InternalHelper::GetArena(p)); return InternalHelper::GetOwningArena(p); } @@ -476,6 +478,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // For internal use only. template static Arena* InternalGetArena(T* p) { + ABSL_DCHECK_EQ(InternalHelper::GetOwningArena(p), + InternalHelper::GetArena(p)); return InternalHelper::GetArena(p); } diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 4b15be2630..ed3233b1e7 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -333,6 +333,7 @@ class RepeatedField final : rep()->arena; } + // Swaps entire contents with "other". Should be called only if the caller can // guarantee that both repeated fields are on the same arena or are on the // heap. Swapping between different arenas is disallowed and caught by a diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 6bf4b3e133..85a20dad27 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -1323,6 +1323,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // Internal version of GetArena(). inline Arena* GetOwningArena() const; + // Implementations for ExtractSubrange(). The copying behavior must be // included only if the type supports the necessary operations (e.g., // MergeFrom()), so we must resolve this at compile time. ExtractSubrange()