Internal change

PiperOrigin-RevId: 576883351
pull/14525/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 137e5984af
commit f69f40e3f6
  1. 3
      src/google/protobuf/extension_set.cc
  2. 16
      src/google/protobuf/extension_set.h
  3. 5
      src/google/protobuf/generated_message_reflection.cc

@ -11,6 +11,7 @@
#include "google/protobuf/extension_set.h"
#include <atomic>
#include <string>
#include <tuple>
#include <type_traits>
@ -1933,6 +1934,8 @@ LazyEagerVerifyFnType FindExtensionLazyEagerVerifyFn(
return nullptr;
}
std::atomic<ExtensionSet::LazyMessageExtension* (*)(Arena* arena)>
ExtensionSet::maybe_create_lazy_extension_;
} // namespace internal
} // namespace protobuf

@ -16,6 +16,7 @@
#define GOOGLE_PROTOBUF_EXTENSION_SET_H__
#include <algorithm>
#include <atomic>
#include <cassert>
#include <string>
#include <type_traits>
@ -57,6 +58,7 @@ class FeatureSet;
namespace internal {
class FieldSkipper; // wire_format_lite.h
class WireFormat;
void InitializeLazyExtensionSet();
} // namespace internal
} // namespace protobuf
} // namespace google
@ -508,6 +510,8 @@ class PROTOBUF_EXPORT ExtensionSet {
friend class google::protobuf::Reflection;
friend class google::protobuf::internal::WireFormat;
friend void internal::InitializeLazyExtensionSet();
const int32_t& GetRefInt32(int number, const int32_t& default_value) const;
const int64_t& GetRefInt64(int number, const int64_t& default_value) const;
const uint32_t& GetRefUInt32(int number, const uint32_t& default_value) const;
@ -579,7 +583,13 @@ class PROTOBUF_EXPORT ExtensionSet {
virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.
};
// Give access to function defined below to see LazyMessageExtension.
friend LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena);
static LazyMessageExtension* MaybeCreateLazyExtensionImpl(Arena* arena);
static LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena) {
auto* f = maybe_create_lazy_extension_.load(std::memory_order_relaxed);
return f != nullptr ? f(arena) : nullptr;
}
static std::atomic<LazyMessageExtension* (*)(Arena* arena)>
maybe_create_lazy_extension_;
struct Extension {
// The order of these fields packs Extension into 24 bytes when using 8
// byte alignment. Consider this when adding or removing fields here.
@ -1529,10 +1539,6 @@ class ExtensionIdentifier {
// Generated accessors
// Used to retrieve a lazy extension, may return nullptr in some environments.
extern PROTOBUF_ATTRIBUTE_WEAK ExtensionSet::LazyMessageExtension*
MaybeCreateLazyExtension(Arena* arena);
// Define a specialization of ExtensionIdentifier for bootstrapped extensions
// that we need to register lazily.
template <>

@ -16,6 +16,7 @@
#include <cstdint>
#include <cstring>
#include <string>
#include <type_traits>
#include "absl/base/call_once.h"
#include "absl/base/casts.h"
@ -93,6 +94,9 @@ void InitializeFileDescriptorDefaultInstances() {
#endif // !defined(PROTOBUF_CONSTINIT_DEFAULT_INSTANCES)
}
void InitializeLazyExtensionSet() {
}
bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name,
int* value) {
const EnumValueDescriptor* d = descriptor->FindValueByName(name);
@ -3660,6 +3664,7 @@ void AddDescriptorsImpl(const DescriptorTable* table) {
// Reflection refers to the default fields so make sure they are initialized.
internal::InitProtobufDefaults();
internal::InitializeFileDescriptorDefaultInstances();
internal::InitializeLazyExtensionSet();
// Ensure all dependent descriptors are registered to the generated descriptor
// pool and message factory.

Loading…
Cancel
Save