diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index f194fadf9e..fc1ac2e09f 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -258,6 +258,16 @@ using IntT = int; template using PointerT = T*; +// State that we gather during EstimatedMemoryUsed while on the lock, but we +// will use outside the lock. +struct EstimatedMemoryUsedState { + // We can't call SpaceUsed under the lock because it uses reflection and can + // potentially deadlock if it requires to load new files into the pool. + // NOTE: Messages added here must not be modified or destroyed outside the + // lock while the pool is alive. + std::vector messages; +}; + // Manages an allocation of sequential arrays of type `T...`. // It is more space efficient than storing N (ptr, size) pairs, by storing only // the pointer to the head and the boundaries between the arrays. diff --git a/src/google/protobuf/late_loaded_option.proto b/src/google/protobuf/late_loaded_option.proto new file mode 100644 index 0000000000..6fc30166f1 --- /dev/null +++ b/src/google/protobuf/late_loaded_option.proto @@ -0,0 +1,13 @@ +edition = "2023"; + +package protobuf_unittest; + +import "google/protobuf/descriptor.proto"; + +message LateLoadedOption { + int32 value = 1; + + extend google.protobuf.MessageOptions { + LateLoadedOption ext = 95126892; + } +} diff --git a/src/google/protobuf/late_loaded_option_user.proto b/src/google/protobuf/late_loaded_option_user.proto new file mode 100644 index 0000000000..f969af216a --- /dev/null +++ b/src/google/protobuf/late_loaded_option_user.proto @@ -0,0 +1,11 @@ +edition = "2023"; + +package protobuf_unittest; + +import "google/protobuf/late_loaded_option.proto"; + +message LateLoadedOptionUser { + option (protobuf_unittest.LateLoadedOption.ext) = { + value: 1 + }; +}