From 3817bbb572e7d496442ccecf465b384a461d01e6 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 1 Aug 2023 11:26:55 -0700 Subject: [PATCH] upb: create upb/mem/BUILD The next in a series of CLs to split upb/BUILD into subdirs. Create mem/internal/ Delete the deprecated upb/arena.h and upb/alloc.h stub headers PiperOrigin-RevId: 552864952 --- BUILD | 78 ++++++----------- benchmarks/BUILD | 2 +- cmake/BUILD.bazel | 1 + protos/BUILD | 3 + protos/protos_internal_test.cc | 2 +- python/dist/BUILD.bazel | 1 + upb/alloc.h | 36 -------- upb/arena.h | 36 -------- upb/io/BUILD | 1 + upb/mem/BUILD | 87 +++++++++++++++++++ upb/mem/arena.c | 5 +- .../{arena_internal.h => internal/arena.h} | 6 +- upb/test/BUILD | 1 + upb/wire/decode.c | 2 +- upb/wire/internal/decode.h | 2 +- 15 files changed, 129 insertions(+), 134 deletions(-) delete mode 100644 upb/alloc.h delete mode 100644 upb/arena.h create mode 100644 upb/mem/BUILD rename upb/mem/{arena_internal.h => internal/arena.h} (97%) diff --git a/BUILD b/BUILD index d39d42b415..f5a64d7d60 100644 --- a/BUILD +++ b/BUILD @@ -127,13 +127,9 @@ cc_library( cc_library( name = "upb", hdrs = [ - "upb/alloc.h", - "upb/arena.h", "upb/collections/array.h", "upb/decode.h", "upb/encode.h", - "upb/mem/alloc.h", - "upb/mem/arena.h", "upb/message/extension_internal.h", "upb/message/message.h", "upb/msg.h", @@ -285,6 +281,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":collections_internal", + ":mem", ":message_accessors", ":message_internal", ":port", @@ -367,10 +364,11 @@ cc_test( deps = [ ":base", ":collections", + ":mem", ":message_accessors", ":message_copy", + ":mini_table", ":upb", - "//upb/mini_table", "//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_upb_proto", @@ -389,9 +387,9 @@ cc_library( ":hash", ":mem_internal", ":message_internal", + ":mini_table", ":port", ":wire", - "//upb/mini_table", ], ) @@ -414,13 +412,14 @@ cc_library( ":base", ":base_internal", ":collections_internal", + ":mem", ":message_accessors", ":message_accessors_internal", ":message_internal", + ":mini_table", ":upb", ":wire_internal", "//upb/mini_descriptor", - "//upb/mini_table", ], ) @@ -442,9 +441,10 @@ cc_library( ":base", ":collections_internal", ":hash", + ":mem", ":message_copy", + ":mini_table", ":upb", - "//upb/mini_table", ], ) @@ -459,6 +459,7 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":mem", ":reflection_internal", "//upb/mini_descriptor", ], @@ -640,6 +641,7 @@ bootstrap_cc_library( ":base", ":collections", ":hash", + ":mem", ":message_accessors", ":port", ":upb", @@ -692,6 +694,18 @@ alias( visibility = ["//visibility:public"], ) +alias( + name = "mem", + actual = "//upb/mem", + visibility = ["//visibility:public"], +) + +alias( + name = "mem_internal", + actual = "//upb/mem:internal", + visibility = ["//:__subpackages__"], +) + alias( name = "mini_table", actual = "//upb/mini_table", @@ -797,51 +811,6 @@ cc_test( # Internal C/C++ libraries ##################################################### -cc_library( - name = "mem", - hdrs = [ - "upb/mem/alloc.h", - "upb/mem/arena.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//:__subpackages__"], - deps = [ - ":mem_internal", - ":port", - ], -) - -cc_test( - name = "arena_test", - srcs = ["upb/mem/arena_test.cc"], - deps = [ - ":port", - ":upb", - "@com_google_absl//absl/random", - "@com_google_absl//absl/random:distributions", - "@com_google_absl//absl/synchronization", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "mem_internal", - srcs = [ - "upb/mem/alloc.c", - "upb/mem/arena.c", - ], - hdrs = [ - "upb/mem/alloc.h", - "upb/mem/arena.h", - "upb/mem/arena_internal.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = [ - "//visibility:private", # Only private by automation, not intent. Owner may accept CLs adding visibility. See go/scheuklappen#explicit-private. - ], - deps = [":port"], -) - cc_library( name = "wire", hdrs = [ @@ -1013,6 +982,7 @@ upb_amalgamation( ":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", ":hash", ":lex", + ":mem", ":mem_internal", ":message_accessors", ":message_internal", @@ -1061,6 +1031,7 @@ upb_amalgamation( ":hash", ":json", ":lex", + ":mem", ":mem_internal", ":message_accessors", ":message_internal", @@ -1110,6 +1081,7 @@ upb_amalgamation( ":hash", ":json", ":lex", + ":mem", ":mem_internal", ":message_accessors", ":message_internal", diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 243274a189..4fc417d018 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -92,10 +92,10 @@ cc_test( ":benchmark_descriptor_upb_proto", ":benchmark_descriptor_upb_proto_reflection", "//:base", + "//:base_internal", "//:descriptor_upb_proto", "//:mem", "//:reflection", - "//upb/base:internal", "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/container:flat_hash_set", "@com_google_protobuf//:protobuf", diff --git a/cmake/BUILD.bazel b/cmake/BUILD.bazel index 9ddc669a07..2afc6a3367 100644 --- a/cmake/BUILD.bazel +++ b/cmake/BUILD.bazel @@ -101,6 +101,7 @@ sh_test( ":gen_cmakelists", "//:source_files", "//upb/base:source_files", + "//upb/mem:source_files", "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "@utf8_range//:utf8_range_srcs", diff --git a/protos/BUILD b/protos/BUILD index c9c8672d92..67c7d8222f 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -51,6 +51,7 @@ cc_library( ":protos_traits", "//:base", "//:collections_internal", + "//:mem", "//:message_copy", "//:mini_table", "//:port", @@ -71,6 +72,7 @@ cc_library( copts = UPB_DEFAULT_CPPOPTS, visibility = ["//visibility:public"], deps = [ + "//:mem", "//:message_copy", "//:message_promote", "//:mini_table", @@ -128,6 +130,7 @@ cc_test( copts = UPB_DEFAULT_CPPOPTS, deps = [ ":protos_internal", + "//:mem", "//:upb", "//protos_generator/tests:test_model_upb_cc_proto", "//protos_generator/tests:test_model_upb_proto", diff --git a/protos/protos_internal_test.cc b/protos/protos_internal_test.cc index 99bfaa2402..46f9d12b0e 100644 --- a/protos/protos_internal_test.cc +++ b/protos/protos_internal_test.cc @@ -29,7 +29,7 @@ #include "gtest/gtest.h" #include "protos_generator/tests/test_model.upb.h" #include "protos_generator/tests/test_model.upb.proto.h" -#include "upb/arena.h" +#include "upb/mem/arena.h" namespace protos::testing { namespace { diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index ccf226052b..82ce2ad231 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -215,6 +215,7 @@ pkg_tar( "//:source_files", "//python:message_srcs", "//upb/base:source_files", + "//upb/mem:source_files", "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "//upb/util:source_files", diff --git a/upb/alloc.h b/upb/alloc.h deleted file mode 100644 index b276b935ca..0000000000 --- a/upb/alloc.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2009-2021, Google LLC - * All rights reserved. - * - * 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 Google LLC 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. - */ - -// This header is deprecated, use upb/mem/alloc.h instead -// IWYU pragma: private, include "upb/mem/alloc.h" - -#ifndef UPB_ALLOC_H_ -#define UPB_ALLOC_H_ - -#include "upb/mem/alloc.h" - -#endif /* UPB_ALLOC_H_ */ diff --git a/upb/arena.h b/upb/arena.h deleted file mode 100644 index 3d849e09fd..0000000000 --- a/upb/arena.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2009-2021, Google LLC - * All rights reserved. - * - * 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 Google LLC 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. - */ - -// This header is deprecated, use upb/mem/arena.h instead -// IWYU pragma: private, include "upb/mem/arena.h" - -#ifndef UPB_ARENA_H_ -#define UPB_ARENA_H_ - -#include "upb/mem/arena.h" - -#endif /* UPB_ARENA_H_ */ diff --git a/upb/io/BUILD b/upb/io/BUILD index 539ca67c4f..ee62221622 100644 --- a/upb/io/BUILD +++ b/upb/io/BUILD @@ -54,6 +54,7 @@ cc_library( deps = [ ":zero_copy_stream", "//:upb", + "//:mem", "//:port", ], ) diff --git a/upb/mem/BUILD b/upb/mem/BUILD new file mode 100644 index 0000000000..800821f5a4 --- /dev/null +++ b/upb/mem/BUILD @@ -0,0 +1,87 @@ +# Copyright (c) 2009-2021, Google LLC +# All rights reserved. +# +# 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 Google LLC 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. + +load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") + +cc_library( + name = "mem", + hdrs = [ + "alloc.h", + "arena.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + ":internal", + "//:port", + ], +) + +cc_library( + name = "internal", + srcs = [ + "alloc.c", + "arena.c", + ], + hdrs = [ + "alloc.h", + "arena.h", + "internal/arena.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//:__subpackages__"], + deps = ["//:port"], +) + +cc_test( + name = "arena_test", + srcs = ["arena_test.cc"], + deps = [ + "//:mem", + "//:port", + "//:upb", + "@com_google_absl//absl/random", + "@com_google_absl//absl/random:distributions", + "@com_google_absl//absl/synchronization", + "@com_google_googletest//:gtest_main", + ], +) + +# begin:github_only +filegroup( + name = "source_files", + srcs = glob( + [ + "**/*.c", + "**/*.h", + ], + exclude = ["arena_test.cc"], + ), + visibility = [ + "//cmake:__pkg__", + "//python/dist:__pkg__", + ] +) +# end:github_only diff --git a/upb/mem/arena.c b/upb/mem/arena.c index c4037eb281..a06c6c0a02 100644 --- a/upb/mem/arena.c +++ b/upb/mem/arena.c @@ -25,7 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "upb/mem/arena_internal.h" +#include "upb/mem/internal/arena.h" + #include "upb/port/atomic.h" // Must be last. @@ -67,7 +68,7 @@ static _upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { // // This is true because: // - If no fuses occur, this will eventually become the root. - // - If fuses are actively occuring, the root may change, but the + // - If fuses are actively occurring, the root may change, but the // invariant is that `parent_or_count` merely points to *a* parent. // // In other words, it is moving towards "the" root, and that root may move diff --git a/upb/mem/arena_internal.h b/upb/mem/internal/arena.h similarity index 97% rename from upb/mem/arena_internal.h rename to upb/mem/internal/arena.h index cecc4d7a9d..c7a93eb202 100644 --- a/upb/mem/arena_internal.h +++ b/upb/mem/internal/arena.h @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef UPB_MEM_ARENA_INTERNAL_H_ -#define UPB_MEM_ARENA_INTERNAL_H_ +#ifndef UPB_MEM_INTERNAL_ARENA_H_ +#define UPB_MEM_INTERNAL_ARENA_H_ #include "upb/mem/arena.h" @@ -111,4 +111,4 @@ UPB_INLINE bool upb_Arena_HasInitialBlock(upb_Arena* arena) { #include "upb/port/undef.inc" -#endif /* UPB_MEM_ARENA_INTERNAL_H_ */ +#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ diff --git a/upb/test/BUILD b/upb/test/BUILD index 97240b8094..5ed5af2555 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -188,6 +188,7 @@ cc_test( ":test_upb_proto", "//:upb", "//:base", + "//:mem", "//:port", "@com_google_googletest//:gtest_main", ], diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 951dc58bc3..c7a116d43b 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -32,7 +32,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/collections/array_internal.h" #include "upb/collections/map_internal.h" -#include "upb/mem/arena_internal.h" +#include "upb/mem/internal/arena.h" #include "upb/message/accessors_internal.h" #include "upb/message/internal/map_entry.h" #include "upb/mini_table/sub.h" diff --git a/upb/wire/internal/decode.h b/upb/wire/internal/decode.h index 0011d35619..b6a7ba039b 100644 --- a/upb/wire/internal/decode.h +++ b/upb/wire/internal/decode.h @@ -33,7 +33,7 @@ #ifndef UPB_WIRE_INTERNAL_DECODE_H_ #define UPB_WIRE_INTERNAL_DECODE_H_ -#include "upb/mem/arena_internal.h" +#include "upb/mem/internal/arena.h" #include "upb/message/internal.h" #include "upb/wire/decode.h" #include "upb/wire/eps_copy_input_stream.h"