diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 553c46b41cd..68c01837ffc 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -232,9 +232,9 @@ def grpc_deps(): if "upb" not in native.existing_rules(): http_archive( name = "upb", - sha256 = "e9f281c56ab1eb1f97a80ca8a83bb7ef73d230eabb8591f83876f4e7b85d9b47", - strip_prefix = "upb-8a3ae1ef3e3e3f26b45dec735c5776737fc7247f", - url = "https://github.com/protocolbuffers/upb/archive/8a3ae1ef3e3e3f26b45dec735c5776737fc7247f.tar.gz", + sha256 = "e9c136e56b98c8eb48ad1c9f8df4a6348e99f9f336ee6199c4259a312c2e3598", + strip_prefix = "upb-d8f3d6f9d415b31f3ce56d46791706c38fa311bc", + url = "https://github.com/protocolbuffers/upb/archive/d8f3d6f9d415b31f3ce56d46791706c38fa311bc.tar.gz", ) if "envoy_api" not in native.existing_rules(): http_archive( diff --git a/third_party/upb/BUILD b/third_party/upb/BUILD index 040d97c79c9..fa2ad904f4b 100644 --- a/third_party/upb/BUILD +++ b/third_party/upb/BUILD @@ -54,6 +54,17 @@ config_setting( # Public C/C++ libraries ####################################################### +cc_library( + name = "port", + textual_hdrs = [ + "upb/port_def.inc", + "upb/port_undef.inc", + ], + srcs = [ + "upb/port.c", + ], +) + cc_library( name = "upb", srcs = [ @@ -62,9 +73,6 @@ cc_library( "upb/generated_util.h", "upb/msg.c", "upb/msg.h", - "upb/port.c", - "upb/port_def.inc", - "upb/port_undef.inc", "upb/table.c", "upb/table.int.h", "upb/upb.c", @@ -79,6 +87,7 @@ cc_library( "//conditions:default": COPTS, }), visibility = ["//visibility:public"], + deps = [":port"], ) # Common support routines used by generated code. This library has no @@ -92,17 +101,17 @@ cc_library( hdrs = [ "upb/generated_util.h", "upb/msg.h", + "upb/port_def.inc", + "upb/port_undef.inc", ], copts = select({ ":windows": [], "//conditions:default": COPTS, }), - textual_hdrs = [ - "upb/port_def.inc", - "upb/port_undef.inc", - ], visibility = ["//visibility:public"], - deps = [":upb"], + deps = [ + ":upb", + ], ) upb_proto_library( @@ -128,6 +137,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":descriptor_upbproto", + ":port", ":table", ":upb", ], @@ -138,7 +148,10 @@ cc_library( cc_library( name = "table", hdrs = ["upb/table.int.h"], - deps = [":upb"], + deps = [ + ":port", + ":upb", + ], ) # Legacy C/C++ Libraries (not recommended for new code) ######################## @@ -146,6 +159,7 @@ cc_library( cc_library( name = "legacy_msg_reflection", srcs = [ + "upb/msg.h", "upb/legacy_msg_reflection.c", ], hdrs = ["upb/legacy_msg_reflection.h"], @@ -154,6 +168,7 @@ cc_library( "//conditions:default": COPTS, }), deps = [ + ":port", ":table", ":upb", ], @@ -176,6 +191,7 @@ cc_library( }), deps = [ ":reflection", + ":port", ":table", ":upb", ], @@ -205,6 +221,7 @@ cc_library( ":descriptor_upbproto", ":handlers", ":reflection", + ":port", ":table", ":upb", ], @@ -240,6 +257,7 @@ cc_library( deps = [ ":descriptor_upbproto", ":handlers", + ":port", ":upb", ], ) @@ -259,9 +277,9 @@ cc_library( "//conditions:default": CPPOPTS, }), deps = [ - "@absl//absl/base:core_headers", - "@absl//absl/container:flat_hash_map", - "@absl//absl/strings", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", "@com_google_protobuf//:protoc_lib", ], @@ -286,6 +304,11 @@ cc_binary( # C/C++ tests ################################################################## +upb_proto_reflection_library( + name = "descriptor_upbreflection", + deps = ["@com_google_protobuf//:descriptor_proto"], +) + cc_binary( name = "benchmark", testonly = 1, @@ -313,6 +336,7 @@ cc_library( }), deps = [ ":handlers", + ":port", ":upb", ], ) @@ -328,6 +352,7 @@ cc_test( "//conditions:default": COPTS, }), deps = [ + ":port", ":upb", ":upb_pb", ":upb_test", @@ -358,6 +383,7 @@ cc_test( }), deps = [ ":handlers", + ":port", ":test_decoder_upbproto", ":upb", ":upb_pb", @@ -386,6 +412,7 @@ cc_test( }), deps = [ ":handlers", + ":port", ":reflection", ":test_cpp_upbproto", ":upb", @@ -402,6 +429,7 @@ cc_test( "//conditions:default": CPPOPTS, }), deps = [ + ":port", ":table", ":upb", ":upb_test", @@ -431,11 +459,6 @@ cc_binary( ) # copybara:strip_for_google3_begin -upb_proto_reflection_library( - name = "descriptor_upbreflection", - deps = ["@com_google_protobuf//:descriptor_proto"], -) - cc_test( name = "test_encoder", srcs = ["tests/pb/test_encoder.cc"], @@ -563,6 +586,7 @@ upb_amalgamation( ":descriptor_upbproto", ":reflection", ":handlers", + ":port", ":upb_pb", ":upb_json", ], diff --git a/third_party/upb/CMakeLists.txt b/third_party/upb/CMakeLists.txt index 836c5ff1fe5..96b265dd3a7 100644 --- a/third_party/upb/CMakeLists.txt +++ b/third_party/upb/CMakeLists.txt @@ -60,21 +60,22 @@ endif() enable_testing() +add_library(port + upb/port.c) add_library(upb upb/decode.c upb/encode.c upb/generated_util.h upb/msg.c upb/msg.h - upb/port.c - upb/port_def.inc - upb/port_undef.inc upb/table.c upb/table.int.h upb/upb.c upb/decode.h upb/encode.h upb/upb.h) +target_link_libraries(upb + port) add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE) target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE upb) @@ -85,15 +86,19 @@ add_library(reflection upb/msgfactory.h) target_link_libraries(reflection descriptor_upbproto + port table upb) add_library(table INTERFACE) target_link_libraries(table INTERFACE + port upb) add_library(legacy_msg_reflection + upb/msg.h upb/legacy_msg_reflection.c upb/legacy_msg_reflection.h) target_link_libraries(legacy_msg_reflection + port table upb) add_library(handlers @@ -104,6 +109,7 @@ add_library(handlers upb/sink.h) target_link_libraries(handlers reflection + port table upb) add_library(upb_pb @@ -121,6 +127,7 @@ target_link_libraries(upb_pb descriptor_upbproto handlers reflection + port table upb) add_library(upb_json @@ -135,6 +142,7 @@ add_library(upb_cc_bindings INTERFACE) target_link_libraries(upb_cc_bindings INTERFACE descriptor_upbproto handlers + port upb) add_library(upb_test tests/testmain.cc @@ -142,6 +150,7 @@ add_library(upb_test tests/upb_test.h) target_link_libraries(upb_test handlers + port upb) diff --git a/third_party/upb/bazel/upb_proto_library.bzl b/third_party/upb/bazel/upb_proto_library.bzl index b30ce5d9976..bea611776c4 100644 --- a/third_party/upb/bazel/upb_proto_library.bzl +++ b/third_party/upb/bazel/upb_proto_library.bzl @@ -279,6 +279,7 @@ _upb_proto_reflection_library_aspect = aspect( ), "_upb": attr.label_list( default = [ + "//:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", "//:upb", "//:reflection", ], diff --git a/third_party/upb/bazel/workspace_deps.bzl b/third_party/upb/bazel/workspace_deps.bzl index 284277926fd..4aec3ebbd81 100644 --- a/third_party/upb/bazel/workspace_deps.bzl +++ b/third_party/upb/bazel/workspace_deps.bzl @@ -8,7 +8,7 @@ def upb_deps(): ) git_repository( - name = "absl", + name = "com_google_absl", commit = "070f6e47b33a2909d039e620c873204f78809492", remote = "https://github.com/abseil/abseil-cpp.git", shallow_since = "1541627663 -0500", diff --git a/third_party/upb/upb/decode.c b/third_party/upb/upb/decode.c index 4f079885950..4672b1b84ba 100644 --- a/third_party/upb/upb/decode.c +++ b/third_party/upb/upb/decode.c @@ -249,6 +249,10 @@ static upb_msg *upb_addmsg(upb_decframe *frame, upb_msg *submsg; upb_array *arr = upb_getorcreatearr(frame, field); + UPB_ASSERT(field->label == UPB_LABEL_REPEATED); + UPB_ASSERT(field->descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE || + field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP); + *subm = frame->layout->submsgs[field->submsg_index]; submsg = upb_msg_new(*subm, frame->state->arena); CHK(submsg); diff --git a/third_party/upb/upb/port.c b/third_party/upb/upb/port.c index 023f7dc0ce1..9ecf135167a 100644 --- a/third_party/upb/upb/port.c +++ b/third_party/upb/upb/port.c @@ -1,5 +1,4 @@ -#include "upb/upb.h" #include "upb/port_def.inc" #ifdef UPB_MSVC_VSNPRINTF diff --git a/third_party/upb/upb/port_def.inc b/third_party/upb/upb/port_def.inc index a8967b36794..b416eaeaf1a 100644 --- a/third_party/upb/upb/port_def.inc +++ b/third_party/upb/upb/port_def.inc @@ -20,9 +20,7 @@ * * This file is private and must not be included by users! */ -#ifndef UINTPTR_MAX -#error must include stdint.h first -#endif +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 diff --git a/third_party/upb/upb/table.c b/third_party/upb/upb/table.c index 8896d217db6..fd5bc53f962 100644 --- a/third_party/upb/upb/table.c +++ b/third_party/upb/upb/table.c @@ -756,7 +756,8 @@ uint32_t upb_murmur_hash2(const void *key, size_t len, uint32_t seed) { /* Mix 4 bytes at a time into the hash */ const uint8_t * data = (const uint8_t *)key; while(len >= 4) { - uint32_t k = *(uint32_t *)data; + uint32_t k; + memcpy(&k, data, sizeof(k)); k *= m; k ^= k >> r;