diff --git a/lua/msg.c b/lua/msg.c index bdec7a2d09..7c0e0e7d24 100644 --- a/lua/msg.c +++ b/lua/msg.c @@ -40,9 +40,9 @@ #include "lauxlib.h" #include "lua/upb.h" -#include "upb/collections/map.h" #include "upb/json/decode.h" #include "upb/json/encode.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/port/def.inc" #include "upb/reflection/message.h" diff --git a/protos/BUILD b/protos/BUILD index 648d9388f6..d037b60ac9 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -32,8 +32,8 @@ cc_library( ":protos", ":protos_traits", "//upb:base", - "//upb:collections", "//upb:mem", + "//upb:message", "//upb:message_copy", "//upb:message_types", "//upb:port", diff --git a/protos/repeated_field.h b/protos/repeated_field.h index 6edcfb5381..da42c44bc1 100644 --- a/protos/repeated_field.h +++ b/protos/repeated_field.h @@ -40,8 +40,8 @@ #include "protos/protos_traits.h" #include "protos/repeated_field_iterator.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" #include "upb/mem/arena.h" +#include "upb/message/array.h" #include "upb/message/copy.h" #include "upb/message/types.h" diff --git a/protos/repeated_field_iterator.h b/protos/repeated_field_iterator.h index a552d76be1..6ae25de14c 100644 --- a/protos/repeated_field_iterator.h +++ b/protos/repeated_field_iterator.h @@ -38,8 +38,8 @@ #include "absl/strings/string_view.h" #include "protos/protos.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" #include "upb/mem/arena.h" +#include "upb/message/array.h" #include "upb/message/copy.h" // Must be last: diff --git a/python/BUILD b/python/BUILD index 6d8ba1c575..92e9c496c5 100644 --- a/python/BUILD +++ b/python/BUILD @@ -190,10 +190,10 @@ py_extension( ], target_compatible_with = select(_message_target_compatible_with), deps = [ - "//upb:collections", "//upb:descriptor_upb_proto_reflection", "//upb:eps_copy_input_stream", "//upb:hash", + "//upb:message", "//upb:message_copy", "//upb:port", "//upb:reflection", diff --git a/python/convert.c b/python/convert.c index 98d9b75dcf..413c42f735 100644 --- a/python/convert.c +++ b/python/convert.c @@ -32,7 +32,7 @@ #include "python/message.h" #include "python/protobuf.h" -#include "upb/collections/map.h" +#include "upb/message/map.h" #include "upb/reflection/message.h" #include "upb/util/compare.h" diff --git a/python/map.c b/python/map.c index bd9022d847..a1d75de9a1 100644 --- a/python/map.c +++ b/python/map.c @@ -33,7 +33,7 @@ #include "python/convert.h" #include "python/message.h" #include "python/protobuf.h" -#include "upb/collections/map.h" +#include "upb/message/map.h" #include "upb/reflection/def.h" // ----------------------------------------------------------------------------- diff --git a/upb/BUILD b/upb/BUILD index b67b7a6c4f..53c5b61e6d 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -81,14 +81,13 @@ package_group( packages = ["//..."], ) -# This is a stub library to keep gRPC happy. Do not use it for any reason, -# use the smaller targets below instead. cc_library( name = "upb", hdrs = [ "upb.hpp", ], copts = UPB_DEFAULT_COPTS, + deprecation = "use upb:base and/or upb:mem instead", visibility = ["//visibility:public"], deps = [ ":base", @@ -112,8 +111,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":base", - ":collections", - ":collections_internal", ":mem", ":message", ":message_accessors", @@ -200,8 +197,8 @@ bootstrap_cc_library( visibility = ["//visibility:public"], deps = [ ":base", - ":collections", ":mem", + ":message", ":message_types", ":message_value", ":port", @@ -269,7 +266,6 @@ bootstrap_cc_library( visibility = ["//visibility:public"], deps = [ ":base", - ":collections", ":hash", ":mem", ":message", @@ -301,18 +297,7 @@ alias( alias( name = "collections", actual = "//upb/collections", - visibility = ["//visibility:public"], -) - -alias( - name = "collections_internal", - actual = "//upb/collections:internal", - visibility = ["//visibility:public"], -) - -alias( - name = "collections_split64", - actual = "//upb/collections:split64", + deprecation = "use upb:message instead", visibility = ["//visibility:public"], ) @@ -516,8 +501,6 @@ cc_binary( linkstatic = 1, visibility = ["//visibility:public"], deps = [ - ":collections", - ":collections_split64", ":mem", ":message", ":message_accessors", @@ -541,8 +524,6 @@ upb_amalgamation( libs = [ ":base", ":base_internal", - ":collections", - ":collections_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto", ":eps_copy_input_stream", @@ -591,8 +572,6 @@ upb_amalgamation( libs = [ ":base", ":base_internal", - ":collections", - ":collections_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto_reflection", ":descriptor_upb_proto", @@ -644,8 +623,6 @@ upb_amalgamation( libs = [ ":base", ":base_internal", - ":collections", - ":collections_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto", ":eps_copy_input_stream", diff --git a/upb/collections/BUILD b/upb/collections/BUILD index c043e688f2..8437cd598a 100644 --- a/upb/collections/BUILD +++ b/upb/collections/BUILD @@ -16,77 +16,7 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":internal", - "//upb:base", - "//upb:mem", - "//upb:message_value", - "//upb:port", - ], -) - -cc_library( - name = "internal", - srcs = [ - "array.c", - "array.h", - "map.c", - "map.h", - "map_sorter.c", - ], - hdrs = [ - "internal/array.h", - "internal/map.h", - "internal/map_entry.h", - "internal/map_sorter.h", - "map_gencode_util.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - "//upb:base", - "//upb:base_internal", - "//upb:hash", - "//upb:mem", - "//upb:message_internal", - "//upb:message_internal_types", - "//upb:message_types", - "//upb:message_value", - "//upb:port", - ], -) - -cc_library( - name = "split64", - hdrs = [ - "array_split64.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":collections", - "//upb:port", - ], -) - -cc_test( - name = "array_test", - srcs = ["array_test.cc"], - deps = [ - ":collections", - "@com_google_googletest//:gtest_main", - "//upb:base", - "//upb:mem", - ], -) - -cc_test( - name = "map_test", - srcs = ["map_test.cc"], - deps = [ - ":collections", - "@com_google_googletest//:gtest_main", - "//upb:base", - "//upb:mem", + "//upb:message", ], ) @@ -95,7 +25,6 @@ filegroup( name = "source_files", srcs = glob( [ - "**/*.c", "**/*.h", ], ), diff --git a/upb/collections/array.h b/upb/collections/array.h index 6fb1e8f350..187e74eeab 100644 --- a/upb/collections/array.h +++ b/upb/collections/array.h @@ -1,98 +1,17 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +// Temporary hack to fix gRPC. Do not use. #ifndef UPB_COLLECTIONS_ARRAY_H_ #define UPB_COLLECTIONS_ARRAY_H_ -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/message/value.h" // IWYU pragma: export - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API size_t upb_Array_Size(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, - upb_Arena* arena); - -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); - -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); - -// Returns pointer to array data. -UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); - -// Returns mutable pointer to array data. -UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" +// IWYU pragma: begin_exports +#include "upb/message/array.h" +// IWYU pragma: end_exports #endif /* UPB_COLLECTIONS_ARRAY_H_ */ diff --git a/upb/collections/map.h b/upb/collections/map.h index 9377eaca49..0729cb3ec3 100644 --- a/upb/collections/map.h +++ b/upb/collections/map.h @@ -1,147 +1,17 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +// Temporary hack to fix gRPC. Do not use. #ifndef UPB_COLLECTIONS_MAP_H_ #define UPB_COLLECTIONS_MAP_H_ -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/message/value.h" // IWYU pragma: export - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Map upb_Map; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new map on the given arena with the given key/value size. -UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, - upb_CType value_type); - -// Returns the number of entries in the map. -UPB_API size_t upb_Map_Size(const upb_Map* map); - -// Stores a value for the given key into |*val| (or the zero value if the key is -// not present). Returns whether the key was present. The |val| pointer may be -// NULL, in which case the function tests whether the given key is present. -UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -// Removes all entries in the map. -UPB_API void upb_Map_Clear(upb_Map* map); - -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; - -// Sets the given key to the given value, returning whether the key was inserted -// or replaced. If the key was inserted, then any existing iterators will be -// invalidated. -UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, - upb_Arena* arena); - -// Sets the given key to the given value. Returns false if memory allocation -// failed. If the key is newly inserted, then any existing iterators will be -// invalidated. -UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} - -// Deletes this key from the table. Returns true if the key was present. -// If present and |val| is non-NULL, stores the deleted value. -UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -// (DEPRECATED and going away soon. Do not use.) -UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return upb_Map_Delete(map, key, val); -} - -// Map iteration: -// -// size_t iter = kUpb_Map_Begin; -// upb_MessageValue key, val; -// while (upb_Map_Next(map, &key, &val, &iter)) { -// ... -// } - -#define kUpb_Map_Begin ((size_t)-1) - -// Advances to the next entry. Returns false if no more entries are present. -// Otherwise returns true and populates both *key and *value. -UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter); - -// Sets the value for the entry pointed to by iter. -// WARNING: this does not currently work for string values! -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val); - -// DEPRECATED iterator, slated for removal. - -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * } - */ - -// Advances to the next entry. Returns false if no more entries are present. -UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); - -// Returns true if the iterator still points to a valid entry, or false if the -// iterator is past the last element. It is an error to call this function with -// kUpb_Map_Begin (you must call next() at least once first). -UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); - -// Returns the key and value for this entry of the map. -UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" +// IWYU pragma: begin_exports +#include "upb/message/map.h" +// IWYU pragma: end_exports #endif /* UPB_COLLECTIONS_MAP_H_ */ diff --git a/upb/generated_code_support.h b/upb/generated_code_support.h index 9f222cc418..cbc72945b9 100644 --- a/upb/generated_code_support.h +++ b/upb/generated_code_support.h @@ -9,13 +9,13 @@ #define UPB_GENERATED_CODE_SUPPORT_H_ // IWYU pragma: begin_exports -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/map_gencode_util.h" #include "upb/message/accessors.h" +#include "upb/message/array.h" #include "upb/message/internal/accessors.h" +#include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" +#include "upb/message/map_gencode_util.h" #include "upb/message/message.h" #include "upb/mini_descriptor/decode.h" #include "upb/mini_table/enum.h" diff --git a/upb/json/BUILD b/upb/json/BUILD index fc09d39397..31840a4f29 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -20,8 +20,8 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - "//upb:collections", "//upb:lex", + "//upb:message", "//upb:port", "//upb:reflection", "//upb:wire", diff --git a/upb/json/decode.c b/upb/json/decode.c index 0f4346bb71..5b7fc3d9f4 100644 --- a/upb/json/decode.c +++ b/upb/json/decode.c @@ -38,9 +38,9 @@ #include #include -#include "upb/collections/map.h" #include "upb/lex/atoi.h" #include "upb/lex/unicode.h" +#include "upb/message/map.h" #include "upb/reflection/message.h" #include "upb/wire/encode.h" diff --git a/upb/json/encode.c b/upb/json/encode.c index 656bee958c..1ec9f83665 100644 --- a/upb/json/encode.c +++ b/upb/json/encode.c @@ -37,8 +37,8 @@ #include #include -#include "upb/collections/map.h" #include "upb/lex/round_trip.h" +#include "upb/message/map.h" #include "upb/port/vsnprintf_compat.h" #include "upb/reflection/message.h" #include "upb/wire/decode.h" diff --git a/upb/message/BUILD b/upb/message/BUILD index 78b9c033c4..c3575490c1 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -27,8 +27,6 @@ cc_library( ":internal", ":message", "//upb:base", - "//upb:collections", - "//upb:collections_internal", "//upb:eps_copy_input_stream", "//upb:mini_table", "//upb:mini_table_internal", @@ -47,7 +45,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":internal", - "//upb:collections_internal", "//upb:mini_table_internal", "//upb:port", ], @@ -69,7 +66,6 @@ cc_library( ":message", ":types", "//upb:base", - "//upb:collections", "//upb:mem", "//upb:mini_table", "//upb:mini_table_internal", @@ -80,20 +76,32 @@ cc_library( cc_library( name = "internal", srcs = [ + "array.c", + "array.h", + "map.c", + "map.h", + "map_sorter.c", "message.c", "message.h", ], hdrs = [ + "internal/array.h", "internal/extension.h", + "internal/map.h", + "internal/map_entry.h", + "internal/map_sorter.h", "internal/message.h", + "map_gencode_util.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ ":internal_types", ":types", + ":value", "//upb:base", "//upb:base_internal", + "//upb:hash", "//upb:mem", "//upb:mini_table", "//upb:port", @@ -114,6 +122,8 @@ cc_library( cc_library( name = "message", hdrs = [ + "array.h", + "map.h", "message.h", ], copts = UPB_DEFAULT_COPTS, @@ -121,6 +131,7 @@ cc_library( deps = [ ":internal", ":types", + ":value", "//upb:base", "//upb:mem", "//upb:mini_table", @@ -145,8 +156,6 @@ cc_library( ":message", ":types", "//upb:base", - "//upb:collections", - "//upb:collections_internal", "//upb:eps_copy_input_stream", "//upb:mem", "//upb:message_tagged_ptr", @@ -163,11 +172,13 @@ cc_library( name = "split64", hdrs = [ "accessors_split64.h", + "array_split64.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ ":accessors", + ":message", "//upb:port", ], ) @@ -231,10 +242,10 @@ cc_test( srcs = ["accessors_test.cc"], deps = [ ":accessors", + ":message", "//:protobuf", "@com_google_googletest//:gtest_main", "//upb:base", - "//upb:collections", "//upb:mini_descriptor", "//upb:mini_descriptor_internal", "//upb:mini_table", @@ -247,6 +258,17 @@ cc_test( ], ) +cc_test( + name = "array_test", + srcs = ["array_test.cc"], + deps = [ + ":message", + "@com_google_googletest//:gtest_main", + "//upb:base", + "//upb:mem", + ], +) + cc_test( name = "copy_test", srcs = ["copy_test.cc"], @@ -258,7 +280,6 @@ cc_test( "//:protobuf", "@com_google_googletest//:gtest_main", "//upb:base", - "//upb:collections", "//upb:mem", "//upb:mini_table", "//upb:wire", @@ -269,17 +290,28 @@ cc_test( ], ) +cc_test( + name = "map_test", + srcs = ["map_test.cc"], + deps = [ + ":message", + "@com_google_googletest//:gtest_main", + "//upb:base", + "//upb:mem", + ], +) + cc_test( name = "promote_test", srcs = ["promote_test.cc"], deps = [ ":accessors", ":copy", + ":message", ":promote", "//:protobuf", "@com_google_googletest//:gtest_main", "//upb:base", - "//upb:collections", "//upb:mem", "//upb:mini_descriptor_internal", "//upb:mini_table", diff --git a/upb/message/accessors.c b/upb/message/accessors.c index f3969a9e58..25c0f9e5ef 100644 --- a/upb/message/accessors.c +++ b/upb/message/accessors.c @@ -7,9 +7,9 @@ #include "upb/message/accessors.h" -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/map.h" +#include "upb/message/array.h" +#include "upb/message/internal/array.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_table/field.h" #include "upb/wire/decode.h" diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 14896a06d0..f8a9f9987b 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -9,12 +9,12 @@ #define UPB_MESSAGE_ACCESSORS_H_ #include "upb/base/descriptor_constants.h" -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/internal/map.h" -#include "upb/collections/map.h" +#include "upb/message/array.h" #include "upb/message/internal/accessors.h" +#include "upb/message/internal/array.h" +#include "upb/message/internal/map.h" #include "upb/message/internal/message.h" +#include "upb/message/map.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/field.h" diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index b8b65697fd..e6a934cc3a 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -19,7 +19,7 @@ #include "google/protobuf/test_messages_proto2.upb.h" #include "google/protobuf/test_messages_proto3.upb.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" +#include "upb/message/array.h" #include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/internal/encode.hpp" #include "upb/mini_descriptor/internal/modifiers.h" diff --git a/upb/collections/array.c b/upb/message/array.c similarity index 99% rename from upb/collections/array.c rename to upb/message/array.c index f46fc3e88f..bf59f0139e 100644 --- a/upb/collections/array.c +++ b/upb/message/array.c @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upb/collections/internal/array.h" +#include "upb/message/internal/array.h" #include diff --git a/upb/message/array.h b/upb/message/array.h new file mode 100644 index 0000000000..55290c8b2d --- /dev/null +++ b/upb/message/array.h @@ -0,0 +1,98 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef UPB_MESSAGE_ARRAY_H_ +#define UPB_MESSAGE_ARRAY_H_ + +#include + +#include "upb/base/descriptor_constants.h" +#include "upb/mem/arena.h" +#include "upb/message/value.h" // IWYU pragma: export + +// Must be last. +#include "upb/port/def.inc" + +typedef struct upb_Array upb_Array; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new array on the given arena that holds elements of this type. +UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); + +// Returns the number of elements in the array. +UPB_API size_t upb_Array_Size(const upb_Array* arr); + +// Returns the given element, which must be within the array's current size. +UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); + +// Sets the given element, which must be within the array's current size. +UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); + +// Appends an element to the array. Returns false on allocation failure. +UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, + upb_Arena* arena); + +// Moves elements within the array using memmove(). +// Like memmove(), the source and destination elements may be overlapping. +UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); + +// Inserts one or more empty elements into the array. +// Existing elements are shifted right. +// The new elements have undefined state and must be set with `upb_Array_Set()`. +// REQUIRES: `i <= upb_Array_Size(arr)` +UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); + +// Deletes one or more elements from the array. +// Existing elements are shifted left. +// REQUIRES: `i + count <= upb_Array_Size(arr)` +UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); + +// Changes the size of a vector. New elements are initialized to NULL/0. +// Returns false on allocation failure. +UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); + +// Returns pointer to array data. +UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); + +// Returns mutable pointer to array data. +UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* UPB_MESSAGE_ARRAY_H_ */ diff --git a/upb/collections/array_split64.h b/upb/message/array_split64.h similarity index 95% rename from upb/collections/array_split64.h rename to upb/message/array_split64.h index 69ea57906b..5d136bd7fb 100644 --- a/upb/collections/array_split64.h +++ b/upb/message/array_split64.h @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef UPB_COLLECTIONS_ARRAY_SPLIT64_H_ -#define UPB_COLLECTIONS_ARRAY_SPLIT64_H_ +#ifndef UPB_MESSAGE_ARRAY_SPLIT64_H_ +#define UPB_MESSAGE_ARRAY_SPLIT64_H_ -#include "upb/collections/array.h" +#include "upb/message/array.h" // Must be last. #include "upb/port/def.inc" @@ -90,4 +90,4 @@ UPB_API_INLINE bool upb_Array_AppendUInt64Split(upb_Array* array, uint32_t hi, #include "upb/port/undef.inc" -#endif /* UPB_COLLECTIONS_ARRAY_SPLIT64_H_ */ +#endif /* UPB_MESSAGE_ARRAY_SPLIT64_H_ */ diff --git a/upb/collections/array_test.cc b/upb/message/array_test.cc similarity index 98% rename from upb/collections/array_test.cc rename to upb/message/array_test.cc index fb1762e0d7..11f88d627e 100644 --- a/upb/collections/array_test.cc +++ b/upb/message/array_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upb/collections/array.h" +#include "upb/message/array.h" #include #include "upb/base/status.hpp" diff --git a/upb/message/copy.h b/upb/message/copy.h index 9377d297f3..ce682efa53 100644 --- a/upb/message/copy.h +++ b/upb/message/copy.h @@ -8,9 +8,9 @@ #ifndef UPB_MESSAGE_COPY_H_ #define UPB_MESSAGE_COPY_H_ -#include "upb/collections/array.h" -#include "upb/collections/map.h" #include "upb/mem/arena.h" +#include "upb/message/array.h" +#include "upb/message/map.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/message/copy_test.cc b/upb/message/copy_test.cc index f9bbff511f..febeeab13a 100644 --- a/upb/message/copy_test.cc +++ b/upb/message/copy_test.cc @@ -22,10 +22,10 @@ #include #include "google/protobuf/test_messages_proto2.upb.h" #include "upb/base/string_view.h" -#include "upb/collections/map.h" #include "upb/mem/arena.h" #include "upb/message/accessors.h" #include "upb/message/internal/message.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_table/message.h" #include "upb/wire/encode.h" diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index d71a999216..2ec295a22c 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -8,8 +8,8 @@ #ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ #define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#include "upb/collections/internal/map.h" #include "upb/message/internal/extension.h" +#include "upb/message/internal/map.h" #include "upb/message/internal/message.h" #include "upb/mini_table/internal/field.h" diff --git a/upb/collections/internal/array.h b/upb/message/internal/array.h similarity index 96% rename from upb/collections/internal/array.h rename to upb/message/internal/array.h index 1c2f3f50d0..e8e8429cfd 100644 --- a/upb/collections/internal/array.h +++ b/upb/message/internal/array.h @@ -28,12 +28,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef UPB_COLLECTIONS_INTERNAL_ARRAY_H_ -#define UPB_COLLECTIONS_INTERNAL_ARRAY_H_ +#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ +#define UPB_MESSAGE_INTERNAL_ARRAY_H_ #include -#include "upb/collections/array.h" +#include "upb/message/array.h" // Must be last. #include "upb/port/def.inc" @@ -135,4 +135,4 @@ UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { #include "upb/port/undef.inc" -#endif /* UPB_COLLECTIONS_INTERNAL_ARRAY_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ diff --git a/upb/collections/internal/map.h b/upb/message/internal/map.h similarity index 99% rename from upb/collections/internal/map.h rename to upb/message/internal/map.h index b009254d9d..26d23ca0f9 100644 --- a/upb/collections/internal/map.h +++ b/upb/message/internal/map.h @@ -34,9 +34,9 @@ #define UPB_COLLECTIONS_INTERNAL_MAP_H_ #include "upb/base/string_view.h" -#include "upb/collections/map.h" #include "upb/hash/str_table.h" #include "upb/mem/arena.h" +#include "upb/message/map.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/collections/internal/map_entry.h b/upb/message/internal/map_entry.h similarity index 100% rename from upb/collections/internal/map_entry.h rename to upb/message/internal/map_entry.h diff --git a/upb/collections/internal/map_sorter.h b/upb/message/internal/map_sorter.h similarity index 97% rename from upb/collections/internal/map_sorter.h rename to upb/message/internal/map_sorter.h index a464959b79..77e6263091 100644 --- a/upb/collections/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -35,9 +35,9 @@ #include -#include "upb/collections/internal/map.h" -#include "upb/collections/internal/map_entry.h" #include "upb/message/internal/extension.h" +#include "upb/message/internal/map.h" +#include "upb/message/internal/map_entry.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/collections/map.c b/upb/message/map.c similarity index 98% rename from upb/collections/map.c rename to upb/message/map.c index a445e591c2..2a90cd0c79 100644 --- a/upb/collections/map.c +++ b/upb/message/map.c @@ -28,12 +28,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upb/collections/map.h" +#include "upb/message/map.h" #include -#include "upb/collections/internal/map.h" #include "upb/mem/arena.h" +#include "upb/message/internal/map.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/map.h b/upb/message/map.h new file mode 100644 index 0000000000..051f954e40 --- /dev/null +++ b/upb/message/map.h @@ -0,0 +1,147 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef UPB_MESSAGE_MAP_H_ +#define UPB_MESSAGE_MAP_H_ + +#include + +#include "upb/base/descriptor_constants.h" +#include "upb/mem/arena.h" +#include "upb/message/value.h" // IWYU pragma: export + +// Must be last. +#include "upb/port/def.inc" + +typedef struct upb_Map upb_Map; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new map on the given arena with the given key/value size. +UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, + upb_CType value_type); + +// Returns the number of entries in the map. +UPB_API size_t upb_Map_Size(const upb_Map* map); + +// Stores a value for the given key into |*val| (or the zero value if the key is +// not present). Returns whether the key was present. The |val| pointer may be +// NULL, in which case the function tests whether the given key is present. +UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// Removes all entries in the map. +UPB_API void upb_Map_Clear(upb_Map* map); + +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; + +// Sets the given key to the given value, returning whether the key was inserted +// or replaced. If the key was inserted, then any existing iterators will be +// invalidated. +UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, + upb_Arena* arena); + +// Sets the given key to the given value. Returns false if memory allocation +// failed. If the key is newly inserted, then any existing iterators will be +// invalidated. +UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + return upb_Map_Insert(map, key, val, arena) != + kUpb_MapInsertStatus_OutOfMemory; +} + +// Deletes this key from the table. Returns true if the key was present. +// If present and |val| is non-NULL, stores the deleted value. +UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// (DEPRECATED and going away soon. Do not use.) +UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return upb_Map_Delete(map, key, val); +} + +// Map iteration: +// +// size_t iter = kUpb_Map_Begin; +// upb_MessageValue key, val; +// while (upb_Map_Next(map, &key, &val, &iter)) { +// ... +// } + +#define kUpb_Map_Begin ((size_t)-1) + +// Advances to the next entry. Returns false if no more entries are present. +// Otherwise returns true and populates both *key and *value. +UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, + upb_MessageValue* val, size_t* iter); + +// Sets the value for the entry pointed to by iter. +// WARNING: this does not currently work for string values! +UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, + upb_MessageValue val); + +// DEPRECATED iterator, slated for removal. + +/* Map iteration: + * + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); + * } + */ + +// Advances to the next entry. Returns false if no more entries are present. +UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); + +// Returns true if the iterator still points to a valid entry, or false if the +// iterator is past the last element. It is an error to call this function with +// kUpb_Map_Begin (you must call next() at least once first). +UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); + +// Returns the key and value for this entry of the map. +UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* UPB_MESSAGE_MAP_H_ */ diff --git a/upb/collections/map_gencode_util.h b/upb/message/map_gencode_util.h similarity index 94% rename from upb/collections/map_gencode_util.h rename to upb/message/map_gencode_util.h index c6df5451c1..52ad69f5a2 100644 --- a/upb/collections/map_gencode_util.h +++ b/upb/message/map_gencode_util.h @@ -30,10 +30,10 @@ // These functions are only used by generated code. -#ifndef UPB_COLLECTIONS_MAP_GENCODE_UTIL_H_ -#define UPB_COLLECTIONS_MAP_GENCODE_UTIL_H_ +#ifndef UPB_MESSAGE_MAP_GENCODE_UTIL_H_ +#define UPB_MESSAGE_MAP_GENCODE_UTIL_H_ -#include "upb/collections/internal/map.h" +#include "upb/message/internal/map.h" // Must be last. #include "upb/port/def.inc" @@ -78,4 +78,4 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #include "upb/port/undef.inc" -#endif /* UPB_COLLECTIONS_MAP_GENCODE_UTIL_H_ */ +#endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ diff --git a/upb/collections/map_sorter.c b/upb/message/map_sorter.c similarity index 99% rename from upb/collections/map_sorter.c rename to upb/message/map_sorter.c index 9ad2a66087..bdbfb59c53 100644 --- a/upb/collections/map_sorter.c +++ b/upb/message/map_sorter.c @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upb/collections/internal/map_sorter.h" +#include "upb/message/internal/map_sorter.h" #include "upb/base/internal/log2.h" diff --git a/upb/collections/map_test.cc b/upb/message/map_test.cc similarity index 98% rename from upb/collections/map_test.cc rename to upb/message/map_test.cc index 0a2400092e..bb7e424bf5 100644 --- a/upb/collections/map_test.cc +++ b/upb/message/map_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upb/collections/map.h" +#include "upb/message/map.h" #include #include "upb/base/string_view.h" diff --git a/upb/message/promote.c b/upb/message/promote.c index 3e4c6dbf89..b414eaa80b 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -12,14 +12,14 @@ #include #include "upb/base/descriptor_constants.h" -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/map.h" #include "upb/mem/arena.h" #include "upb/message/accessors.h" +#include "upb/message/array.h" #include "upb/message/internal/accessors.h" +#include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" diff --git a/upb/message/promote.h b/upb/message/promote.h index dfa9fdc03b..fb3823e205 100644 --- a/upb/message/promote.h +++ b/upb/message/promote.h @@ -8,9 +8,9 @@ #ifndef UPB_MESSAGE_PROMOTE_H_ #define UPB_MESSAGE_PROMOTE_H_ -#include "upb/collections/array.h" -#include "upb/collections/map.h" +#include "upb/message/array.h" #include "upb/message/internal/extension.h" +#include "upb/message/map.h" #include "upb/wire/decode.h" // Must be last. diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index 6adf9a428d..2b86f95694 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -19,9 +19,9 @@ #include "google/protobuf/test_messages_proto2.upb.h" #include "google/protobuf/test_messages_proto3.upb.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" #include "upb/mem/arena.hpp" #include "upb/message/accessors.h" +#include "upb/message/array.h" #include "upb/message/copy.h" #include "upb/mini_descriptor/internal/encode.hpp" #include "upb/mini_descriptor/internal/modifiers.h" diff --git a/upb/message/value.h b/upb/message/value.h index 954d88acdb..99df02597c 100644 --- a/upb/message/value.h +++ b/upb/message/value.h @@ -6,7 +6,7 @@ // https://developers.google.com/open-source/licenses/bsd // Users should include array.h or map.h instead. -// IWYU pragma: private, include "upb/collections/array.h" +// IWYU pragma: private, include "upb/message/array.h" #ifndef UPB_MESSAGE_VALUE_H_ #define UPB_MESSAGE_VALUE_H_ diff --git a/upb/reflection/message.c b/upb/reflection/message.c index 7ea30e6710..dc014ae11c 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -9,9 +9,9 @@ #include -#include "upb/collections/map.h" #include "upb/hash/common.h" #include "upb/message/accessors.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_table/field.h" #include "upb/reflection/def.h" diff --git a/upb/reflection/message.h b/upb/reflection/message.h index 01a0840fe1..9e57c1a16e 100644 --- a/upb/reflection/message.h +++ b/upb/reflection/message.h @@ -10,8 +10,8 @@ #include -#include "upb/collections/map.h" #include "upb/mem/arena.h" +#include "upb/message/map.h" #include "upb/message/types.h" #include "upb/message/value.h" // IWYU pragma: export #include "upb/reflection/common.h" diff --git a/upb/test/BUILD b/upb/test/BUILD index 824bf7c604..2270476de1 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -169,8 +169,8 @@ cc_test( ":test_upb_proto", "@com_google_googletest//:gtest_main", "//upb:base", - "//upb:collections", "//upb:mem", + "//upb:message", "//upb:port", ], ) diff --git a/upb/test/test_generated_code.cc b/upb/test/test_generated_code.cc index e8f33d5cd1..2a2d723654 100644 --- a/upb/test/test_generated_code.cc +++ b/upb/test/test_generated_code.cc @@ -18,8 +18,8 @@ #include "google/protobuf/test_messages_proto3.upb.h" #include "upb/base/status.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" #include "upb/mem/arena.hpp" +#include "upb/message/array.h" #include "upb/test/test.upb.h" // Must be last. diff --git a/upb/text/BUILD b/upb/text/BUILD index cca2b7ef4a..575dda3bc3 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -18,10 +18,10 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - "//upb:collections", - "//upb:collections_internal", "//upb:eps_copy_input_stream", "//upb:lex", + "//upb:message", + "//upb:message_internal", "//upb:port", "//upb:reflection", "//upb:wire", diff --git a/upb/text/encode.c b/upb/text/encode.c index d3e0b610ae..6d26faca06 100644 --- a/upb/text/encode.c +++ b/upb/text/encode.c @@ -13,9 +13,9 @@ #include #include -#include "upb/collections/internal/map_sorter.h" -#include "upb/collections/map.h" #include "upb/lex/round_trip.h" +#include "upb/message/internal/map_sorter.h" +#include "upb/message/map.h" #include "upb/port/vsnprintf_compat.h" #include "upb/reflection/message.h" #include "upb/wire/eps_copy_input_stream.h" diff --git a/upb/upb_so.c b/upb/upb_so.c index 23d2530a2c..a7bb3e7ffc 100644 --- a/upb/upb_so.c +++ b/upb/upb_so.c @@ -7,8 +7,10 @@ // These headers form a spanning tree for the upb defs needed by FFI layers. -#include "upb/collections/array_split64.h" -#include "upb/collections/map.h" +// IWYU pragma: begin_exports #include "upb/message/accessors_split64.h" +#include "upb/message/array_split64.h" +#include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_descriptor/decode.h" +// IWYU pragma: end_exports diff --git a/upb/util/BUILD b/upb/util/BUILD index 40bf564719..1abbaf070f 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -98,7 +98,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:collections", + "//upb:message", "//upb:message_types", "//upb:port", "//upb:reflection", diff --git a/upb/util/required_fields.c b/upb/util/required_fields.c index 3e4c403bd3..4e66cdd9e6 100644 --- a/upb/util/required_fields.c +++ b/upb/util/required_fields.c @@ -17,8 +17,8 @@ #include #include "upb/base/descriptor_constants.h" -#include "upb/collections/array.h" -#include "upb/collections/map.h" +#include "upb/message/array.h" +#include "upb/message/map.h" #include "upb/message/types.h" #include "upb/port/vsnprintf_compat.h" #include "upb/reflection/def.h" diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 4d9e31cf59..20b421a3fc 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -49,8 +49,6 @@ cc_library( ":reader", ":types", "//upb:base", - "//upb:collections", - "//upb:collections_internal", "//upb:hash", "//upb:mem", "//upb:mem_internal", diff --git a/upb/wire/decode.c b/upb/wire/decode.c index b3b8f9236b..c528c912f2 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -15,17 +15,17 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/internal/map.h" -#include "upb/collections/internal/map_entry.h" -#include "upb/collections/map.h" #include "upb/hash/common.h" #include "upb/mem/arena.h" #include "upb/mem/internal/arena.h" +#include "upb/message/array.h" #include "upb/message/internal/accessors.h" +#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/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/enum.h" diff --git a/upb/wire/decode_fast.c b/upb/wire/decode_fast.c index 857d84a026..8e2860a76b 100644 --- a/upb/wire/decode_fast.c +++ b/upb/wire/decode_fast.c @@ -17,7 +17,8 @@ #include "upb/wire/decode_fast.h" -#include "upb/collections/internal/array.h" +#include "upb/message/array.h" +#include "upb/message/internal/array.h" #include "upb/message/internal/types.h" #include "upb/wire/internal/decode.h" diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 367199c7b1..774c6ff50a 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -16,16 +16,16 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" -#include "upb/collections/array.h" -#include "upb/collections/internal/array.h" -#include "upb/collections/internal/map.h" -#include "upb/collections/internal/map_entry.h" -#include "upb/collections/internal/map_sorter.h" #include "upb/hash/common.h" #include "upb/hash/str_table.h" #include "upb/mem/arena.h" +#include "upb/message/array.h" #include "upb/message/internal/accessors.h" +#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/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/field.h"