diff --git a/BUILD b/BUILD index 693cfc5e22..e09cd8ca93 100644 --- a/BUILD +++ b/BUILD @@ -169,7 +169,6 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":descriptor_upb_proto", ":mini_table", ":port", ":reflection", @@ -345,6 +344,7 @@ cc_library( srcs = [ "upb/array.c", "upb/map.c", + "upb/msg_internal.h", ], hdrs = [ "upb/array.h", @@ -355,7 +355,6 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":descriptor_upb_proto", ":mini_table", ":port", ":table", diff --git a/upb/array.c b/upb/array.c index 97a8d9503e..2eaa43a851 100644 --- a/upb/array.c +++ b/upb/array.c @@ -30,6 +30,7 @@ #include #include "upb/msg.h" +#include "upb/msg_internal.h" // Must be last. #include "upb/port_def.inc" diff --git a/upb/array.h b/upb/array.h index 7117392ed8..c780fbe77a 100644 --- a/upb/array.h +++ b/upb/array.h @@ -29,6 +29,7 @@ #define UPB_ARRAY_H_ #include "upb/message_value.h" +#include "upb/upb.h" // Must be last. #include "upb/port_def.inc" diff --git a/upb/def.c b/upb/def.c index 6ddc45bbbb..76683fefc1 100644 --- a/upb/def.c +++ b/upb/def.c @@ -33,7 +33,6 @@ #include #include -#include "google/protobuf/descriptor.upb.h" #include "upb/mini_table.h" #include "upb/reflection.h" diff --git a/upb/map.c b/upb/map.c index 6cc785db65..71a6a5f067 100644 --- a/upb/map.c +++ b/upb/map.c @@ -30,6 +30,7 @@ #include #include "upb/msg.h" +#include "upb/msg_internal.h" // Must be last. #include "upb/port_def.inc" diff --git a/upb/map.h b/upb/map.h index ecaaa1d029..ca8fccc0a2 100644 --- a/upb/map.h +++ b/upb/map.h @@ -29,6 +29,7 @@ #define UPB_MAP_H_ #include "upb/message_value.h" +#include "upb/upb.h" // Must be last. #include "upb/port_def.inc" diff --git a/upb/message_value.h b/upb/message_value.h index a08b90fc1e..5d7364c674 100644 --- a/upb/message_value.h +++ b/upb/message_value.h @@ -28,14 +28,18 @@ #ifndef UPB_MESSAGE_VALUE_H_ #define UPB_MESSAGE_VALUE_H_ -#include "google/protobuf/descriptor.upb.h" +#include "upb/msg.h" +#include "upb/string_view.h" +#include "upb/upb.h" + +// Must be last. #include "upb/port_def.inc" #ifdef __cplusplus extern "C" { #endif -// Definitions commn to both upb_Array and upb_Map. +// Definitions common to both upb_Array and upb_Map. typedef union { bool bool_val; @@ -45,16 +49,16 @@ typedef union { int64_t int64_val; uint32_t uint32_val; uint64_t uint64_val; + const upb_Array* array_val; const upb_Map* map_val; const upb_Message* msg_val; - const upb_Array* array_val; upb_StringView str_val; } upb_MessageValue; typedef union { + upb_Array* array; upb_Map* map; upb_Message* msg; - upb_Array* array; } upb_MutableMessageValue; #ifdef __cplusplus diff --git a/upb/mini_table_accessors.c b/upb/mini_table_accessors.c index b04a7cf116..c53a185849 100644 --- a/upb/mini_table_accessors.c +++ b/upb/mini_table_accessors.c @@ -27,6 +27,8 @@ #include "upb/mini_table_accessors.h" +#include "upb/decode.h" +#include "upb/encode.h" #include "upb/mini_table.h" #include "upb/msg_internal.h" diff --git a/upb/msg.h b/upb/msg.h index 5c1e8e8931..89db4dd6eb 100644 --- a/upb/msg.h +++ b/upb/msg.h @@ -36,11 +36,10 @@ #ifndef UPB_MSG_H_ #define UPB_MSG_H_ -#include +#include "upb/arena.h" -// TODO(b/232091617): Remove this and fix everything that breaks as a result. -#include "upb/extension_registry.h" -#include "upb/upb.h" +// Must be last. +#include "upb/port_def.inc" #ifdef __cplusplus extern "C" { @@ -50,7 +49,6 @@ typedef void upb_Message; /* For users these are opaque. They can be obtained from * upb_MessageDef_MiniTable() but users cannot access any of the members. */ -struct upb_MiniTable; typedef struct upb_MiniTable upb_MiniTable; /* Adds unknown data (serialized protobuf data) to the given message. The data @@ -64,6 +62,8 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); /* Returns the number of extensions present in this message. */ size_t upb_Message_ExtensionCount(const upb_Message* msg); +#include "upb/port_undef.inc" + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/upb/msg_internal.h b/upb/msg_internal.h index ff68606c4e..7360ad12c1 100644 --- a/upb/msg_internal.h +++ b/upb/msg_internal.h @@ -410,12 +410,12 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_Message* msg, size_t ofs) { /** upb_Array *****************************************************************/ /* Our internal representation for repeated fields. */ -typedef struct { +struct upb_Array { uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ size_t size; /* The number of elements in the array. */ size_t capacity; /* Allocated storage. Measured in elements. */ uint64_t junk; -} upb_Array; +}; UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { UPB_ASSERT((arr->data & 7) <= 4); @@ -567,14 +567,14 @@ UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, /* Right now we use strmaps for everything. We'll likely want to use * integer-specific maps for integer-keyed maps.*/ -typedef struct { +struct upb_Map { /* Size of key and val, based on the map type. Strings are represented as '0' * because they must be handled specially. */ char key_size; char val_size; upb_strtable table; -} upb_Map; +}; /* Map entries aren't actually stored, they are only used during parsing. For * parsing, it helps a lot if all map entry messages have the same layout. diff --git a/upb/upb.h b/upb/upb.h index a2345eb1b1..20cb928f79 100644 --- a/upb/upb.h +++ b/upb/upb.h @@ -51,6 +51,11 @@ extern "C" { #endif +// These types appear in circular references so we need to forward-declare them. +// There is no obviously good place for this so let's just put it here. +typedef struct upb_Array upb_Array; +typedef struct upb_Map upb_Map; + /* Constants ******************************************************************/ /* A list of types as they are encoded on-the-wire. */