From f9d27c0b8c77ebaa42dd1d287e1ec7d0c3682ad4 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Mon, 13 Jan 2020 12:53:08 -0800 Subject: [PATCH] Squashed 'third_party/upb/' changes from 2a25fd557e..d8f3d6f9d4 d8f3d6f9d4 Merge pull request #233 from annarev/add_port_dependencies a27429f265 Add port_def.inc and port_undef.inc to generated code hdrs 3797ad2217 port should not be public 578dc32208 Set port visibility to public. fc4941183f Add :port dependencies to libraries that include it 7d1abedbdd Merge pull request #232 from annarev/forward_assert_changes 1b131ca544 Merge pull request #231 from annarev/fix_build_for_sync d2389ba261 Add correctness asserts to upb_addmsg de1bc11663 Split port into its own target, add msg.h to :legacy_msg_reflection abdf14937d Merge pull request #216 from XrXr/use-memcpy-to-do-unaligned-read 47ab661706 Merge pull request #227 from lizan/absl_workspace_name 0b63c75164 Do not strip :descriptor_upbreflection and make some headers public that are used outside of the their module bcdfe6b1b0 bazel: use canonical repository name for absl a73fd86c13 Use memcpy to perform unaligned reads git-subtree-dir: third_party/upb git-subtree-split: d8f3d6f9d415b31f3ce56d46791706c38fa311bc --- BUILD | 58 ++++++++++++++++++++++++++----------- CMakeLists.txt | 15 ++++++++-- bazel/upb_proto_library.bzl | 3 +- bazel/workspace_deps.bzl | 2 +- upb/decode.c | 4 +++ upb/port.c | 1 - upb/port_def.inc | 4 +-- upb/table.c | 3 +- 8 files changed, 63 insertions(+), 27 deletions(-) diff --git a/BUILD b/BUILD index ad85b202a9a..0166b14c98f 100644 --- a/BUILD +++ b/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/CMakeLists.txt b/CMakeLists.txt index 836c5ff1fe5..96b265dd3a7 100644 --- a/CMakeLists.txt +++ b/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/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index 21ed34b487a..bea611776c4 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -238,7 +238,7 @@ _upb_proto_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" + "//:upb", ]), "_ext": attr.string(default = ".upb"), }), @@ -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/bazel/workspace_deps.bzl b/bazel/workspace_deps.bzl index 23ebae11d1f..a03a643a324 100644 --- a/bazel/workspace_deps.bzl +++ b/bazel/workspace_deps.bzl @@ -9,7 +9,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/upb/decode.c b/upb/decode.c index 4f079885950..4672b1b84ba 100644 --- a/upb/decode.c +++ b/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/upb/port.c b/upb/port.c index 023f7dc0ce1..9ecf135167a 100644 --- a/upb/port.c +++ b/upb/port.c @@ -1,5 +1,4 @@ -#include "upb/upb.h" #include "upb/port_def.inc" #ifdef UPB_MSVC_VSNPRINTF diff --git a/upb/port_def.inc b/upb/port_def.inc index a8967b36794..b416eaeaf1a 100644 --- a/upb/port_def.inc +++ b/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/upb/table.c b/upb/table.c index 8896d217db6..fd5bc53f962 100644 --- a/upb/table.c +++ b/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;