upb: split apart upb/upb.hpp, delete :upb

PiperOrigin-RevId: 558945210
pull/13675/head^2
Eric Salo 1 year ago committed by Copybara-Service
parent a93acc00c2
commit d2f10df2dc
  1. 35
      BUILD
  2. 1
      lua/BUILD.bazel
  3. 7
      protos/BUILD
  4. 4
      protos/protos.h
  5. 2
      protos/protos_extension_lock_test.cc
  6. 1
      protos_generator/protoc-gen-upb-protos.cc
  7. 1
      protos_generator/tests/BUILD
  8. 1
      protos_generator/tests/test_generated.cc
  9. 1
      python/BUILD
  10. 2
      upb/base/BUILD
  11. 73
      upb/base/status.hpp
  12. 4
      upb/collections/BUILD
  13. 6
      upb/collections/array_test.cc
  14. 5
      upb/collections/map_test.cc
  15. 3
      upb/hash/BUILD
  16. 14
      upb/hash/test.cc
  17. 8
      upb/io/BUILD
  18. 2
      upb/io/string_test.cc
  19. 2
      upb/io/tokenizer_test.cc
  20. 3
      upb/io/zero_copy_stream_test.cc
  21. 5
      upb/json/BUILD
  22. 2
      upb/json/decode_test.cc
  23. 3
      upb/json/encode_test.cc
  24. 3
      upb/mem/BUILD
  25. 41
      upb/mem/arena.hpp
  26. 1
      upb/mem/arena_test.cc
  27. 7
      upb/message/BUILD
  28. 2
      upb/message/promote_test.cc
  29. 3
      upb/message/test.cc
  30. 3
      upb/mini_descriptor/BUILD
  31. 5
      upb/mini_descriptor/internal/encode_test.cc
  32. 3
      upb/reflection/def.hpp
  33. 2
      upb/reflection/def_builder_test.cc
  34. 5
      upb/test/BUILD
  35. 2
      upb/test/fuzz_util.cc
  36. 3
      upb/test/test_generated_code.cc
  37. 1
      upb/test/test_mini_table_oneof.cc
  38. 8
      upb/util/BUILD
  39. 2
      upb/util/def_to_proto_test.cc
  40. 3
      upb/util/def_to_proto_test.h
  41. 3
      upb/util/required_fields_test.cc
  42. 2
      upb/wire/BUILD
  43. 2
      upb/wire/eps_copy_input_stream_test.cc
  44. 2
      upbc/BUILD
  45. 2
      upbc/file_layout.h

35
BUILD

