diff --git a/BUILD b/BUILD index adeb5ae937..f5243407fb 100644 --- a/BUILD +++ b/BUILD @@ -55,6 +55,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/encode.c", "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 @@ -96,12 +105,11 @@ cc_library( ":windows": [], "//conditions:default": COPTS }), - textual_hdrs = [ - "upb/port_def.inc", - "upb/port_undef.inc", - ], visibility = ["//visibility:public"], - deps = [":upb"], + deps = [ + ":port", + ":upb", + ], ) upb_proto_library( @@ -137,7 +145,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) ######################## @@ -242,9 +253,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", ], @@ -269,6 +280,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, @@ -423,11 +439,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"], @@ -556,6 +567,7 @@ upb_amalgamation( ":descriptor_upbproto", ":reflection", ":handlers", + ":port", ":upb_pb", ":upb_json", ], @@ -619,7 +631,7 @@ cc_binary( }), visibility = ["//visibility:public"], deps = [ - "@absl//absl/strings", + "@com_google_absl//absl/strings", "@com_google_protobuf//:protoc_lib" ], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index a88176389f..eadb429024 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,22 +60,24 @@ endif() enable_testing() +add_library(port + upb/port.c) add_library(upb upb/decode.c upb/encode.c 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 + port upb) add_library(reflection upb/def.c @@ -88,6 +90,7 @@ target_link_libraries(reflection upb) add_library(table INTERFACE) target_link_libraries(table INTERFACE + port upb) add_library(handlers upb/handlers.c diff --git a/bazel/workspace_deps.bzl b/bazel/workspace_deps.bzl index 23ebae11d1..a03a643a32 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 4a991e564b..dae9b3d1aa 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -250,6 +250,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 023f7dc0ce..9ecf135167 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 a8e5070695..992148e736 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 <stdint.h> #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 diff --git a/upb/table.c b/upb/table.c index 1d01a223d0..21f8fcf6f8 100644 --- a/upb/table.c +++ b/upb/table.c @@ -732,7 +732,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;