From 72275ded70de429e5305a99832c9dee16b1e0caf Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 15 Jan 2024 23:27:46 -0800 Subject: [PATCH] upb: move upb_Message definition back into upb/message/ PiperOrigin-RevId: 598741329 --- upb/BUILD | 3 +++ upb/message/BUILD | 16 ++++++++++++++++ upb/message/internal/accessors.h | 1 + upb/message/internal/extension.c | 1 + upb/{mini_table => message}/internal/map_entry.h | 8 ++++---- upb/message/internal/map_sorter.h | 2 +- upb/message/internal/message.c | 1 + upb/message/internal/message.h | 5 ++--- upb/{mini_table => message}/internal/types.h | 10 +++------- upb/message/message.c | 1 + upb/mini_descriptor/BUILD | 1 + upb/mini_descriptor/decode.c | 4 ++-- upb/mini_table/BUILD | 3 +-- upb/mini_table/internal/message.c | 2 +- upb/mini_table/internal/message.h | 2 +- .../stage0/google/protobuf/descriptor.upb.h | 2 +- upb/text/BUILD | 2 +- upb/text/encode.c | 2 +- upb/wire/BUILD | 1 + upb/wire/decode.c | 2 +- upb/wire/encode.c | 2 +- 21 files changed, 45 insertions(+), 26 deletions(-) rename upb/{mini_table => message}/internal/map_entry.h (87%) rename upb/{mini_table => message}/internal/types.h (56%) diff --git a/upb/BUILD b/upb/BUILD index 44476c167c..c5497b249e 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -281,6 +281,7 @@ upb_amalgamation( "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", + "//upb/message:types", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", "//upb/reflection:internal", @@ -326,6 +327,7 @@ upb_amalgamation( "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", + "//upb/message:types", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", "//upb/reflection:internal", @@ -372,6 +374,7 @@ upb_amalgamation( "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", + "//upb/message:types", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", "//upb/reflection:internal", diff --git a/upb/message/BUILD b/upb/message/BUILD index 85e00f780f..763b36d042 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -40,6 +40,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":internal", + ":types", "//upb:base", "//upb:mem", "//upb:mini_table", @@ -67,6 +68,7 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":types", "//upb:base", "//upb:mem", "//upb:mini_table", @@ -155,6 +157,20 @@ cc_library( ], ) +cc_library( + name = "types", + hdrs = [ + "internal/map_entry.h", + "internal/types.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + "//upb:base", + "//upb/hash", + ], +) + proto_library( name = "message_test_proto", testonly = 1, diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 2519b1a98d..ef26b8b61c 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -19,6 +19,7 @@ #include "upb/message/internal/map.h" #include "upb/message/internal/message.h" #include "upb/message/internal/tagged_ptr.h" +#include "upb/message/internal/types.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" diff --git a/upb/message/internal/extension.c b/upb/message/internal/extension.c index 981bcd3ce2..b8392424be 100644 --- a/upb/message/internal/extension.c +++ b/upb/message/internal/extension.c @@ -12,6 +12,7 @@ #include "upb/mem/arena.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" +#include "upb/message/internal/types.h" #include "upb/mini_table/extension.h" // Must be last. diff --git a/upb/mini_table/internal/map_entry.h b/upb/message/internal/map_entry.h similarity index 87% rename from upb/mini_table/internal/map_entry.h rename to upb/message/internal/map_entry.h index 1cbb84215a..5a0b52493c 100644 --- a/upb/mini_table/internal/map_entry.h +++ b/upb/message/internal/map_entry.h @@ -5,14 +5,14 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_H_ -#define UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ +#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ #include #include "upb/base/string_view.h" #include "upb/hash/common.h" -#include "upb/mini_table/internal/types.h" +#include "upb/message/internal/types.h" // Map entries aren't actually stored for map fields, they are only used during // parsing. (It helps a lot if all map entry messages have the same layout.) @@ -38,4 +38,4 @@ typedef struct { } v; } upb_MapEntry; -#endif // UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_H_ +#endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h index c6c0ec65b6..08f34d2b7d 100644 --- a/upb/message/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -17,7 +17,7 @@ #include "upb/mem/alloc.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" -#include "upb/mini_table/internal/map_entry.h" +#include "upb/message/internal/map_entry.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/internal/message.c b/upb/message/internal/message.c index b9378834e5..76f4e3fe5a 100644 --- a/upb/message/internal/message.c +++ b/upb/message/internal/message.c @@ -12,6 +12,7 @@ #include "upb/base/internal/log2.h" #include "upb/mem/arena.h" +#include "upb/message/internal/types.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index 01cda184f4..dcabf56c05 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -20,7 +20,6 @@ #include "upb/mem/arena.h" #include "upb/message/internal/extension.h" -#include "upb/mini_table/internal/types.h" #include "upb/mini_table/message.h" // Must be last. @@ -56,8 +55,8 @@ typedef struct upb_Message_Internal { * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ uint32_t unknown_end; uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_Internal)]; */ + // Data follows, as if there were an array: + // char data[size - sizeof(upb_Message_Internal)]; } upb_Message_Internal; // Inline version upb_Message_New(), for internal use. diff --git a/upb/mini_table/internal/types.h b/upb/message/internal/types.h similarity index 56% rename from upb/mini_table/internal/types.h rename to upb/message/internal/types.h index 02efbb12cf..3c4bb28b6f 100644 --- a/upb/mini_table/internal/types.h +++ b/upb/message/internal/types.h @@ -5,12 +5,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -// This definition exists here (instead of in upb/message/) as an optimization -// so that minitable code can cleanly know the size of a upb_Message - which is -// also the minimum size of a minitable. +#ifndef UPB_MESSAGE_INTERNAL_TYPES_H_ +#define UPB_MESSAGE_INTERNAL_TYPES_H_ struct upb_Message { union { @@ -19,4 +15,4 @@ struct upb_Message { }; }; -#endif /* UPB_MINI_TABLE_INTERNAL_TYPES_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */ diff --git a/upb/message/message.c b/upb/message/message.c index 148f4c3208..47c24f82a5 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -13,6 +13,7 @@ #include "upb/mem/arena.h" #include "upb/message/internal/message.h" +#include "upb/message/internal/types.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index a397e901e3..29e2edfa96 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -25,6 +25,7 @@ cc_library( "//upb:mini_table", "//upb:port", "//upb/base:internal", + "//upb/message:types", "//upb/mini_table:internal", ], ) diff --git a/upb/mini_descriptor/decode.c b/upb/mini_descriptor/decode.c index de1b932e25..bd666c1de2 100644 --- a/upb/mini_descriptor/decode.c +++ b/upb/mini_descriptor/decode.c @@ -17,6 +17,8 @@ #include "upb/base/status.h" #include "upb/base/string_view.h" #include "upb/mem/arena.h" +#include "upb/message/internal/map_entry.h" +#include "upb/message/internal/types.h" #include "upb/mini_descriptor/internal/base92.h" #include "upb/mini_descriptor/internal/decoder.h" #include "upb/mini_descriptor/internal/modifiers.h" @@ -24,9 +26,7 @@ #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/map_entry.h" #include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/types.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 1abc8ff4c8..ad30b4addc 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -46,11 +46,9 @@ cc_library( "internal/extension.h", "internal/field.h", "internal/file.h", - "internal/map_entry.h", "internal/message.h", "internal/size_log2.h", "internal/sub.h", - "internal/types.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], @@ -59,6 +57,7 @@ cc_library( "//upb:mem", "//upb:port", "//upb/hash", + "//upb/message:types", ], ) diff --git a/upb/mini_table/internal/message.c b/upb/mini_table/internal/message.c index 8eea39eab1..f278b36577 100644 --- a/upb/mini_table/internal/message.c +++ b/upb/mini_table/internal/message.c @@ -9,7 +9,7 @@ #include -#include "upb/mini_table/internal/types.h" +#include "upb/message/internal/types.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index a5bfb34591..95244233c9 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -12,12 +12,12 @@ #include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/internal/types.h" // Must be last. #include "upb/port/def.inc" struct upb_Decoder; +struct upb_Message; typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, struct upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data); diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index efd2e35171..0d431c768f 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -6532,7 +6532,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google /* Max size 32 is google.protobuf.FileOptions */ /* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) +#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/text/BUILD b/upb/text/BUILD index dc40fb570e..c036e1c849 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -27,7 +27,7 @@ cc_library( "//upb:wire_reader", "//upb/lex", "//upb/message:internal", - "//upb/mini_table:internal", + "//upb/message:types", ], ) diff --git a/upb/text/encode.c b/upb/text/encode.c index 03107447e8..7df42218bf 100644 --- a/upb/text/encode.c +++ b/upb/text/encode.c @@ -18,11 +18,11 @@ #include "upb/base/string_view.h" #include "upb/lex/round_trip.h" #include "upb/message/array.h" +#include "upb/message/internal/map_entry.h" #include "upb/message/internal/map_sorter.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/value.h" -#include "upb/mini_table/internal/map_entry.h" #include "upb/port/vsnprintf_compat.h" #include "upb/reflection/def.h" #include "upb/reflection/message.h" diff --git a/upb/wire/BUILD b/upb/wire/BUILD index f655d64b9c..9dfd3b6439 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -36,6 +36,7 @@ cc_library( "//upb/hash", "//upb/mem:internal", "//upb/message:internal", + "//upb/message:types", "//upb/mini_table:internal", ], ) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 07e48cb1f0..4bc0cd9e65 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -23,6 +23,7 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" +#include "upb/message/internal/map_entry.h" #include "upb/message/internal/message.h" #include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" @@ -33,7 +34,6 @@ #include "upb/mini_table/extension_registry.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/map_entry.h" #include "upb/mini_table/internal/message.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" diff --git a/upb/wire/encode.c b/upb/wire/encode.c index d425b299c1..bb33934efb 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -25,6 +25,7 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" +#include "upb/message/internal/map_entry.h" #include "upb/message/internal/map_sorter.h" #include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" @@ -33,7 +34,6 @@ #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/map_entry.h" #include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h"