@ -100,22 +100,6 @@ package_group(
packages = ["//..."], packages = ["//..."],
) )
# Public C/C++ libraries #######################################################
cc_library(
name = "upb",
hdrs = [
"upb/upb.hpp",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":base",
":mem",
":port",
],
)
# Common support routines used by generated code. This library has no # Common support routines used by generated code. This library has no
# implementation, but depends on :upb and exposes a few more hdrs. # implementation, but depends on :upb and exposes a few more hdrs.
# #
@ -148,22 +132,11 @@ cc_library(
# Common support code for C++ generated code. # Common support code for C++ generated code.
cc_library( cc_library(
name = "generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", name = "generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
hdrs = ["upb/upb.hpp"],
copts = UPB_DEFAULT_COPTS, copts = UPB_DEFAULT_COPTS,
textual_hdrs = [ textual_hdrs = [
"//upb/port:inc", "//upb/port:inc",
], ],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [
":base",
":collections_internal",
":hash",
":mem",
":message_copy",
":message_typedef",
":mini_table",
":upb",
],
) )
cc_library( cc_library(
@ -220,8 +193,8 @@ bootstrap_cc_library(
deps = [ deps = [
":base", ":base",
":collections", ":collections",
":mem",
":port", ":port",
":upb",
], ],
) )
@ -293,7 +266,6 @@ bootstrap_cc_library(
":mini_descriptor_internal", ":mini_descriptor_internal",
":mini_table", ":mini_table",
":port", ":port",
":upb",
], ],
) )
@ -499,10 +471,10 @@ cc_test(
deps = [ deps = [
":descriptor_upb_proto", ":descriptor_upb_proto",
":hash", ":hash",
":mem",
":port", ":port",
":reflection", ":reflection",
":reflection_internal", ":reflection_internal",
":upb",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -563,7 +535,6 @@ upb_amalgamation(
":port", ":port",
":reflection_internal", ":reflection_internal",
":reflection", ":reflection",
":upb",
":wire_internal", ":wire_internal",
":wire_reader", ":wire_reader",
":wire_types", ":wire_types",
@ -610,7 +581,6 @@ upb_amalgamation(
":port", ":port",
":reflection_internal", ":reflection_internal",
":reflection", ":reflection",
":upb",
":wire_internal", ":wire_internal",
":wire_reader", ":wire_reader",
":wire_types", ":wire_types",
@ -658,7 +628,6 @@ upb_amalgamation(
":port", ":port",
":reflection_internal", ":reflection_internal",
":reflection", ":reflection",
":upb",
":wire_internal", ":wire_internal",
":wire_reader", ":wire_reader",
":wire_types", ":wire_types",

@ -52,7 +52,6 @@ cc_library(
"//:message", "//:message",
"//:reflection", "//:reflection",
"//:text", "//:text",
"//:upb",
"@lua//:liblua", "@lua//:liblua",
], ],
) )

@ -56,7 +56,6 @@ cc_library(
"//:message_copy", "//:message_copy",
"//:mini_table", "//:mini_table",
"//:port", "//:port",
"//:upb",
"@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
], ],
@ -74,6 +73,7 @@ cc_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
":protos_extension_lock", ":protos_extension_lock",
"//:base",
"//:mem", "//:mem",
"//:message", "//:message",
"//:message_copy", "//:message_copy",
@ -81,7 +81,6 @@ cc_library(
"//:message_promote", "//:message_promote",
"//:message_typedef", "//:message_typedef",
"//:mini_table", "//:mini_table",
"//:upb",
"//:wire", "//:wire",
"@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/status", "@com_google_absl//absl/status",
@ -111,7 +110,6 @@ cc_library(
"//:mem", "//:mem",
"//:message_typedef", "//:message_typedef",
"//:mini_table", "//:mini_table",
"//:upb",
"@com_google_absl//absl/status", "@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor", "@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/strings:str_format",
@ -155,7 +153,6 @@ cc_test(
deps = [ deps = [
":protos_internal", ":protos_internal",
"//:mem", "//:mem",
"//:upb",
"//protos_generator/tests:test_model_upb_cc_proto", "//protos_generator/tests:test_model_upb_cc_proto",
"//protos_generator/tests:test_model_upb_proto", "//protos_generator/tests:test_model_upb_proto",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
@ -181,7 +178,7 @@ cc_test(
name = "protos_extension_lock_test", name = "protos_extension_lock_test",
srcs = ["protos_extension_lock_test.cc"], srcs = ["protos_extension_lock_test.cc"],
deps = [ deps = [
"//:upb", "//:mem",
"//protos", "//protos",
"//protos:protos_extension_lock", "//protos:protos_extension_lock",
"//protos_generator/tests:test_model_upb_cc_proto", "//protos_generator/tests:test_model_upb_cc_proto",

@ -36,10 +36,10 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "upb/mem/arena.h" #include "upb/base/status.hpp"
#include "upb/mem/arena.hpp"
#include "upb/message/copy.h" #include "upb/message/copy.h"
#include "upb/message/internal/extension.h" #include "upb/message/internal/extension.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.h" #include "upb/wire/decode.h"
#include "upb/wire/encode.h" #include "upb/wire/encode.h"

@ -12,7 +12,7 @@
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "protos/protos.h" #include "protos/protos.h"
#include "protos_generator/tests/test_model.upb.proto.h" #include "protos_generator/tests/test_model.upb.proto.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
#ifndef ASSERT_OK #ifndef ASSERT_OK
#define ASSERT_OK(x) ASSERT_TRUE(x.ok()) #define ASSERT_OK(x) ASSERT_TRUE(x.ok())

@ -141,7 +141,6 @@ void WriteHeader(const protobuf::FileDescriptor* file, Output& output) {
#include "protos/protos.h" #include "protos/protos.h"
#include "protos/protos_internal.h" #include "protos/protos_internal.h"
#include "protos/repeated_field.h" #include "protos/repeated_field.h"
#include "upb/upb.hpp"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"

@ -151,7 +151,6 @@ cc_test(
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
"@com_google_absl//absl/status:statusor", "@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"//:upb",
"//protos", "//protos",
"//protos:repeated_field", "//protos:repeated_field",
], ],

@ -44,7 +44,6 @@
#include "protos_generator/tests/child_model.upb.proto.h" #include "protos_generator/tests/child_model.upb.proto.h"
#include "protos_generator/tests/no_package.upb.proto.h" #include "protos_generator/tests/no_package.upb.proto.h"
#include "protos_generator/tests/test_model.upb.proto.h" #include "protos_generator/tests/test_model.upb.proto.h"
#include "upb/upb.hpp"
using ::protos_generator::test::protos::ChildModel1; using ::protos_generator::test::protos::ChildModel1;
using ::protos_generator::test::protos::other_ext; using ::protos_generator::test::protos::other_ext;

@ -243,7 +243,6 @@ py_extension(
"//:port", "//:port",
"//:reflection", "//:reflection",
"//:text", "//:text",
"//:upb",
"//:wire", "//:wire",
"//:wire_reader", "//:wire_reader",
"//:wire_types", "//:wire_types",

@ -33,6 +33,7 @@ cc_library(
hdrs = [ hdrs = [
"descriptor_constants.h", "descriptor_constants.h",
"status.h", "status.h",
"status.hpp",
"string_view.h", "string_view.h",
], ],
copts = UPB_DEFAULT_COPTS, copts = UPB_DEFAULT_COPTS,
@ -59,6 +60,7 @@ filegroup(
[ [
"**/*.c", "**/*.c",
"**/*.h", "**/*.h",
"**/*.hpp",
], ],
), ),
visibility = [ visibility = [

@ -0,0 +1,73 @@
// 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_BASE_STATUS_HPP_
#define UPB_BASE_STATUS_HPP_
#include "upb/base/status.h"
namespace upb {
class Status {
public:
Status() { upb_Status_Clear(&status_); }
upb_Status* ptr() { return &status_; }
// Returns true if there is no error.
bool ok() const { return upb_Status_IsOk(&status_); }
// Guaranteed to be NULL-terminated.
const char* error_message() const {
return upb_Status_ErrorMessage(&status_);
}
// The error message will be truncated if it is longer than
// _kUpb_Status_MaxMessage-4.
void SetErrorMessage(const char* msg) {
upb_Status_SetErrorMessage(&status_, msg);
}
void SetFormattedErrorMessage(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
upb_Status_VSetErrorFormat(&status_, fmt, args);
va_end(args);
}
// Resets the status to a successful state with no message.
void Clear() { upb_Status_Clear(&status_); }
private:
upb_Status status_;
};
} // namespace upb
#endif // UPB_BASE_STATUS_HPP_

@ -91,7 +91,7 @@ cc_test(
deps = [ deps = [
":collections", ":collections",
"//:base", "//:base",
"//:upb", "//:mem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
@ -102,7 +102,7 @@ cc_test(
deps = [ deps = [
":collections", ":collections",
"//:base", "//:base",
"//:upb", "//:mem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -28,9 +28,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gtest/gtest.h"
#include "upb/collections/array.h" #include "upb/collections/array.h"
#include "upb/upb.hpp"
#include "gtest/gtest.h"
#include "upb/base/status.hpp"
#include "upb/mem/arena.hpp"
TEST(ArrayTest, Resize) { TEST(ArrayTest, Resize) {
upb::Arena arena; upb::Arena arena;

@ -28,10 +28,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upb/collections/map.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/collections/map.h" #include "upb/mem/arena.hpp"
#include "upb/upb.hpp"
TEST(MapTest, DeleteRegression) { TEST(MapTest, DeleteRegression) {
upb::Arena arena; upb::Arena arena;

@ -50,8 +50,9 @@ cc_test(
srcs = ["test.cc"], srcs = ["test.cc"],
deps = [ deps = [
":hash", ":hash",
"//:mem",
"//:port", "//:port",
"//:upb", "@com_google_absl//absl/container:flat_hash_map",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -37,13 +37,13 @@
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <unordered_map>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
#include "upb/hash/int_table.h" #include "upb/hash/int_table.h"
#include "upb/hash/str_table.h" #include "upb/hash/str_table.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"
@ -146,7 +146,7 @@ TEST_P(IntTableTest, TestIntTable) {
upb_inttable_init(&t, arena.ptr()); upb_inttable_init(&t, arena.ptr());
uint32_t largest_key = 0; uint32_t largest_key = 0;
std::map<uint32_t, uint32_t> m; std::map<uint32_t, uint32_t> m;
std::unordered_map<uint32_t, uint32_t> hm; absl::flat_hash_map<uint32_t, uint32_t> hm;
for (const auto& key : keys_) { for (const auto& key : keys_) {
largest_key = UPB_MAX((int32_t)largest_key, key); largest_key = UPB_MAX((int32_t)largest_key, key);
upb_value val = upb_value_uint32(key * 2); upb_value val = upb_value_uint32(key * 2);
@ -240,15 +240,15 @@ TEST(Table, Delete) {
upb_inttable_insert(&t, 2, upb_value_bool(true), arena.ptr()); upb_inttable_insert(&t, 2, upb_value_bool(true), arena.ptr());
upb_inttable_insert(&t, 4, upb_value_bool(true), arena.ptr()); upb_inttable_insert(&t, 4, upb_value_bool(true), arena.ptr());
upb_inttable_compact(&t, arena.ptr()); upb_inttable_compact(&t, arena.ptr());
upb_inttable_remove(&t, 0, NULL); upb_inttable_remove(&t, 0, nullptr);
upb_inttable_remove(&t, 2, NULL); upb_inttable_remove(&t, 2, nullptr);
upb_inttable_remove(&t, 4, NULL); upb_inttable_remove(&t, 4, nullptr);
intptr_t iter = UPB_INTTABLE_BEGIN; intptr_t iter = UPB_INTTABLE_BEGIN;
uintptr_t key; uintptr_t key;
upb_value val; upb_value val;
while (upb_inttable_next(&t, &key, &val, &iter)) { while (upb_inttable_next(&t, &key, &val, &iter)) {
ASSERT_TRUE(false); FAIL();
} }
} }

@ -53,7 +53,6 @@ cc_library(
], ],
deps = [ deps = [
":zero_copy_stream", ":zero_copy_stream",
"//:upb",
"//:mem", "//:mem",
"//:port", "//:port",
], ],
@ -65,7 +64,7 @@ cc_test(
srcs = ["string_test.cc"], srcs = ["string_test.cc"],
deps = [ deps = [
":string", ":string",
"//:upb", "//:mem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
@ -81,8 +80,8 @@ cc_test(
":zero_copy_stream", ":zero_copy_stream",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/strings:str_format",
"//:upb",
"//:lex", "//:lex",
"//:mem",
"//:port", "//:port",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -97,7 +96,8 @@ cc_test(
deps = [ deps = [
":chunked_stream", ":chunked_stream",
":zero_copy_stream", ":zero_copy_stream",
"//:upb", "//:base",
"//:mem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -33,7 +33,7 @@
#include <string.h> #include <string.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
TEST(StringTest, Append) { TEST(StringTest, Append) {
upb::Arena arena; upb::Arena arena;

@ -36,7 +36,7 @@
#include "upb/io/chunked_input_stream.h" #include "upb/io/chunked_input_stream.h"
#include "upb/io/string.h" #include "upb/io/string.h"
#include "upb/lex/unicode.h" #include "upb/lex/unicode.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -38,9 +38,10 @@
// the output. // the output.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/base/status.hpp"
#include "upb/io/chunked_input_stream.h" #include "upb/io/chunked_input_stream.h"
#include "upb/io/chunked_output_stream.h" #include "upb/io/chunked_output_stream.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
namespace upb { namespace upb {
namespace { namespace {

@ -36,8 +36,8 @@ cc_test(
":struct_upb_proto", ":struct_upb_proto",
":test_upb_proto", ":test_upb_proto",
":test_upb_proto_reflection", ":test_upb_proto_reflection",
"//:mem",
"//:reflection", "//:reflection",
"//:upb",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
@ -50,8 +50,9 @@ cc_test(
":struct_upb_proto", ":struct_upb_proto",
":test_upb_proto", ":test_upb_proto",
":test_upb_proto_reflection", ":test_upb_proto_reflection",
"//:base",
"//:mem",
"//:reflection", "//:reflection",
"//:upb",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -34,8 +34,8 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/json/test.upb.h" #include "upb/json/test.upb.h"
#include "upb/json/test.upbdefs.h" #include "upb/json/test.upbdefs.h"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/upb.hpp"
static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) { static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) {
upb::Status status; upb::Status status;

@ -32,10 +32,11 @@
#include "google/protobuf/struct.upb.h" #include "google/protobuf/struct.upb.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/base/status.hpp"
#include "upb/json/test.upb.h" #include "upb/json/test.upb.h"
#include "upb/json/test.upbdefs.h" #include "upb/json/test.upbdefs.h"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/upb.hpp"
static std::string JsonEncode(const upb_test_Box* msg, int options) { static std::string JsonEncode(const upb_test_Box* msg, int options) {
upb::Arena a; upb::Arena a;

@ -30,6 +30,7 @@ cc_library(
hdrs = [ hdrs = [
"alloc.h", "alloc.h",
"arena.h", "arena.h",
"arena.hpp",
], ],
copts = UPB_DEFAULT_COPTS, copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
@ -63,7 +64,6 @@ cc_test(
deps = [ deps = [
"//:mem", "//:mem",
"//:port", "//:port",
"//:upb",
"@com_google_absl//absl/random", "@com_google_absl//absl/random",
"@com_google_absl//absl/random:distributions", "@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/synchronization", "@com_google_absl//absl/synchronization",
@ -78,6 +78,7 @@ filegroup(
[ [
"**/*.c", "**/*.c",
"**/*.h", "**/*.h",
"**/*.hpp",
], ],
), ),
visibility = [ visibility = [

@ -28,50 +28,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPB_HPP_ #ifndef UPB_MEM_ARENA_HPP_
#define UPB_HPP_ #define UPB_MEM_ARENA_HPP_
#include <memory> #include <memory>
#include "upb/base/descriptor_constants.h"
#include "upb/base/status.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
namespace upb { namespace upb {
class Status {
public:
Status() { upb_Status_Clear(&status_); }
upb_Status* ptr() { return &status_; }
// Returns true if there is no error.
bool ok() const { return upb_Status_IsOk(&status_); }
// Guaranteed to be NULL-terminated.
const char* error_message() const {
return upb_Status_ErrorMessage(&status_);
}
// The error message will be truncated if it is longer than
// _kUpb_Status_MaxMessage-4.
void SetErrorMessage(const char* msg) {
upb_Status_SetErrorMessage(&status_, msg);
}
void SetFormattedErrorMessage(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
upb_Status_VSetErrorFormat(&status_, fmt, args);
va_end(args);
}
// Resets the status to a successful state with no message.
void Clear() { upb_Status_Clear(&status_); }
private:
upb_Status status_;
};
class Arena { class Arena {
public: public:
// A simple arena with no initial memory block and the default allocator. // A simple arena with no initial memory block and the default allocator.
@ -109,4 +74,4 @@ class InlinedArena : public Arena {
} // namespace upb } // namespace upb
#endif // UPB_HPP_ #endif // UPB_MEM_ARENA_HPP_

@ -40,7 +40,6 @@
#include "absl/random/distributions.h" #include "absl/random/distributions.h"
#include "absl/random/random.h" #include "absl/random/random.h"
#include "absl/synchronization/notification.h" #include "absl/synchronization/notification.h"
#include "upb/upb.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -237,7 +237,6 @@ cc_test(
"//:mini_descriptor_internal", "//:mini_descriptor_internal",
"//:mini_table", "//:mini_table",
"//:port", "//:port",
"//:upb",
"//:wire", "//:wire",
"//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_messages_proto3_upb_proto",
@ -259,7 +258,6 @@ cc_test(
"//:collections", "//:collections",
"//:mem", "//:mem",
"//:mini_table", "//:mini_table",
"//:upb",
"//:wire", "//:wire",
"//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_messages_proto3_upb_proto",
@ -279,10 +277,10 @@ cc_test(
":promote", ":promote",
"//:base", "//:base",
"//:collections", "//:collections",
"//:mem",
"//:mini_descriptor_internal", "//:mini_descriptor_internal",
"//:mini_table", "//:mini_table",
"//:port", "//:port",
"//:upb",
"//:wire", "//:wire",
"//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_messages_proto3_upb_proto",
@ -301,9 +299,10 @@ cc_test(
deps = [ deps = [
":message_test_upb_proto", ":message_test_upb_proto",
":message_test_upb_proto_reflection", ":message_test_upb_proto_reflection",
"//:base",
"//:json", "//:json",
"//:mem",
"//:reflection", "//:reflection",
"//:upb",
"//:wire", "//:wire",
"//upb/test:fuzz_util", "//upb/test:fuzz_util",
"//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_messages_proto3_upb_proto",

@ -43,12 +43,12 @@
#include "google/protobuf/test_messages_proto3.upb.h" #include "google/protobuf/test_messages_proto3.upb.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/collections/array.h" #include "upb/collections/array.h"
#include "upb/mem/arena.hpp"
#include "upb/message/accessors.h" #include "upb/message/accessors.h"
#include "upb/message/copy.h" #include "upb/message/copy.h"
#include "upb/mini_descriptor/internal/encode.hpp" #include "upb/mini_descriptor/internal/encode.hpp"
#include "upb/mini_descriptor/internal/modifiers.h" #include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/test/test.upb.h" #include "upb/test/test.upb.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.h" #include "upb/wire/decode.h"
// Must be last // Must be last

@ -34,13 +34,14 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "google/protobuf/test_messages_proto3.upb.h" #include "google/protobuf/test_messages_proto3.upb.h"
#include "upb/base/status.hpp"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/mem/arena.hpp"
#include "upb/message/test.upb.h" #include "upb/message/test.upb.h"
#include "upb/message/test.upbdefs.h" #include "upb/message/test.upbdefs.h"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/test/fuzz_util.h" #include "upb/test/fuzz_util.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.h" #include "upb/wire/decode.h"
// begin:google_only // begin:google_only

@ -58,9 +58,10 @@ cc_test(
deps = [ deps = [
":internal", ":internal",
":mini_descriptor", ":mini_descriptor",
"//:base",
"//:mem",
"//:message_accessors_internal", "//:message_accessors_internal",
"//:mini_table", "//:mini_table",
"//:upb",
"//:wire", "//:wire",
"@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:flat_hash_set",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",

@ -37,12 +37,13 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "upb/base/status.hpp"
#include "upb/mem/arena.hpp"
#include "upb/message/internal/accessors.h" #include "upb/message/internal/accessors.h"
#include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/base92.h" #include "upb/mini_descriptor/internal/base92.h"
#include "upb/mini_descriptor/internal/modifiers.h" #include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/mini_table/enum.h" #include "upb/mini_table/enum.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.h" #include "upb/wire/decode.h"
// begin:google_only // begin:google_only
@ -57,7 +58,7 @@ TEST_P(MiniTableTest, Empty) {
upb::Arena arena; upb::Arena arena;
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable* table =
_upb_MiniTable_Build(NULL, 0, GetParam(), arena.ptr(), status.ptr()); _upb_MiniTable_Build(nullptr, 0, GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(0, table->field_count); EXPECT_EQ(0, table->field_count);
EXPECT_EQ(0, table->required_count); EXPECT_EQ(0, table->required_count);

@ -36,11 +36,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "upb/base/status.hpp"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.h" #include "upb/reflection/def.h"
#include "upb/reflection/internal/def_pool.h" #include "upb/reflection/internal/def_pool.h"
#include "upb/reflection/internal/enum_def.h" #include "upb/reflection/internal/enum_def.h"
#include "upb/reflection/message.h" #include "upb/reflection/message.h"
#include "upb/upb.hpp"
// Must be last // Must be last
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -32,7 +32,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -138,7 +138,7 @@ cc_library(
hdrs = ["fuzz_util.h"], hdrs = ["fuzz_util.h"],
visibility = ["//:__subpackages__"], visibility = ["//:__subpackages__"],
deps = [ deps = [
"//:upb", "//:base",
"//:message", "//:message",
"//:mini_descriptor", "//:mini_descriptor",
"//:mini_table", "//:mini_table",
@ -168,7 +168,6 @@ cc_test(
":test_cpp_upb_proto_reflection", ":test_cpp_upb_proto_reflection",
":timestamp_upb_proto", ":timestamp_upb_proto",
":timestamp_upb_proto_reflection", ":timestamp_upb_proto_reflection",
"//:upb",
"//:json", "//:json",
"//:port", "//:port",
"//:reflection", "//:reflection",
@ -186,7 +185,6 @@ cc_test(
":test_messages_proto2_upb_proto", ":test_messages_proto2_upb_proto",
":test_messages_proto3_upb_proto", ":test_messages_proto3_upb_proto",
":test_upb_proto", ":test_upb_proto",
"//:upb",
"//:base", "//:base",
"//:collections", "//:collections",
"//:mem", "//:mem",
@ -205,7 +203,6 @@ cc_test(
":test_messages_proto2_upb_proto", ":test_messages_proto2_upb_proto",
":test_messages_proto3_upb_proto", ":test_messages_proto3_upb_proto",
":test_upb_proto", ":test_upb_proto",
"//:upb",
"//:mini_table", "//:mini_table",
"//:mini_table_internal", "//:mini_table_internal",
"//:port", "//:port",

@ -30,11 +30,11 @@
#include "upb/test/fuzz_util.h" #include "upb/test/fuzz_util.h"
#include "upb/base/status.hpp"
#include "upb/message/message.h" #include "upb/message/message.h"
#include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/decode.h"
#include "upb/mini_table/extension.h" #include "upb/mini_table/extension.h"
#include "upb/mini_table/extension_registry.h" #include "upb/mini_table/extension_registry.h"
#include "upb/upb.hpp"
// Must be last // Must be last
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -42,9 +42,8 @@
#include "upb/base/status.h" #include "upb/base/status.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/collections/array.h" #include "upb/collections/array.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.hpp"
#include "upb/test/test.upb.h" #include "upb/test/test.upb.h"
#include "upb/upb.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -34,7 +34,6 @@
#include "upb/mini_table/field.h" #include "upb/mini_table/field.h"
#include "upb/mini_table/message.h" #include "upb/mini_table/message.h"
#include "upb/test/test.upb.h" #include "upb/test/test.upb.h"
#include "upb/upb.hpp"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"

@ -49,9 +49,10 @@ cc_library(
hdrs = ["def_to_proto_test.h"], hdrs = ["def_to_proto_test.h"],
deps = [ deps = [
":def_to_proto", ":def_to_proto",
"//:base",
"//:descriptor_upb_proto", "//:descriptor_upb_proto",
"//:mem",
"//:reflection_internal", "//:reflection_internal",
"//:upb",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf", "@com_google_protobuf//:protobuf",
], ],
@ -66,8 +67,8 @@ cc_test(
":def_to_proto_test_upb_proto", ":def_to_proto_test_upb_proto",
":def_to_proto_test_upb_proto_reflection", ":def_to_proto_test_upb_proto_reflection",
"//:descriptor_upb_proto_reflection", "//:descriptor_upb_proto_reflection",
"//:mem",
"//:reflection", "//:reflection",
"//:upb",
"//upb/test:parse_text_proto", "//upb/test:parse_text_proto",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
@ -124,9 +125,10 @@ cc_test(
":required_fields", ":required_fields",
":required_fields_test_upb_proto", ":required_fields_test_upb_proto",
":required_fields_test_upb_proto_reflection", ":required_fields_test_upb_proto_reflection",
"//:base",
"//:json", "//:json",
"//:mem",
"//:reflection", "//:reflection",
"//:upb",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],

@ -39,9 +39,9 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "google/protobuf/dynamic_message.h" #include "google/protobuf/dynamic_message.h"
#include "google/protobuf/util/message_differencer.h" #include "google/protobuf/util/message_differencer.h"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/test/parse_text_proto.h" #include "upb/test/parse_text_proto.h"
#include "upb/upb.hpp"
#include "upb/util/def_to_proto_test.h" #include "upb/util/def_to_proto_test.h"
#include "upb/util/def_to_proto_test.upbdefs.h" #include "upb/util/def_to_proto_test.upbdefs.h"

@ -40,8 +40,9 @@
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/dynamic_message.h" #include "google/protobuf/dynamic_message.h"
#include "google/protobuf/util/field_comparator.h" #include "google/protobuf/util/field_comparator.h"
#include "upb/base/status.hpp"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/upb.hpp"
#include "upb/util/def_to_proto.h" #include "upb/util/def_to_proto.h"
namespace upb_test { namespace upb_test {

@ -33,9 +33,10 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "upb/base/status.hpp"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/mem/arena.hpp"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/upb.hpp"
#include "upb/util/required_fields_test.upb.h" #include "upb/util/required_fields_test.upb.h"
#include "upb/util/required_fields_test.upbdefs.h" #include "upb/util/required_fields_test.upbdefs.h"

@ -117,7 +117,7 @@ cc_test(
srcs = ["eps_copy_input_stream_test.cc"], srcs = ["eps_copy_input_stream_test.cc"],
deps = [ deps = [
":eps_copy_input_stream", ":eps_copy_input_stream",
"//:upb", "//:mem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -35,7 +35,7 @@
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "upb/upb.hpp" #include "upb/mem/arena.hpp"
// begin:google_only // begin:google_only
// #include "testing/fuzzing/fuzztest.h" // #include "testing/fuzzing/fuzztest.h"
// end:google_only // end:google_only

@ -130,11 +130,11 @@ bootstrap_cc_library(
copts = UPB_DEFAULT_CPPOPTS, copts = UPB_DEFAULT_CPPOPTS,
visibility = ["//protos_generator:__pkg__"], visibility = ["//protos_generator:__pkg__"],
deps = [ deps = [
"//:base",
"//:mini_descriptor", "//:mini_descriptor",
"//:mini_table", "//:mini_table",
"//:mini_table_internal", "//:mini_table_internal",
"//:port", "//:port",
"//:upb",
"@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
], ],

@ -46,10 +46,10 @@
// end:github_only // end:github_only
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "upb/base/status.hpp"
#include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/decode.h"
#include "upb/reflection/def.h" #include "upb/reflection/def.h"
#include "upb/reflection/def.hpp" #include "upb/reflection/def.hpp"
#include "upb/upb.hpp"
// Must be last // Must be last
#include "upb/port/def.inc" #include "upb/port/def.inc"

Loading…
Cancel
Save