From 9f8c08083255c432cccfe707e4cc0d697400a25a Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 19 Feb 2022 17:35:17 -0500 Subject: [PATCH 01/15] add missing license lines to bazel files --- bazel/BUILD | 2 ++ upb/fuzz/BUILD | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bazel/BUILD b/bazel/BUILD index 1564219b32..148f4a0bee 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -25,6 +25,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +licenses(["notice"]) + py_binary( name = "amalgamate", srcs = ["amalgamate.py"], diff --git a/upb/fuzz/BUILD b/upb/fuzz/BUILD index 3dd5a35744..4719531fb2 100644 --- a/upb/fuzz/BUILD +++ b/upb/fuzz/BUILD @@ -1,6 +1,7 @@ - load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") +licenses(["notice"]) + cc_fuzz_test( name = "file_descriptor_parsenew_fuzzer", srcs = ["file_descriptor_parsenew_fuzzer.cc"], From 9d9e36125c631b63f45992e90ce9ae5f2b470fa3 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 19 Feb 2022 17:38:29 -0500 Subject: [PATCH 02/15] another license --- python/pb_unit_tests/BUILD | 116 +++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index 2c28f2c784..bcea96ecf1 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -23,229 +23,231 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) + py_test( name = "descriptor_database_test", - main = "descriptor_database_test_wrapper.py", srcs = ["descriptor_database_test_wrapper.py"], + legacy_create_init = False, + main = "descriptor_database_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "descriptor_pool_test", - main = "descriptor_pool_test_wrapper.py", srcs = ["descriptor_pool_test_wrapper.py"], + legacy_create_init = False, + main = "descriptor_pool_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "descriptor_test", - main = "descriptor_test_wrapper.py", srcs = ["descriptor_test_wrapper.py"], + legacy_create_init = False, + main = "descriptor_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "generator_test", - main = "generator_test_wrapper.py", srcs = ["generator_test_wrapper.py"], + legacy_create_init = False, + main = "generator_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "json_format_test", - main = "json_format_test_wrapper.py", srcs = ["json_format_test_wrapper.py"], + legacy_create_init = False, + main = "json_format_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "keywords_test", - main = "keywords_test_wrapper.py", srcs = ["keywords_test_wrapper.py"], + legacy_create_init = False, + main = "keywords_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "message_factory_test", - main = "message_factory_test_wrapper.py", srcs = ["message_factory_test_wrapper.py"], + legacy_create_init = False, + main = "message_factory_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "message_test", - main = "message_test_wrapper.py", srcs = ["message_test_wrapper.py"], + data = [ + "@com_google_protobuf//:testdata", + ], + legacy_create_init = False, + main = "message_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - data = [ - "@com_google_protobuf//:testdata", - ], - legacy_create_init = False, ) py_test( name = "proto_builder_test", - main = "proto_builder_test_wrapper.py", srcs = ["proto_builder_test_wrapper.py"], + legacy_create_init = False, + main = "proto_builder_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "reflection_test", - main = "reflection_test_wrapper.py", srcs = ["reflection_test_wrapper.py"], + legacy_create_init = False, + main = "reflection_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "service_reflection_test", - main = "service_reflection_test_wrapper.py", srcs = ["service_reflection_test_wrapper.py"], + legacy_create_init = False, + main = "service_reflection_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "symbol_database_test", - main = "symbol_database_test_wrapper.py", srcs = ["symbol_database_test_wrapper.py"], + legacy_create_init = False, + main = "symbol_database_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "text_encoding_test", - main = "text_encoding_test_wrapper.py", srcs = ["text_encoding_test_wrapper.py"], + legacy_create_init = False, + main = "text_encoding_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "text_format_test", - main = "text_format_test_wrapper.py", srcs = ["text_format_test_wrapper.py"], + data = [ + "@com_google_protobuf//:testdata", + ], + legacy_create_init = False, + main = "text_format_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - data = [ - "@com_google_protobuf//:testdata", - ], - legacy_create_init = False, ) py_test( name = "unknown_fields_test", - main = "unknown_fields_test_wrapper.py", srcs = ["unknown_fields_test_wrapper.py"], + legacy_create_init = False, + main = "unknown_fields_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "well_known_types_test", - main = "well_known_types_test_wrapper.py", srcs = ["well_known_types_test_wrapper.py"], + legacy_create_init = False, + main = "well_known_types_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) py_test( name = "wire_format_test", - main = "wire_format_test_wrapper.py", srcs = ["wire_format_test_wrapper.py"], + legacy_create_init = False, + main = "wire_format_test_wrapper.py", deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - legacy_create_init = False, ) From cce4cffd85d1ae90bb334cf8f97e88dba2571447 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 19 Feb 2022 17:57:37 -0500 Subject: [PATCH 03/15] more licenses --- python/BUILD | 23 ++++++++++++++--------- upb/util/BUILD | 29 +++++++++++++++-------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/python/BUILD b/python/BUILD index 158b79e010..a146fb14b1 100644 --- a/python/BUILD +++ b/python/BUILD @@ -36,6 +36,8 @@ load( "py_wheel", ) +license(["notice"]) + cc_binary( name = "message", srcs = [ @@ -68,16 +70,19 @@ cc_binary( # the module. linkopts = select({ "@platforms//os:linux": ["-Wl,--version-script,$(location :version_script.lds)"], - "@platforms//os:macos": ["-Wl,-exported_symbol", "-Wl,_PyInit__message"], + "@platforms//os:macos": [ + "-Wl,-exported_symbol", + "-Wl,_PyInit__message", + ], }), linkshared = True, linkstatic = True, deps = [ ":version_script.lds", + "//:descriptor_upb_proto_reflection", "//:reflection", "//:textformat", "//:upb", - "//:descriptor_upb_proto_reflection", "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", @@ -90,11 +95,11 @@ cc_binary( srcs = [ "api_implementation.c", ], + linkshared = True, + linkstatic = True, # Enable once linker script is available. #copts = ["-fvisibility=hidden"], deps = ["@system_python//:python_headers"], - linkshared = True, - linkstatic = True, ) # Copy the extensions into the location recognized by Python. @@ -136,14 +141,14 @@ py_test( srcs = [ "minimal_test.py", ], + imports = ["."], + legacy_create_init = False, deps = [ "//python:message_ext", - "@com_google_protobuf//:python_srcs", "@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", ], - imports = ["."], - legacy_create_init = False, ) py_proto_library( @@ -168,13 +173,13 @@ py_wheel( name = "binary_wheel", abi = "abi3", distribution = "protobuf", - python_tag = "cp36", # TODO(https://github.com/protocolbuffers/upb/issues/502): we need to make # this a select() that is calculated from the platform we are actually # building on. platform = "manylinux2014_x86_64", - version = "4.20.0", + python_tag = "cp36", strip_path_prefixes = ["python/"], + version = "4.20.0", deps = [ ":extension_files", ":well_known_proto_pb2", diff --git a/upb/util/BUILD b/upb/util/BUILD index 07649dedcb..65b64b2350 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -1,26 +1,27 @@ - load( "//bazel:upb_proto_library.bzl", "upb_proto_library", "upb_proto_reflection_library", ) +license(["notice"]) + # Def to Proto cc_library( name = "def_to_proto", srcs = ["def_to_proto.c"], hdrs = ["def_to_proto.h"], - deps = ["//:reflection"], visibility = ["//visibility:public"], + deps = ["//:reflection"], ) proto_library( name = "def_to_proto_test_proto", srcs = [ - "def_to_proto_test.proto", - "def_to_proto_regular_import_test.proto", "def_to_proto_public_import_test.proto", + "def_to_proto_regular_import_test.proto", + "def_to_proto_test.proto", "def_to_proto_weak_import_test.proto", ], ) @@ -39,13 +40,13 @@ cc_test( name = "def_to_proto_test", srcs = ["def_to_proto_test.cc"], deps = [ - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest_main", - "//:descriptor_upb_proto_reflection", - "@com_google_protobuf//:protobuf", ":def_to_proto", ":def_to_proto_test_upb_proto", ":def_to_proto_test_upb_proto_reflection", + "//:descriptor_upb_proto_reflection", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest_main", + "@com_google_protobuf//:protobuf", ], ) @@ -55,8 +56,8 @@ cc_library( name = "required_fields", srcs = ["required_fields.c"], hdrs = ["required_fields.h"], - deps = ["//:reflection"], visibility = ["//visibility:public"], + deps = ["//:reflection"], ) proto_library( @@ -78,12 +79,12 @@ cc_test( name = "required_fields_test", srcs = ["required_fields_test.cc"], deps = [ - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest_main", - "//:json", ":required_fields", ":required_fields_test_upb_proto", ":required_fields_test_upb_proto_reflection", + "//:json", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest_main", ], ) @@ -93,16 +94,16 @@ cc_library( name = "compare", srcs = ["compare.c"], hdrs = ["compare.h"], - deps = ["//:reflection"], visibility = ["//visibility:public"], + deps = ["//:reflection"], ) cc_test( name = "compare_test", srcs = ["compare_test.cc"], deps = [ + ":compare", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", - ":compare", ], ) From bf043418053d80bf8573f7c8d57b9af4ab6f6d51 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 19 Feb 2022 18:07:33 -0500 Subject: [PATCH 04/15] more licenses --- python/BUILD | 2 +- upb/util/BUILD | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/BUILD b/python/BUILD index a146fb14b1..8126f52200 100644 --- a/python/BUILD +++ b/python/BUILD @@ -36,7 +36,7 @@ load( "py_wheel", ) -license(["notice"]) +licenses(["notice"]) cc_binary( name = "message", diff --git a/upb/util/BUILD b/upb/util/BUILD index 65b64b2350..d81cb43cb8 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -4,7 +4,7 @@ load( "upb_proto_reflection_library", ) -license(["notice"]) +licenses(["notice"]) # Def to Proto From 61b0905040936613a3e7d20ca89a5f90dbc1788f Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 19 Feb 2022 19:35:58 -0500 Subject: [PATCH 05/15] add some missing testonly attributes --- BUILD | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BUILD b/BUILD index aaf356d55a..0c4d8c76c9 100644 --- a/BUILD +++ b/BUILD @@ -113,9 +113,9 @@ cc_library( name = "fastdecode", srcs = [ "upb/decode.h", - "upb/decode_internal.h", "upb/decode_fast.c", "upb/decode_fast.h", + "upb/decode_internal.h", "upb/msg.h", "upb/msg_internal.h", "upb/upb_internal.h", @@ -262,31 +262,34 @@ upb_proto_library( testonly = 1, deps = ["@com_google_protobuf//:test_messages_proto3_proto"], ) + cc_test( name = "msg_test", srcs = ["upb/msg_test.cc"], deps = [ - "@com_google_googletest//:gtest_main", - ":msg_test_upb_proto_reflection", ":json", + ":msg_test_upb_proto_reflection", + "@com_google_googletest//:gtest_main", ], ) proto_library( name = "msg_test_proto", + testonly = 1, srcs = ["upb/msg_test.proto"], deps = ["@com_google_protobuf//:test_messages_proto3_proto"], ) upb_proto_reflection_library( name = "msg_test_upb_proto_reflection", + testonly = 1, deps = [":msg_test_proto"], ) proto_library( name = "test_cpp_proto", srcs = ["upb/test_cpp.proto"], - deps = ["@com_google_protobuf//:timestamp_proto"] + deps = ["@com_google_protobuf//:timestamp_proto"], ) upb_proto_library( From dc11657df6ce104ca154566246d77afd61016e84 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 11:59:41 -0500 Subject: [PATCH 06/15] Small fixes to compile with stricter warnings --- upb/test_table.cc | 1 - upbc/protoc-gen-upb.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/upb/test_table.cc b/upb/test_table.cc index e1a1d40733..2c368f839c 100644 --- a/upb/test_table.cc +++ b/upb/test_table.cc @@ -354,7 +354,6 @@ class TypedIntTable { } // namespace upb -bool benchmark = false; #define CPU_TIME_PER_TEST 0.5 using std::vector; diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 4703fa7033..da19286766 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -312,7 +312,7 @@ bool HasNonZeroDefault(const protobuf::FieldDescriptor* field) { return field->default_value_enum()->number() != 0; } ABSL_ASSERT(false); - return "XXX"; + return false; } std::string FieldDefault(const protobuf::FieldDescriptor* field) { From 074a469cbe64a441daba2406cdc066b4357805b6 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 13:02:50 -0500 Subject: [PATCH 07/15] sort file list --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 82d518cdbc..83e0c1b562 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -83,9 +83,9 @@ target_link_libraries(upb /third_party/utf8_range) add_library(fastdecode ../upb/decode.h - ../upb/decode_internal.h ../upb/decode_fast.c ../upb/decode_fast.h + ../upb/decode_internal.h ../upb/msg.h ../upb/msg_internal.h ../upb/upb_internal.h) From 9457aa6452b0a79187e3fea3a9b3c759353cfaa4 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 13:43:04 -0500 Subject: [PATCH 08/15] force explicit conversions to desired types in generated code --- upb/upb.h | 18 ++++++++++++++++++ upbc/protoc-gen-upb.cc | 12 ++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/upb/upb.h b/upb/upb.h index 12aecb46cb..5b1824ae9b 100644 --- a/upb/upb.h +++ b/upb/upb.h @@ -90,6 +90,24 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; } +/** upb_*Int* conversion routines ********************************************/ + +UPB_INLINE int32_t upb_Int32_FromI(int v) { + return (int32_t)v; +} + +UPB_INLINE int64_t upb_Int64_FromLL(long long v) { + return (int64_t)v; +} + +UPB_INLINE uint32_t upb_UInt32_FromU(unsigned v) { + return (uint32_t)v; +} + +UPB_INLINE uint64_t upb_UInt64_FromULL(unsigned long long v) { + return (uint64_t)v; +} + #define UPB_STRINGVIEW_INIT(ptr, len) \ { ptr, len } diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index da19286766..6cacda1650 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -323,13 +323,17 @@ std::string FieldDefault(const protobuf::FieldDescriptor* field) { return absl::Substitute("upb_StringView_FromString(\"$0\")", absl::CEscape(field->default_value_string())); case protobuf::FieldDescriptor::CPPTYPE_INT32: - return absl::StrCat(field->default_value_int32()); + return absl::Substitute("upb_Int32_FromI($0)", + field->default_value_int32()); case protobuf::FieldDescriptor::CPPTYPE_INT64: - return absl::StrCat(field->default_value_int64()); + return absl::Substitute("upb_Int64_FromLL($0ll)", + field->default_value_int64()); case protobuf::FieldDescriptor::CPPTYPE_UINT32: - return absl::StrCat(field->default_value_uint32()); + return absl::Substitute("upb_UInt32_FromU($0u)", + field->default_value_uint32()); case protobuf::FieldDescriptor::CPPTYPE_UINT64: - return absl::StrCat(field->default_value_uint64()); + return absl::Substitute("upb_UInt64_FromULL($0ull)", + field->default_value_uint64()); case protobuf::FieldDescriptor::CPPTYPE_FLOAT: return absl::StrCat(field->default_value_float()); case protobuf::FieldDescriptor::CPPTYPE_DOUBLE: From d2ff429dc9e98957428cfb144dec5da552bcbdb9 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 13:44:51 -0500 Subject: [PATCH 09/15] clang-format --- upb/upb.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/upb/upb.h b/upb/upb.h index 5b1824ae9b..335e5fc0e1 100644 --- a/upb/upb.h +++ b/upb/upb.h @@ -92,17 +92,11 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { /** upb_*Int* conversion routines ********************************************/ -UPB_INLINE int32_t upb_Int32_FromI(int v) { - return (int32_t)v; -} +UPB_INLINE int32_t upb_Int32_FromI(int v) { return (int32_t)v; } -UPB_INLINE int64_t upb_Int64_FromLL(long long v) { - return (int64_t)v; -} +UPB_INLINE int64_t upb_Int64_FromLL(long long v) { return (int64_t)v; } -UPB_INLINE uint32_t upb_UInt32_FromU(unsigned v) { - return (uint32_t)v; -} +UPB_INLINE uint32_t upb_UInt32_FromU(unsigned v) { return (uint32_t)v; } UPB_INLINE uint64_t upb_UInt64_FromULL(unsigned long long v) { return (uint64_t)v; From 17f3a0d236ab7e1985ccba84ea29c542bf11ee3b Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 13:51:19 -0500 Subject: [PATCH 10/15] move to internal --- upb/msg_internal.h | 13 +++++++++++++ upb/upb.h | 12 ------------ upbc/protoc-gen-upb.cc | 8 ++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/upb/msg_internal.h b/upb/msg_internal.h index 88c17108f1..60d60b7ce4 100644 --- a/upb/msg_internal.h +++ b/upb/msg_internal.h @@ -50,6 +50,19 @@ extern "C" { #endif +/** upb_*Int* conversion routines ********************************************/ + +UPB_INLINE int32_t _upb_Int32_FromI(int v) { return (int32_t)v; } + +UPB_INLINE int64_t _upb_Int64_FromLL(long long v) { return (int64_t)v; } + +UPB_INLINE uint32_t _upb_UInt32_FromU(unsigned v) { return (uint32_t)v; } + +UPB_INLINE uint64_t _upb_UInt64_FromULL(unsigned long long v) { + return (uint64_t)v; +} + + /** upb_MiniTable *************************************************************/ /* upb_MiniTable represents the memory layout of a given upb_MessageDef. The diff --git a/upb/upb.h b/upb/upb.h index 335e5fc0e1..12aecb46cb 100644 --- a/upb/upb.h +++ b/upb/upb.h @@ -90,18 +90,6 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; } -/** upb_*Int* conversion routines ********************************************/ - -UPB_INLINE int32_t upb_Int32_FromI(int v) { return (int32_t)v; } - -UPB_INLINE int64_t upb_Int64_FromLL(long long v) { return (int64_t)v; } - -UPB_INLINE uint32_t upb_UInt32_FromU(unsigned v) { return (uint32_t)v; } - -UPB_INLINE uint64_t upb_UInt64_FromULL(unsigned long long v) { - return (uint64_t)v; -} - #define UPB_STRINGVIEW_INIT(ptr, len) \ { ptr, len } diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 6cacda1650..ff4a5028f1 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -323,16 +323,16 @@ std::string FieldDefault(const protobuf::FieldDescriptor* field) { return absl::Substitute("upb_StringView_FromString(\"$0\")", absl::CEscape(field->default_value_string())); case protobuf::FieldDescriptor::CPPTYPE_INT32: - return absl::Substitute("upb_Int32_FromI($0)", + return absl::Substitute("_upb_Int32_FromI($0)", field->default_value_int32()); case protobuf::FieldDescriptor::CPPTYPE_INT64: - return absl::Substitute("upb_Int64_FromLL($0ll)", + return absl::Substitute("_upb_Int64_FromLL($0ll)", field->default_value_int64()); case protobuf::FieldDescriptor::CPPTYPE_UINT32: - return absl::Substitute("upb_UInt32_FromU($0u)", + return absl::Substitute("_upb_UInt32_FromU($0u)", field->default_value_uint32()); case protobuf::FieldDescriptor::CPPTYPE_UINT64: - return absl::Substitute("upb_UInt64_FromULL($0ull)", + return absl::Substitute("_upb_UInt64_FromULL($0ull)", field->default_value_uint64()); case protobuf::FieldDescriptor::CPPTYPE_FLOAT: return absl::StrCat(field->default_value_float()); From 00a88b2426953e8c599ac136bf53e0da43569efa Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 14:03:21 -0500 Subject: [PATCH 11/15] clang-format --- upb/msg_internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/upb/msg_internal.h b/upb/msg_internal.h index 60d60b7ce4..1cad56df7e 100644 --- a/upb/msg_internal.h +++ b/upb/msg_internal.h @@ -62,7 +62,6 @@ UPB_INLINE uint64_t _upb_UInt64_FromULL(unsigned long long v) { return (uint64_t)v; } - /** upb_MiniTable *************************************************************/ /* upb_MiniTable represents the memory layout of a given upb_MessageDef. The From c8f823ef0aeba35b5ae31ef302488a0dc5900c19 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 14:29:19 -0500 Subject: [PATCH 12/15] explicitly include deps for internal headers --- BUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BUILD b/BUILD index 0c4d8c76c9..e4384a1822 100644 --- a/BUILD +++ b/BUILD @@ -190,6 +190,7 @@ cc_library( name = "textformat", srcs = [ "upb/text_encode.c", + "upb/upb_internal.h", ], hdrs = [ "upb/text_encode.h", @@ -207,6 +208,7 @@ cc_library( srcs = [ "upb/json_decode.c", "upb/json_encode.c", + "upb/upb_internal.h", ], hdrs = [ "upb/json_decode.h", From 8b74557e30045886c2f6ec64fac9b589a1d53b8a Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 14:42:55 -0500 Subject: [PATCH 13/15] test for previous definition --- upb/test_generated_code.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/upb/test_generated_code.cc b/upb/test_generated_code.cc index 86d8fe8edc..a3835d6ee5 100644 --- a/upb/test_generated_code.cc +++ b/upb/test_generated_code.cc @@ -35,7 +35,9 @@ #include "upb/test.upb.h" #include "upb/upb.hpp" +#if !defined(MIN) #define MIN(x, y) ((x) < (y) ? (x) : (y)) +#endif const char test_str[] = "abcdefg"; const char test_str2[] = "12345678910"; From 5d7daf1ce25edc4fb5263d85e27986af316b652e Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 15:09:37 -0500 Subject: [PATCH 14/15] fix cmake --- cmake/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 83e0c1b562..7a961b3468 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -112,6 +112,7 @@ target_link_libraries(reflection upb) add_library(textformat ../upb/text_encode.c + ../upb/upb_internal.h ../upb/text_encode.h) target_link_libraries(textformat port @@ -119,6 +120,7 @@ target_link_libraries(textformat add_library(json ../upb/json_decode.c ../upb/json_encode.c + ../upb/upb_internal.h ../upb/json_decode.h ../upb/json_encode.h) target_link_libraries(json From 92d71a4667437f0572d24f960f351232ec6e0ee8 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sun, 20 Feb 2022 15:20:48 -0500 Subject: [PATCH 15/15] make deps explicit --- BUILD | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BUILD b/BUILD index e4384a1822..cf5206fe8d 100644 --- a/BUILD +++ b/BUILD @@ -304,6 +304,16 @@ upb_proto_reflection_library( deps = ["test_cpp_proto"], ) +upb_proto_library( + name = "timestamp_upb_proto", + deps = ["@com_google_protobuf//:timestamp_proto"], +) + +upb_proto_reflection_library( + name = "timestamp_upb_proto_reflection", + deps = ["@com_google_protobuf//:timestamp_proto"], +) + cc_test( name = "test_cpp", srcs = ["upb/test_cpp.cc"], @@ -311,6 +321,8 @@ cc_test( deps = [ ":test_cpp_upb_proto", ":test_cpp_upb_proto_reflection", + ":timestamp_upb_proto", + ":timestamp_upb_proto_reflection", "//:json", "//:port", "//:reflection",