mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Continue cleaning up after the GLOBALS experiment.
Change registration APIs to take ClassData* instead of prototypes. PiperOrigin-RevId: 970649058
This commit is contained in:
parent
3df019d491
commit
b445fe13b1
8 changed files with 56 additions and 50 deletions
|
|
@ -240,7 +240,7 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
(::_pbi::ExtensionSet::ShouldRegisterAtThisTime(
|
||||
{{&$extendee_table$, $extendee_index$}}, $preregister$)
|
||||
? ::_pbi::ExtensionSet::RegisterEnumExtension(
|
||||
::_pbi::GetPrototypeForWeakDescriptor(
|
||||
::_pbi::GetClassDataForWeakDescriptor(
|
||||
&$extendee_table$, $extendee_index$, true),
|
||||
$number$, $field_type$, $repeated$, $packed$,
|
||||
$enum_name$_internal_data_)
|
||||
|
|
@ -250,8 +250,9 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
p->Emit({{"enum_name", ClassName(descriptor_->enum_type(), true)}},
|
||||
R"cc(
|
||||
::_pbi::ExtensionSet::RegisterEnumExtension(
|
||||
&$extendee$::default_instance(), $number$, $field_type$,
|
||||
$repeated$, $packed$, $enum_name$_internal_data_),
|
||||
::_pbi::MessageTraits<$extendee$>::class_data(), $number$,
|
||||
$field_type$, $repeated$, $packed$,
|
||||
$enum_name$_internal_data_),
|
||||
)cc");
|
||||
}
|
||||
|
||||
|
|
@ -282,10 +283,10 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
{&$extension_table$, $extension_index$}},
|
||||
$preregister$)
|
||||
? ::_pbi::ExtensionSet::RegisterMessageExtension(
|
||||
::_pbi::GetPrototypeForWeakDescriptor(
|
||||
::_pbi::GetClassDataForWeakDescriptor(
|
||||
&$extendee_table$, $extendee_index$, true),
|
||||
$number$, $field_type$, $repeated$, $packed$,
|
||||
::_pbi::GetPrototypeForWeakDescriptor(
|
||||
::_pbi::GetClassDataForWeakDescriptor(
|
||||
&$extension_table$, $extension_index$, true),
|
||||
$verify_funcs$, ::_pbi::LazyAnnotation::$lazy$)
|
||||
: (void)0),
|
||||
|
|
@ -294,8 +295,9 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
p->Emit({{"verify_funcs", [&] { EmitVerifyFuncArgs(p, options_); }}},
|
||||
R"cc(
|
||||
::_pbi::ExtensionSet::RegisterMessageExtension(
|
||||
&$extendee$::default_instance(), $number$, $field_type$,
|
||||
$repeated$, $packed$, &$message_type$::default_instance(),
|
||||
::_pbi::MessageTraits<$extendee$>::class_data(), $number$,
|
||||
$field_type$, $repeated$, $packed$,
|
||||
::_pbi::MessageTraits<$message_type$>::class_data(),
|
||||
$verify_funcs$, ::_pbi::LazyAnnotation::$lazy$),
|
||||
)cc");
|
||||
}
|
||||
|
|
@ -308,7 +310,7 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
(::_pbi::ExtensionSet::ShouldRegisterAtThisTime(
|
||||
{{&$extendee_table$, $extendee_index$}}, $preregister$)
|
||||
? ::_pbi::ExtensionSet::RegisterExtension(
|
||||
::_pbi::GetPrototypeForWeakDescriptor(
|
||||
::_pbi::GetClassDataForWeakDescriptor(
|
||||
&$extendee_table$, $extendee_index$, true),
|
||||
$number$, $field_type$, $repeated$, $packed$)
|
||||
: (void)0),
|
||||
|
|
@ -317,8 +319,8 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p,
|
|||
p->Emit(
|
||||
R"cc(
|
||||
::_pbi::ExtensionSet::RegisterExtension(
|
||||
&$extendee$::default_instance(), $number$, $field_type$,
|
||||
$repeated$, $packed$, $is_utf8$),
|
||||
::_pbi::MessageTraits<$extendee$>::class_data(), $number$,
|
||||
$field_type$, $repeated$, $packed$, $is_utf8$),
|
||||
)cc");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -377,8 +377,9 @@ PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type
|
|||
_static_init2_ [[maybe_unused]] =
|
||||
(::_pbi::AddDescriptors(&descriptor_table_google_2fprotobuf_2fcompiler_2fcsharp_2fc_5fsharp_5ffeatures_2eproto),
|
||||
::_pbi::ExtensionSet::RegisterMessageExtension(
|
||||
&::google::protobuf::FeatureSet::default_instance(), 1004, 11,
|
||||
false, false, &::pb::CSharpFeatures::default_instance(),
|
||||
::_pbi::MessageTraits<::google::protobuf::FeatureSet>::class_data(), 1004,
|
||||
11, false, false,
|
||||
::_pbi::MessageTraits<::pb::CSharpFeatures>::class_data(),
|
||||
nullptr, ::_pbi::LazyAnnotation::kUndefined),
|
||||
::std::false_type{});
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
|
|
|
|||
|
|
@ -666,8 +666,9 @@ PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type
|
|||
_static_init2_ [[maybe_unused]] =
|
||||
(::_pbi::AddDescriptors(&descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto),
|
||||
::_pbi::ExtensionSet::RegisterMessageExtension(
|
||||
&::google::protobuf::FeatureSet::default_instance(), 1001, 11,
|
||||
false, false, &::pb::JavaFeatures::default_instance(),
|
||||
::_pbi::MessageTraits<::google::protobuf::FeatureSet>::class_data(), 1001,
|
||||
11, false, false,
|
||||
::_pbi::MessageTraits<::pb::JavaFeatures>::class_data(),
|
||||
nullptr, ::_pbi::LazyAnnotation::kUndefined),
|
||||
::std::false_type{});
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
|
|
|
|||
|
|
@ -135,42 +135,39 @@ bool GeneratedExtensionFinder::Find(int number, ExtensionInfo* output) {
|
|||
}
|
||||
}
|
||||
|
||||
void ExtensionSet::RegisterExtension(const MessageLite* extendee, int number,
|
||||
void ExtensionSet::RegisterExtension(const ClassData* extendee, int number,
|
||||
FieldType type, bool is_repeated,
|
||||
bool is_packed, bool is_utf8) {
|
||||
ABSL_CHECK_NE(type, WireFormatLite::TYPE_ENUM);
|
||||
ABSL_CHECK_NE(type, WireFormatLite::TYPE_MESSAGE);
|
||||
ABSL_CHECK_NE(type, WireFormatLite::TYPE_GROUP);
|
||||
ExtensionInfo info(extendee, number, type, is_repeated, is_packed, is_utf8);
|
||||
ExtensionInfo info(extendee->default_instance(), number, type, is_repeated,
|
||||
is_packed, is_utf8);
|
||||
Register(info);
|
||||
}
|
||||
|
||||
void ExtensionSet::RegisterEnumExtension(const MessageLite* extendee,
|
||||
int number, FieldType type,
|
||||
bool is_repeated, bool is_packed,
|
||||
void ExtensionSet::RegisterEnumExtension(const ClassData* extendee, int number,
|
||||
FieldType type, bool is_repeated,
|
||||
bool is_packed,
|
||||
const uint32_t* validation_data) {
|
||||
ABSL_CHECK_EQ(type, WireFormatLite::TYPE_ENUM);
|
||||
ExtensionInfo info(extendee, number, type, is_repeated, is_packed,
|
||||
/*is_utf8=*/false);
|
||||
ExtensionInfo info(extendee->default_instance(), number, type, is_repeated,
|
||||
is_packed, /*is_utf8=*/false);
|
||||
info.enum_validity_check.enum_data = validation_data;
|
||||
Register(info);
|
||||
}
|
||||
|
||||
// TODO: Change the registration function to take ClassData*
|
||||
// instead.
|
||||
void ExtensionSet::RegisterMessageExtension(const MessageLite* extendee,
|
||||
void ExtensionSet::RegisterMessageExtension(const ClassData* extendee,
|
||||
int number, FieldType type,
|
||||
bool is_repeated, bool is_packed,
|
||||
const MessageLite* prototype,
|
||||
const ClassData* inner_data,
|
||||
LazyEagerVerifyFnType verify_func,
|
||||
LazyAnnotation is_lazy) {
|
||||
ABSL_CHECK(type == WireFormatLite::TYPE_MESSAGE ||
|
||||
type == WireFormatLite::TYPE_GROUP);
|
||||
ExtensionInfo info(extendee, number, type, is_repeated, is_packed,
|
||||
verify_func, is_lazy);
|
||||
info.message_info = {
|
||||
&internal::MessageGlobalsBase::FromDefaultInstance(prototype)
|
||||
->class_data};
|
||||
ExtensionInfo info(extendee->default_instance(), number, type, is_repeated,
|
||||
is_packed, verify_func, is_lazy);
|
||||
info.message_info = {inner_data};
|
||||
Register(info);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ enum class LazyAnnotation : int8_t {
|
|||
};
|
||||
|
||||
// Information about a registered extension.
|
||||
// TODO: Change ExtensionInfo to hold a ClassData instead of a
|
||||
// prototype.
|
||||
struct ExtensionInfo {
|
||||
constexpr ExtensionInfo()
|
||||
: is_packed(false), is_utf8(false), enum_validity_check() {}
|
||||
|
|
@ -255,17 +257,17 @@ class PROTOBUF_EXPORT ExtensionSet {
|
|||
// to look up extensions for parsed field numbers. Note that dynamic parsing
|
||||
// does not use ParseField(); only protocol-compiler-generated parsing
|
||||
// methods do.
|
||||
static void RegisterExtension(const MessageLite* extendee, int number,
|
||||
static void RegisterExtension(const ClassData* extendee, int number,
|
||||
FieldType type, bool is_repeated,
|
||||
bool is_packed, bool is_utf8 = false);
|
||||
static void RegisterEnumExtension(const MessageLite* extendee, int number,
|
||||
static void RegisterEnumExtension(const ClassData* extendee, int number,
|
||||
FieldType type, bool is_repeated,
|
||||
bool is_packed,
|
||||
const uint32_t* validation_data);
|
||||
static void RegisterMessageExtension(const MessageLite* extendee, int number,
|
||||
static void RegisterMessageExtension(const ClassData* extendee, int number,
|
||||
FieldType type, bool is_repeated,
|
||||
bool is_packed,
|
||||
const MessageLite* prototype,
|
||||
const ClassData* inner_data,
|
||||
LazyEagerVerifyFnType verify_func,
|
||||
LazyAnnotation is_lazy);
|
||||
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ bool ExtensionSet::ShouldRegisterAtThisTime(
|
|||
std::initializer_list<WeakPrototypeRef> messages, bool is_preregistration) {
|
||||
bool has_all = true;
|
||||
for (auto ref : messages) {
|
||||
has_all = has_all && GetPrototypeForWeakDescriptor(ref.table, ref.index,
|
||||
has_all = has_all && GetClassDataForWeakDescriptor(ref.table, ref.index,
|
||||
false) != nullptr;
|
||||
}
|
||||
return has_all == is_preregistration;
|
||||
|
|
|
|||
|
|
@ -4036,21 +4036,23 @@ void AddDescriptorsImpl(const DescriptorTable* table) {
|
|||
// we hit data races and would need to add locks.
|
||||
[[maybe_unused]] static std::true_type lazy_register =
|
||||
(internal::ExtensionSet::RegisterMessageExtension(
|
||||
&FeatureSet::default_instance(), pb::cpp.number(),
|
||||
internal::MessageTraits<FeatureSet>::class_data(), pb::cpp.number(),
|
||||
FieldDescriptor::TYPE_MESSAGE, false, false,
|
||||
&pb::CppFeatures::default_instance(),
|
||||
internal::MessageTraits<pb::CppFeatures>::class_data(),
|
||||
nullptr,
|
||||
internal::LazyAnnotation::kUndefined),
|
||||
internal::ExtensionSet::RegisterMessageExtension(
|
||||
&FileOptions::default_instance(), pb::file::cpp.number(),
|
||||
FieldDescriptor::TYPE_MESSAGE, false, false,
|
||||
&pb::file::CppFileOptions::default_instance(),
|
||||
internal::MessageTraits<FileOptions>::class_data(),
|
||||
pb::file::cpp.number(), FieldDescriptor::TYPE_MESSAGE, false, false,
|
||||
internal::MessageTraits<pb::file::CppFileOptions>::class_data(),
|
||||
nullptr,
|
||||
internal::LazyAnnotation::kUndefined),
|
||||
internal::ExtensionSet::RegisterMessageExtension(
|
||||
&EnumValueOptions::default_instance(), pb::enumvalue::json.number(),
|
||||
FieldDescriptor::TYPE_MESSAGE, false, false,
|
||||
&pb::enumvalue::JsonEnumValueOptions::default_instance(),
|
||||
internal::MessageTraits<EnumValueOptions>::class_data(),
|
||||
pb::enumvalue::json.number(), FieldDescriptor::TYPE_MESSAGE, false,
|
||||
false,
|
||||
internal::MessageTraits<
|
||||
pb::enumvalue::JsonEnumValueOptions>::class_data(),
|
||||
nullptr,
|
||||
internal::LazyAnnotation::kUndefined),
|
||||
std::true_type{});
|
||||
|
|
@ -4175,14 +4177,14 @@ bool SplitFieldHasExtraIndirection(const FieldDescriptor* field) {
|
|||
}
|
||||
|
||||
#if defined(PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED)
|
||||
const Message* GetPrototypeForWeakDescriptor(const DescriptorTable* table,
|
||||
int index, bool force_build) {
|
||||
const ClassData* GetClassDataForWeakDescriptor(const DescriptorTable* table,
|
||||
int index, bool force_build) {
|
||||
// First, make sure we inject the surviving default instances.
|
||||
InitProtobufDefaults();
|
||||
|
||||
// Now check if the table has it. If so, return it.
|
||||
if (const auto* globals = table->message_globals[index]) {
|
||||
return MessageGlobalsBase::ToDefaultInstance<Message>(globals);
|
||||
return MessageGlobalsBase::GetClassData(globals);
|
||||
}
|
||||
|
||||
if (!force_build) {
|
||||
|
|
@ -4204,7 +4206,8 @@ const Message* GetPrototypeForWeakDescriptor(const DescriptorTable* table,
|
|||
return nullptr;
|
||||
});
|
||||
|
||||
return MessageFactory::generated_factory()->GetPrototype(descriptor);
|
||||
return internal::GetClassData(
|
||||
*MessageFactory::generated_factory()->GetPrototype(descriptor));
|
||||
}
|
||||
#endif // PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
|
||||
|
||||
|
|
|
|||
|
|
@ -320,12 +320,12 @@ struct PROTOBUF_EXPORT AddDescriptorsRunner {
|
|||
explicit AddDescriptorsRunner(const DescriptorTable* table);
|
||||
};
|
||||
|
||||
// Retrieves the existing prototype out of a descriptor table.
|
||||
// Retrieves the existing ClassData out of a descriptor table.
|
||||
// If it doesn't exist:
|
||||
// - If force_build is true, asks the generated message factory for one.
|
||||
// - Otherwise, return null
|
||||
const Message* GetPrototypeForWeakDescriptor(const DescriptorTable* table,
|
||||
int index, bool force_build);
|
||||
const ClassData* GetClassDataForWeakDescriptor(const DescriptorTable* table,
|
||||
int index, bool force_build);
|
||||
|
||||
struct DenseEnumCacheInfo {
|
||||
absl::once_flag loaded;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue