From 4a01577ccea85142bc83d5b5da2d1e13eb81ec1a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 17:25:30 -0800 Subject: [PATCH 1/2] Two fixes to upb/def.c 1. Be tolerant of messages that extend more than one message set. 2. Implemented missing upb_MethodDef_Index() method. --- upb/def.c | 19 +++++++++++-------- upb/def.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/upb/def.c b/upb/def.c index 6b70263991..4a17c9c4d2 100644 --- a/upb/def.c +++ b/upb/def.c @@ -188,6 +188,7 @@ struct upb_MethodDef { const char* full_name; const upb_MessageDef* input_type; const upb_MessageDef* output_type; + int index; bool client_streaming; bool server_streaming; }; @@ -980,6 +981,10 @@ const char* upb_MethodDef_FullName(const upb_MethodDef* m) { return m->full_name; } +int upb_MethodDef_Index(const upb_MethodDef* m) { + return m->index; +} + const char* upb_MethodDef_Name(const upb_MethodDef* m) { return shortdefname(m->full_name); } @@ -2382,6 +2387,7 @@ static void create_service( m->service = s; m->full_name = makefullname(ctx, s->full_name, name); + m->index = i; m->client_streaming = google_protobuf_MethodDescriptorProto_client_streaming(method_proto); m->server_streaming = @@ -2810,15 +2816,10 @@ static void resolve_msgdef(symtab_addctx* ctx, upb_MessageDef* m) { resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->fields[i]); } - for (int i = 0; i < m->nested_ext_count; i++) { - resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->nested_exts[i]); - } - - if (!ctx->layout) make_layout(ctx, m); - m->in_message_set = false; - if (m->nested_ext_count == 1) { - const upb_FieldDef* ext = &m->nested_exts[0]; + for (int i = 0; i < m->nested_ext_count; i++) { + upb_FieldDef* ext = (upb_FieldDef*)&m->nested_exts[i]; + resolve_fielddef(ctx, m->full_name, ext); if (ext->type_ == kUpb_FieldType_Message && ext->label_ == kUpb_Label_Optional && ext->sub.msgdef == m && google_protobuf_MessageOptions_message_set_wire_format( @@ -2827,6 +2828,8 @@ static void resolve_msgdef(symtab_addctx* ctx, upb_MessageDef* m) { } } + if (!ctx->layout) make_layout(ctx, m); + for (int i = 0; i < m->nested_msg_count; i++) { resolve_msgdef(ctx, (upb_MessageDef*)&m->nested_msgs[i]); } diff --git a/upb/def.h b/upb/def.h index 2d22896e89..1c7adb4b15 100644 --- a/upb/def.h +++ b/upb/def.h @@ -317,6 +317,7 @@ const google_protobuf_MethodOptions* upb_MethodDef_Options( const upb_MethodDef* m); bool upb_MethodDef_HasOptions(const upb_MethodDef* m); const char* upb_MethodDef_FullName(const upb_MethodDef* m); +int upb_MethodDef_Index(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); From 6d2ab885bed3aae554724213160f0a2827410f13 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 17:29:31 -0800 Subject: [PATCH 2/2] Fix clang-format. --- upb/def.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/upb/def.c b/upb/def.c index 4a17c9c4d2..8ae873db4a 100644 --- a/upb/def.c +++ b/upb/def.c @@ -981,9 +981,7 @@ const char* upb_MethodDef_FullName(const upb_MethodDef* m) { return m->full_name; } -int upb_MethodDef_Index(const upb_MethodDef* m) { - return m->index; -} +int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } const char* upb_MethodDef_Name(const upb_MethodDef* m) { return shortdefname(m->full_name);