diff --git a/upb/port/def.inc b/upb/port/def.inc index b23b406992..dfcbce6a5a 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc @@ -302,3 +302,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #else #define UPB_DEPRECATED #endif + +// begin:google_only +// #define UPB_IS_GOOGLE3 +// end:google_only + +#if defined(UPB_IS_GOOGLE3) +#define UPB_DESC(sym) proto2_##sym +#else +#define UPB_DESC(sym) google_protobuf_##sym +#endif diff --git a/upb/port/undef.inc b/upb/port/undef.inc index 8b779502c6..fd201e321c 100644 --- a/upb/port/undef.inc +++ b/upb/port/undef.inc @@ -64,3 +64,5 @@ #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 #undef UPB_DEPRECATED #undef UPB_GNUC_MIN +#undef UPB_DESC +#undef UPB_IS_GOOGLE3 diff --git a/upb/reflection/def_builder_internal.h b/upb/reflection/def_builder_internal.h index f72b36c278..ad43135020 100644 --- a/upb/reflection/def_builder_internal.h +++ b/upb/reflection/def_builder_internal.h @@ -37,17 +37,17 @@ // We want to copy the options verbatim into the destination options proto. // We use serialize+parse as our deep copy. -#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (google_protobuf_##desc_type##_has_options(proto)) { \ - size_t size; \ - char* pb = google_protobuf_##options_type##_serialize( \ - google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = \ - google_protobuf_##options_type##_parse(pb, size, _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const google_protobuf_##options_type*)kUpbDefOptDefault; \ +#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ + if (UPB_DESC(desc_type##_has_options)(proto)) { \ + size_t size; \ + char* pb = UPB_DESC(options_type##_serialize)( \ + UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \ + if (!pb) _upb_DefBuilder_OomErr(ctx); \ + target = \ + UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \ + if (!target) _upb_DefBuilder_OomErr(ctx); \ + } else { \ + target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \ } #ifdef __cplusplus diff --git a/upb/reflection/def_pool.c b/upb/reflection/def_pool.c index a088873034..3f88dc5cd5 100644 --- a/upb/reflection/def_pool.c +++ b/upb/reflection/def_pool.c @@ -281,9 +281,9 @@ static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { } static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, + upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); + const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); if (name.size == 0) { upb_Status_SetErrorFormat(status, @@ -335,9 +335,10 @@ static const upb_FileDef* _upb_DefPool_AddFile( return ctx.file; } -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status) { +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status) { return _upb_DefPool_AddFile(s, file_proto, NULL, status); } @@ -346,7 +347,7 @@ bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, /* Since this function should never fail (it would indicate a bug in upb) we * print errors to stderr instead of returning error status to the user. */ _upb_DefPool_Init** deps = init->deps; - google_protobuf_FileDescriptorProto* file; + UPB_DESC(FileDescriptorProto) * file; upb_Arena* arena; upb_Status status; @@ -362,7 +363,7 @@ bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; } - file = google_protobuf_FileDescriptorProto_parse_ex( + file = UPB_DESC(FileDescriptorProto_parse_ex)( init->descriptor.data, init->descriptor.size, NULL, kUpb_DecodeOption_AliasString, arena); s->bytes_loaded += init->descriptor.size; diff --git a/upb/reflection/def_pool.h b/upb/reflection/def_pool.h index aef54ab356..157ff3aa83 100644 --- a/upb/reflection/def_pool.h +++ b/upb/reflection/def_pool.h @@ -87,9 +87,10 @@ const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, const char* name); -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status); +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status); const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( const upb_DefPool* s); diff --git a/upb/reflection/enum_def.c b/upb/reflection/enum_def.c index d3eb6af105..bb91a1efac 100644 --- a/upb/reflection/enum_def.c +++ b/upb/reflection/enum_def.c @@ -41,7 +41,7 @@ #include "upb/port/def.inc" struct upb_EnumDef { - const google_protobuf_EnumOptions* opts; + const UPB_DESC(EnumOptions) * opts; const upb_MiniTableEnum* layout; // Only for proto2. const upb_FileDef* file; const upb_MessageDef* containing_type; // Could be merged with "file". @@ -89,7 +89,7 @@ bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { return true; } -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { return e->opts; } @@ -237,10 +237,10 @@ static upb_StringView* _upb_EnumReservedNames_New( } static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumDescriptorProto* enum_proto, + const UPB_DESC(EnumDescriptorProto) * enum_proto, upb_EnumDef* e) { - const google_protobuf_EnumValueDescriptorProto* const* values; - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* res_ranges; + const UPB_DESC(EnumValueDescriptorProto)* const* values; + const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; const upb_StringView* res_names; upb_StringView name; size_t n_value, n_res_range, n_res_name; @@ -248,14 +248,14 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, // Must happen before _upb_DefBuilder_Add() e->file = _upb_DefBuilder_File(ctx); - name = google_protobuf_EnumDescriptorProto_name(enum_proto); + name = UPB_DESC(EnumDescriptorProto_name)(enum_proto); _upb_DefBuilder_CheckIdentNotFull(ctx, name); e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); _upb_DefBuilder_Add(ctx, e->full_name, _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n_value); + values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); @@ -274,11 +274,12 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, } res_ranges = - google_protobuf_EnumDescriptorProto_reserved_range(enum_proto, &n_res_range); + UPB_DESC(EnumDescriptorProto_reserved_range)(enum_proto, &n_res_range); e->res_range_count = n_res_range; e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); - res_names = google_protobuf_EnumDescriptorProto_reserved_name(enum_proto, &n_res_name); + res_names = + UPB_DESC(EnumDescriptorProto_reserved_name)(enum_proto, &n_res_name); e->res_name_count = n_res_name; e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); @@ -298,9 +299,10 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, } } -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type) { +upb_EnumDef* _upb_EnumDefs_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto) * const* protos, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); // If a containing type is defined then get the full name from that. diff --git a/upb/reflection/enum_def.h b/upb/reflection/enum_def.h index 20a07a9587..f115e88923 100644 --- a/upb/reflection/enum_def.h +++ b/upb/reflection/enum_def.h @@ -59,7 +59,7 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, upb_StringView* out); const char* upb_EnumDef_Name(const upb_EnumDef* e); -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e); upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); diff --git a/upb/reflection/enum_def_internal.h b/upb/reflection/enum_def_internal.h index 01529d6c32..41f9958683 100644 --- a/upb/reflection/enum_def_internal.h +++ b/upb/reflection/enum_def_internal.h @@ -42,9 +42,10 @@ bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); // Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type); +upb_EnumDef* _upb_EnumDefs_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto) * const* protos, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/enum_reserved_range.c b/upb/reflection/enum_reserved_range.c index ceda4cd071..f6e2268668 100644 --- a/upb/reflection/enum_reserved_range.c +++ b/upb/reflection/enum_reserved_range.c @@ -54,16 +54,16 @@ int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { upb_EnumReservedRange* _upb_EnumReservedRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, const upb_EnumDef* e) { upb_EnumReservedRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n); for (int i = 0; i < n; i++) { const int32_t start = - google_protobuf_EnumDescriptorProto_EnumReservedRange_start(protos[i]); + UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]); const int32_t end = - google_protobuf_EnumDescriptorProto_EnumReservedRange_end(protos[i]); + UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]); // A full validation would also check that each range is disjoint, and that // none of the fields overlap with the extension ranges, but we are just diff --git a/upb/reflection/enum_reserved_range_internal.h b/upb/reflection/enum_reserved_range_internal.h index e3aa2ede26..869f3b60ca 100644 --- a/upb/reflection/enum_reserved_range_internal.h +++ b/upb/reflection/enum_reserved_range_internal.h @@ -43,7 +43,7 @@ upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, // Allocate and initialize an array of |n| reserved ranges owned by |e|. upb_EnumReservedRange* _upb_EnumReservedRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, const upb_EnumDef* e); #ifdef __cplusplus diff --git a/upb/reflection/enum_value_def.c b/upb/reflection/enum_value_def.c index afa1f0d73a..70d2f1a45a 100644 --- a/upb/reflection/enum_value_def.c +++ b/upb/reflection/enum_value_def.c @@ -35,7 +35,7 @@ #include "upb/port/def.inc" struct upb_EnumValueDef { - const google_protobuf_EnumValueOptions* opts; + const UPB_DESC(EnumValueOptions) * opts; const upb_EnumDef* parent; const char* full_name; int32_t number; @@ -66,8 +66,8 @@ const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, return (const upb_EnumValueDef**)out; } -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v) { +const UPB_DESC(EnumValueOptions) * + upb_EnumValueDef_Options(const upb_EnumValueDef* v) { return v->opts; } @@ -95,13 +95,14 @@ uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { } static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumValueDescriptorProto* val_proto, + const UPB_DESC(EnumValueDescriptorProto) * + val_proto, upb_EnumDef* e, upb_EnumValueDef* v) { - upb_StringView name = google_protobuf_EnumValueDescriptorProto_name(val_proto); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); v->parent = e; // Must happen prior to _upb_DefBuilder_Add() v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); + v->number = UPB_DESC(EnumValueDescriptorProto_number)(val_proto); _upb_DefBuilder_Add(ctx, v->full_name, _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); @@ -115,7 +116,7 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); diff --git a/upb/reflection/enum_value_def.h b/upb/reflection/enum_value_def.h index fd43610d9f..9f01edbff0 100644 --- a/upb/reflection/enum_value_def.h +++ b/upb/reflection/enum_value_def.h @@ -45,8 +45,8 @@ bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v); uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v); const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v); +const UPB_DESC(EnumValueOptions) * + upb_EnumValueDef_Options(const upb_EnumValueDef* v); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/enum_value_def_internal.h b/upb/reflection/enum_value_def_internal.h index c073ce8885..09f0644da0 100644 --- a/upb/reflection/enum_value_def_internal.h +++ b/upb/reflection/enum_value_def_internal.h @@ -42,7 +42,7 @@ upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, bool* is_sorted); const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, diff --git a/upb/reflection/extension_range.c b/upb/reflection/extension_range.c index 25a4246023..d7dfebdd62 100644 --- a/upb/reflection/extension_range.c +++ b/upb/reflection/extension_range.c @@ -34,7 +34,7 @@ #include "upb/port/def.inc" struct upb_ExtensionRange { - const google_protobuf_ExtensionRangeOptions* opts; + const UPB_DESC(ExtensionRangeOptions) * opts; int32_t start; int32_t end; }; @@ -43,8 +43,8 @@ upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { return (upb_ExtensionRange*)&r[i]; } -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r) { +const UPB_DESC(ExtensionRangeOptions) * + upb_ExtensionRange_Options(const upb_ExtensionRange* r) { return r->opts; } @@ -60,19 +60,19 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, + const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, const upb_MessageDef* m) { upb_ExtensionRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); for (int i = 0; i < n; i++) { const int32_t start = - google_protobuf_DescriptorProto_ExtensionRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(protos[i]); - const int32_t max = - google_protobuf_MessageOptions_message_set_wire_format(upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; + UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); + const int32_t max = UPB_DESC(MessageOptions_message_set_wire_format)( + upb_MessageDef_Options(m)) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; // A full validation would also check that each range is disjoint, and that // none of the fields overlap with the extension ranges, but we are just diff --git a/upb/reflection/extension_range.h b/upb/reflection/extension_range.h index 004f9a8bb7..c8d56be504 100644 --- a/upb/reflection/extension_range.h +++ b/upb/reflection/extension_range.h @@ -43,8 +43,8 @@ int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r); +const UPB_DESC(ExtensionRangeOptions) * + upb_ExtensionRange_Options(const upb_ExtensionRange* r); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/extension_range_internal.h b/upb/reflection/extension_range_internal.h index 2aa643b03b..fde3d941f3 100644 --- a/upb/reflection/extension_range_internal.h +++ b/upb/reflection/extension_range_internal.h @@ -42,7 +42,7 @@ upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); // Allocate and initialize an array of |n| extension ranges owned by |m|. upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, + const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, const upb_MessageDef* m); #ifdef __cplusplus diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 11d5e403f5..ecf8e32b5c 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -52,7 +52,7 @@ typedef struct { } str_t; struct upb_FieldDef { - const google_protobuf_FieldOptions* opts; + const UPB_DESC(FieldOptions) * opts; const upb_FileDef* file; const upb_MessageDef* msgdef; const char* full_name; @@ -73,7 +73,7 @@ struct upb_FieldDef { union { const upb_MessageDef* msgdef; const upb_EnumDef* enumdef; - const google_protobuf_FieldDescriptorProto* unresolved; + const UPB_DESC(FieldDescriptorProto) * unresolved; } sub; uint32_t number_; uint16_t index_; @@ -94,7 +94,7 @@ upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { return (upb_FieldDef*)&f[i]; } -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f) { +const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f) { return f->opts; } @@ -549,22 +549,23 @@ static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { } static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, + const UPB_DESC(FieldDescriptorProto) * + field_proto, upb_MessageDef* m, upb_FieldDef* f) { // Must happen before _upb_DefBuilder_Add() f->file = _upb_DefBuilder_File(ctx); - if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { _upb_DefBuilder_Errf(ctx, "field has no name"); } - const upb_StringView name = google_protobuf_FieldDescriptorProto_name(field_proto); + const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); _upb_DefBuilder_CheckIdentNotFull(ctx, name); - f->has_json_name_ = google_protobuf_FieldDescriptorProto_has_json_name(field_proto); + f->has_json_name_ = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); if (f->has_json_name_) { const upb_StringView sv = - google_protobuf_FieldDescriptorProto_json_name(field_proto); + UPB_DESC(FieldDescriptorProto_json_name)(field_proto); f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); } else { f->json_name = make_json_name(name.data, name.size, ctx->arena); @@ -572,18 +573,18 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, if (!f->json_name) _upb_DefBuilder_OomErr(ctx); f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); - f->number_ = google_protobuf_FieldDescriptorProto_number(field_proto); + f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); + f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); f->proto3_optional_ = - google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); + UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto); f->msgdef = m; f->scope.oneof = NULL; - const bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); + const bool has_type = UPB_DESC(FieldDescriptorProto_has_type)(field_proto); const bool has_type_name = - google_protobuf_FieldDescriptorProto_has_type_name(field_proto); + UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); - f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); + f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto); if (has_type) { switch (f->type_) { @@ -628,8 +629,9 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, f->full_name); } - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - uint32_t oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + uint32_t oneof_index = + UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", @@ -654,8 +656,8 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - if (google_protobuf_FieldOptions_has_packed(f->opts)) { - f->is_packed_ = google_protobuf_FieldOptions_packed(f->opts); + if (UPB_DESC(FieldOptions_has_packed)(f->opts)) { + f->is_packed_ = UPB_DESC(FieldOptions_packed)(f->opts); } else { // Repeated fields default to packed for proto3 only. f->is_packed_ = upb_FieldDef_IsPrimitive(f) && @@ -664,14 +666,14 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, } } -static void _upb_FieldDef_CreateExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { +static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FieldDescriptorProto) * + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); f->is_extension_ = true; - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", f->full_name); } @@ -685,14 +687,14 @@ static void _upb_FieldDef_CreateExt( } } -static void _upb_FieldDef_CreateNotExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { +static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FieldDescriptorProto) * + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); f->is_extension_ = false; - if (!google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { + if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { if (f->proto3_optional_) { _upb_DefBuilder_Errf( ctx, @@ -719,7 +721,7 @@ static void _upb_FieldDef_CreateNotExt( upb_FieldDef* _upb_FieldDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, + const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, upb_MessageDef* m, bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = @@ -754,11 +756,9 @@ upb_FieldDef* _upb_FieldDefs_New( static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, upb_FieldDef* f) { - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; - upb_StringView name = - google_protobuf_FieldDescriptorProto_type_name(field_proto); - bool has_name = - google_protobuf_FieldDescriptorProto_has_type_name(field_proto); + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; + upb_StringView name = UPB_DESC(FieldDescriptorProto_type_name)(field_proto); + bool has_name = UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); switch ((int)f->type_) { case UPB_FIELD_TYPE_UNSPECIFIED: { // Type was not specified and must be inferred. @@ -843,13 +843,14 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { - if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { + const UPB_DESC(FieldDescriptorProto) * + field_proto) { + if (!UPB_DESC(FieldDescriptorProto_has_extendee)(field_proto)) { _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", f->full_name); } - upb_StringView name = google_protobuf_FieldDescriptorProto_extendee(field_proto); + upb_StringView name = UPB_DESC(FieldDescriptorProto_extendee)(field_proto); const upb_MessageDef* m = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); f->msgdef = m; @@ -889,12 +890,13 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, } static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { + const UPB_DESC(FieldDescriptorProto) * + field_proto) { // Have to delay resolving of the default value until now because of the enum // case, since enum defaults are specified with a label. - if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { + if (UPB_DESC(FieldDescriptorProto_has_default_value)(field_proto)) { upb_StringView defaultval = - google_protobuf_FieldDescriptorProto_default_value(field_proto); + UPB_DESC(FieldDescriptorProto_default_value)(field_proto); if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { _upb_DefBuilder_Errf(ctx, @@ -919,7 +921,7 @@ static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, upb_FieldDef* f) { // We have to stash this away since resolve_subdef() may overwrite it. - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; resolve_subdef(ctx, prefix, f); resolve_default(ctx, f, field_proto); diff --git a/upb/reflection/field_def.h b/upb/reflection/field_def.h index 6e4f5a24bf..4502162f32 100644 --- a/upb/reflection/field_def.h +++ b/upb/reflection/field_def.h @@ -78,7 +78,7 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); const char* upb_FieldDef_Name(const upb_FieldDef* f); uint32_t upb_FieldDef_Number(const upb_FieldDef* f); -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); +const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); diff --git a/upb/reflection/field_def_internal.h b/upb/reflection/field_def_internal.h index e2040aaab8..14ad9b69fd 100644 --- a/upb/reflection/field_def_internal.h +++ b/upb/reflection/field_def_internal.h @@ -51,7 +51,7 @@ void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, // Allocate and initialize an array of |n| field defs. upb_FieldDef* _upb_FieldDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, + const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, upb_MessageDef* m, bool* is_sorted); // Allocate and return a list of pointers to the |n| field defs in |ff|, diff --git a/upb/reflection/file_def.c b/upb/reflection/file_def.c index 91da5dfb92..cffee1cf94 100644 --- a/upb/reflection/file_def.c +++ b/upb/reflection/file_def.c @@ -37,7 +37,7 @@ #include "upb/port/def.inc" struct upb_FileDef { - const google_protobuf_FileOptions* opts; + const UPB_DESC(FileOptions) * opts; const char* name; const char* package; @@ -62,7 +62,7 @@ struct upb_FileDef { upb_Syntax syntax; }; -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { +const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { return f->opts; } @@ -164,13 +164,13 @@ static bool streql_view(upb_StringView view, const char* b) { return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; } -static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { +static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { size_t n; - google_protobuf_DescriptorProto_extension(msg_proto, &n); + UPB_DESC(DescriptorProto_extension)(msg_proto, &n); int ext_count = n; - const google_protobuf_DescriptorProto* const* nested_msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + const UPB_DESC(DescriptorProto)* const* nested_msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n); for (size_t i = 0; i < n; i++) { ext_count += count_exts_in_msg(nested_msgs[i]); } @@ -180,14 +180,14 @@ static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { // Allocate and initialize one file def, and add it to the context object. void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto) { + const UPB_DESC(FileDescriptorProto) * file_proto) { upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); ctx->file = file; - const google_protobuf_DescriptorProto* const* msgs; - const google_protobuf_EnumDescriptorProto* const* enums; - const google_protobuf_FieldDescriptorProto* const* exts; - const google_protobuf_ServiceDescriptorProto* const* services; + const UPB_DESC(DescriptorProto)* const* msgs; + const UPB_DESC(EnumDescriptorProto)* const* enums; + const UPB_DESC(FieldDescriptorProto)* const* exts; + const UPB_DESC(ServiceDescriptorProto)* const* services; const upb_StringView* strs; const int32_t* public_deps; const int32_t* weak_deps; @@ -196,9 +196,9 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, file->symtab = ctx->symtab; // Count all extensions in the file, to build a flat array of layouts. - google_protobuf_FileDescriptorProto_extension(file_proto, &n); + UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); int ext_count = n; - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); for (int i = 0; i < n; i++) { ext_count += count_exts_in_msg(msgs[i]); } @@ -223,13 +223,13 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, } } - if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) { + if (!UPB_DESC(FileDescriptorProto_has_name)(file_proto)) { _upb_DefBuilder_Errf(ctx, "File has no name"); } - file->name = strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); + file->name = strviewdup(ctx, UPB_DESC(FileDescriptorProto_name)(file_proto)); - upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); + upb_StringView package = UPB_DESC(FileDescriptorProto_package)(file_proto); if (package.size) { _upb_DefBuilder_CheckIdentFull(ctx, package); file->package = strviewdup(ctx, package); @@ -237,8 +237,8 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, file->package = NULL; } - if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { - upb_StringView syntax = google_protobuf_FileDescriptorProto_syntax(file_proto); + if (UPB_DESC(FileDescriptorProto_has_syntax)(file_proto)) { + upb_StringView syntax = UPB_DESC(FileDescriptorProto_syntax)(file_proto); if (streql_view(syntax, "proto2")) { file->syntax = kUpb_Syntax_Proto2; @@ -256,7 +256,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); // Verify dependencies. - strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); + strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); file->dep_count = n; file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); @@ -272,7 +272,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, } } - public_deps = google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); + public_deps = UPB_DESC(FileDescriptorProto_public_dependency)(file_proto, &n); file->public_dep_count = n; file->public_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); @@ -285,7 +285,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, mutable_public_deps[i] = public_deps[i]; } - weak_deps = google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); + weak_deps = UPB_DESC(FileDescriptorProto_weak_dependency)(file_proto, &n); file->weak_dep_count = n; file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; @@ -298,23 +298,23 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, } // Create enums. - enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); + enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); file->top_lvl_enum_count = n; file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); // Create extensions. - exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); + exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); file->top_lvl_ext_count = n; file->top_lvl_exts = _upb_FieldDefs_New(ctx, n, exts, file->package, NULL, NULL); // Create messages. - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); file->top_lvl_msg_count = n; file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); // Create services. - services = google_protobuf_FileDescriptorProto_service(file_proto, &n); + services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); file->service_count = n; file->services = _upb_ServiceDefs_New(ctx, n, services); diff --git a/upb/reflection/file_def.h b/upb/reflection/file_def.h index ebaa960f50..3d2abc69cf 100644 --- a/upb/reflection/file_def.h +++ b/upb/reflection/file_def.h @@ -43,7 +43,7 @@ const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); int upb_FileDef_DependencyCount(const upb_FileDef* f); bool upb_FileDef_HasOptions(const upb_FileDef* f); const char* upb_FileDef_Name(const upb_FileDef* f); -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); +const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f); const char* upb_FileDef_Package(const upb_FileDef* f); const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); diff --git a/upb/reflection/file_def_internal.h b/upb/reflection/file_def_internal.h index f58a18b1c9..1d29bb6fab 100644 --- a/upb/reflection/file_def_internal.h +++ b/upb/reflection/file_def_internal.h @@ -46,7 +46,7 @@ const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); const char* _upb_FileDef_RawPackage(const upb_FileDef* f); void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto); + const UPB_DESC(FileDescriptorProto) * file_proto); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/message_def.c b/upb/reflection/message_def.c index e947a7b7d6..a2b71c1852 100644 --- a/upb/reflection/message_def.c +++ b/upb/reflection/message_def.c @@ -44,7 +44,7 @@ #include "upb/port/def.inc" struct upb_MessageDef { - const google_protobuf_MessageOptions* opts; + const UPB_DESC(MessageOptions) * opts; const upb_MiniTable* layout; const upb_FileDef* file; const upb_MessageDef* containing_type; @@ -141,7 +141,8 @@ bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { return false; } -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m) { +const UPB_DESC(MessageOptions) * + upb_MessageDef_Options(const upb_MessageDef* m) { return m->opts; } @@ -255,6 +256,10 @@ int upb_MessageDef_OneofCount(const upb_MessageDef* m) { return m->oneof_count; } +int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { + return m->real_oneof_count; +} + int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { return m->nested_msg_count; } @@ -334,11 +339,11 @@ const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, } bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(m->opts); + return UPB_DESC(MessageOptions_map_entry)(m->opts); } bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format(m->opts); + return UPB_DESC(MessageOptions_message_set_wire_format)(m->opts); } static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, @@ -387,7 +392,7 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && upb_FieldDef_Label(ext) == kUpb_Label_Optional && upb_FieldDef_MessageSubDef(ext) == m && - google_protobuf_MessageOptions_message_set_wire_format( + UPB_DESC(MessageOptions_message_set_wire_format)( upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { m->in_message_set = true; } @@ -556,7 +561,7 @@ bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, if (upb_MessageDef_IsMapEntry(m)) { if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; - } else if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + } else if (UPB_DESC(MessageOptions_message_set_wire_format)(m->opts)) { if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; } else { if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; @@ -582,13 +587,13 @@ static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, } static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_DescriptorProto* msg_proto, + const UPB_DESC(DescriptorProto) * msg_proto, const upb_MessageDef* containing_type, upb_MessageDef* m) { - const google_protobuf_OneofDescriptorProto* const* oneofs; - const google_protobuf_FieldDescriptorProto* const* fields; - const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; - const google_protobuf_DescriptorProto_ReservedRange* const* res_ranges; + const UPB_DESC(OneofDescriptorProto)* const* oneofs; + const UPB_DESC(FieldDescriptorProto)* const* fields; + const UPB_DESC(DescriptorProto_ExtensionRange)* const* ext_ranges; + const UPB_DESC(DescriptorProto_ReservedRange)* const* res_ranges; const upb_StringView* res_names; size_t n_oneof, n_field, n_enum, n_ext, n_msg; size_t n_ext_range, n_res_range, n_res_name; @@ -600,17 +605,19 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, m->containing_type = containing_type; m->is_sorted = true; - name = google_protobuf_DescriptorProto_name(msg_proto); + name = UPB_DESC(DescriptorProto_name)(msg_proto); _upb_DefBuilder_CheckIdentNotFull(ctx, name); m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); - oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); - fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); - ext_ranges = google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); - res_ranges = google_protobuf_DescriptorProto_reserved_range(msg_proto, &n_res_range); - res_names = google_protobuf_DescriptorProto_reserved_name(msg_proto, &n_res_name); + oneofs = UPB_DESC(DescriptorProto_oneof_decl)(msg_proto, &n_oneof); + fields = UPB_DESC(DescriptorProto_field)(msg_proto, &n_field); + ext_ranges = + UPB_DESC(DescriptorProto_extension_range)(msg_proto, &n_ext_range); + res_ranges = + UPB_DESC(DescriptorProto_reserved_range)(msg_proto, &n_res_range); + res_names = UPB_DESC(DescriptorProto_reserved_name)(msg_proto, &n_res_name); bool ok = upb_inttable_init(&m->itof, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); @@ -639,7 +646,7 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); // Message Sets may not contain fields. - if (UPB_UNLIKELY(google_protobuf_MessageOptions_message_set_wire_format(m->opts))) { + if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { if (UPB_UNLIKELY(n_field > 0)) { _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); } @@ -661,25 +668,25 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, assign_msg_wellknowntype(m); upb_inttable_compact(&m->itof, ctx->arena); - const google_protobuf_EnumDescriptorProto* const* enums = - google_protobuf_DescriptorProto_enum_type(msg_proto, &n_enum); + const UPB_DESC(EnumDescriptorProto)* const* enums = + UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); m->nested_enum_count = n_enum; m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); - const google_protobuf_FieldDescriptorProto* const* exts = - google_protobuf_DescriptorProto_extension(msg_proto, &n_ext); + const UPB_DESC(FieldDescriptorProto)* const* exts = + UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); m->nested_ext_count = n_ext; m->nested_exts = _upb_FieldDefs_New(ctx, n_ext, exts, m->full_name, m, NULL); - const google_protobuf_DescriptorProto* const* msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n_msg); + const UPB_DESC(DescriptorProto)* const* msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); m->nested_msg_count = n_msg; m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); } // Allocate and initialize an array of |n| message defs. upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, + upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); diff --git a/upb/reflection/message_def.h b/upb/reflection/message_def.h index d47bf3386a..d1d9891c01 100644 --- a/upb/reflection/message_def.h +++ b/upb/reflection/message_def.h @@ -150,8 +150,10 @@ int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); int upb_MessageDef_OneofCount(const upb_MessageDef* m); +int upb_MessageDef_RealOneofCount(const upb_MessageDef* m); -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m); +const UPB_DESC(MessageOptions) * + upb_MessageDef_Options(const upb_MessageDef* m); upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); diff --git a/upb/reflection/message_def_internal.h b/upb/reflection/message_def_internal.h index ba96cc22b7..d83663a3eb 100644 --- a/upb/reflection/message_def_internal.h +++ b/upb/reflection/message_def_internal.h @@ -50,7 +50,7 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); // Allocate and initialize an array of |n| message defs. upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, + upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, const upb_MessageDef* containing_type); #ifdef __cplusplus diff --git a/upb/reflection/message_reserved_range.c b/upb/reflection/message_reserved_range.c index caf80dbc87..5b6bf00664 100644 --- a/upb/reflection/message_reserved_range.c +++ b/upb/reflection/message_reserved_range.c @@ -53,14 +53,15 @@ int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { upb_MessageReservedRange* _upb_MessageReservedRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ReservedRange* const* protos, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, const upb_MessageDef* m) { upb_MessageReservedRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageReservedRange) * n); for (int i = 0; i < n; i++) { - const int32_t start = google_protobuf_DescriptorProto_ReservedRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ReservedRange_end(protos[i]); + const int32_t start = + UPB_DESC(DescriptorProto_ReservedRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ReservedRange_end)(protos[i]); const int32_t max = kUpb_MaxFieldNumber + 1; // A full validation would also check that each range is disjoint, and that diff --git a/upb/reflection/message_reserved_range_internal.h b/upb/reflection/message_reserved_range_internal.h index 03e8a8ad76..37b10be24c 100644 --- a/upb/reflection/message_reserved_range_internal.h +++ b/upb/reflection/message_reserved_range_internal.h @@ -43,7 +43,7 @@ upb_MessageReservedRange* _upb_MessageReservedRange_At( // Allocate and initialize an array of |n| reserved ranges owned by |m|. upb_MessageReservedRange* _upb_MessageReservedRanges_New( upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ReservedRange* const* protos, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, const upb_MessageDef* m); #ifdef __cplusplus diff --git a/upb/reflection/method_def.c b/upb/reflection/method_def.c index 9a4971d5c2..7c4fd30d41 100644 --- a/upb/reflection/method_def.c +++ b/upb/reflection/method_def.c @@ -34,7 +34,7 @@ #include "upb/port/def.inc" struct upb_MethodDef { - const google_protobuf_MethodOptions* opts; + const UPB_DESC(MethodOptions) * opts; upb_ServiceDef* service; const char* full_name; const upb_MessageDef* input_type; @@ -52,7 +52,7 @@ const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { return m->service; } -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m) { +const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m) { return m->opts; } @@ -87,23 +87,25 @@ bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { } static void create_method(upb_DefBuilder* ctx, - const google_protobuf_MethodDescriptorProto* method_proto, + const UPB_DESC(MethodDescriptorProto) * method_proto, upb_ServiceDef* s, upb_MethodDef* m) { - upb_StringView name = google_protobuf_MethodDescriptorProto_name(method_proto); + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); m->service = s; m->full_name = _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); m->client_streaming = - google_protobuf_MethodDescriptorProto_client_streaming(method_proto); + UPB_DESC(MethodDescriptorProto_client_streaming)(method_proto); m->server_streaming = - google_protobuf_MethodDescriptorProto_server_streaming(method_proto); + UPB_DESC(MethodDescriptorProto_server_streaming)(method_proto); m->input_type = _upb_DefBuilder_Resolve( ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_input_type(method_proto), UPB_DEFTYPE_MSG); + UPB_DESC(MethodDescriptorProto_input_type)(method_proto), + UPB_DEFTYPE_MSG); m->output_type = _upb_DefBuilder_Resolve( ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_output_type(method_proto), UPB_DEFTYPE_MSG); + UPB_DESC(MethodDescriptorProto_output_type)(method_proto), + UPB_DEFTYPE_MSG); UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, method_proto); @@ -112,7 +114,7 @@ static void create_method(upb_DefBuilder* ctx, // Allocate and initialize an array of |n| method defs belonging to |s|. upb_MethodDef* _upb_MethodDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s) { + const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s) { upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); for (int i = 0; i < n; i++) { create_method(ctx, protos[i], s, &m[i]); diff --git a/upb/reflection/method_def.h b/upb/reflection/method_def.h index 3460886b1e..fdf0534db0 100644 --- a/upb/reflection/method_def.h +++ b/upb/reflection/method_def.h @@ -45,7 +45,7 @@ bool upb_MethodDef_HasOptions(const upb_MethodDef* m); int upb_MethodDef_Index(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m); +const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); diff --git a/upb/reflection/method_def_internal.h b/upb/reflection/method_def_internal.h index 1eeff262ea..c6629ff9f2 100644 --- a/upb/reflection/method_def_internal.h +++ b/upb/reflection/method_def_internal.h @@ -42,7 +42,7 @@ upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); // Allocate and initialize an array of |n| method defs owned by |s|. upb_MethodDef* _upb_MethodDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s); + const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/oneof_def.c b/upb/reflection/oneof_def.c index 869ffd1115..767bdc49cf 100644 --- a/upb/reflection/oneof_def.c +++ b/upb/reflection/oneof_def.c @@ -41,7 +41,7 @@ #include "upb/port/def.inc" struct upb_OneofDef { - const google_protobuf_OneofOptions* opts; + const UPB_DESC(OneofOptions) * opts; const upb_MessageDef* parent; const char* full_name; int field_count; @@ -58,7 +58,7 @@ upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { return (upb_OneofDef*)&o[i]; } -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o) { +const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o) { return o->opts; } @@ -164,10 +164,10 @@ size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { } static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const google_protobuf_OneofDescriptorProto* oneof_proto, + const UPB_DESC(OneofDescriptorProto) * oneof_proto, const upb_OneofDef* _o) { upb_OneofDef* o = (upb_OneofDef*)_o; - upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); o->parent = m; o->full_name = @@ -195,7 +195,7 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, // Allocate and initialize an array of |n| oneof defs. upb_OneofDef* _upb_OneofDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m) { + const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); diff --git a/upb/reflection/oneof_def.h b/upb/reflection/oneof_def.h index bd68273214..691b40e0fa 100644 --- a/upb/reflection/oneof_def.h +++ b/upb/reflection/oneof_def.h @@ -55,7 +55,7 @@ const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, uint32_t num); const char* upb_OneofDef_Name(const upb_OneofDef* o); int upb_OneofDef_numfields(const upb_OneofDef* o); -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/oneof_def_internal.h b/upb/reflection/oneof_def_internal.h index 807b558676..3a98c6739c 100644 --- a/upb/reflection/oneof_def_internal.h +++ b/upb/reflection/oneof_def_internal.h @@ -44,7 +44,7 @@ bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, // Allocate and initialize an array of |n| oneof defs owned by |m|. upb_OneofDef* _upb_OneofDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m); + const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m); size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); diff --git a/upb/reflection/service_def.c b/upb/reflection/service_def.c index b904aff61a..cdd3a889ef 100644 --- a/upb/reflection/service_def.c +++ b/upb/reflection/service_def.c @@ -35,7 +35,7 @@ #include "upb/port/def.inc" struct upb_ServiceDef { - const google_protobuf_ServiceOptions* opts; + const UPB_DESC(ServiceOptions) * opts; const upb_FileDef* file; const char* full_name; upb_MethodDef* methods; @@ -47,7 +47,8 @@ upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { return (upb_ServiceDef*)&s[index]; } -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s) { +const UPB_DESC(ServiceOptions) * + upb_ServiceDef_Options(const upb_ServiceDef* s) { return s->opts; } @@ -90,7 +91,7 @@ const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, } static void create_service(upb_DefBuilder* ctx, - const google_protobuf_ServiceDescriptorProto* svc_proto, + const UPB_DESC(ServiceDescriptorProto) * svc_proto, upb_ServiceDef* s) { upb_StringView name; size_t n; @@ -98,15 +99,15 @@ static void create_service(upb_DefBuilder* ctx, // Must happen before _upb_DefBuilder_Add() s->file = _upb_DefBuilder_File(ctx); - name = google_protobuf_ServiceDescriptorProto_name(svc_proto); + name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); _upb_DefBuilder_CheckIdentNotFull(ctx, name); const char* package = _upb_FileDef_RawPackage(s->file); s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); _upb_DefBuilder_Add(ctx, s->full_name, _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); - const google_protobuf_MethodDescriptorProto* const* methods = - google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); + const UPB_DESC(MethodDescriptorProto)* const* methods = + UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); s->method_count = n; s->methods = _upb_MethodDefs_New(ctx, n, methods, s); @@ -116,7 +117,7 @@ static void create_service(upb_DefBuilder* ctx, upb_ServiceDef* _upb_ServiceDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos) { + const UPB_DESC(ServiceDescriptorProto) * const* protos) { _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); diff --git a/upb/reflection/service_def.h b/upb/reflection/service_def.h index 5bedd07be0..7a8f25809f 100644 --- a/upb/reflection/service_def.h +++ b/upb/reflection/service_def.h @@ -48,7 +48,8 @@ int upb_ServiceDef_Index(const upb_ServiceDef* s); const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); const char* upb_ServiceDef_Name(const upb_ServiceDef* s); -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s); +const UPB_DESC(ServiceOptions) * + upb_ServiceDef_Options(const upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/service_def_internal.h b/upb/reflection/service_def_internal.h index 49201bb2f0..e79a93c190 100644 --- a/upb/reflection/service_def_internal.h +++ b/upb/reflection/service_def_internal.h @@ -42,7 +42,7 @@ upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); // Allocate and initialize an array of |n| service defs. upb_ServiceDef* _upb_ServiceDefs_New( upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos); + const UPB_DESC(ServiceDescriptorProto) * const* protos); #ifdef __cplusplus } /* extern "C" */