Merge branch 'main' into minitable-api

pull/13171/head
Joshua Haberman 3 years ago
commit 1c45011b3e
  1. 25
      BUILD
  2. 2
      bazel/BUILD
  3. 4
      cmake/CMakeLists.txt
  4. 23
      python/BUILD
  5. 116
      python/pb_unit_tests/BUILD
  6. 3
      upb/fuzz/BUILD
  7. 12
      upb/msg_internal.h
  8. 2
      upb/test_generated_code.cc
  9. 1
      upb/test_table.cc
  10. 29
      upb/util/BUILD
  11. 14
      upbc/protoc-gen-upb.cc

25
BUILD

@ -135,9 +135,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",
@ -212,6 +212,7 @@ cc_library(
name = "textformat",
srcs = [
"upb/text_encode.c",
"upb/upb_internal.h",
],
hdrs = [
"upb/text_encode.h",
@ -229,6 +230,7 @@ cc_library(
srcs = [
"upb/json_decode.c",
"upb/json_encode.c",
"upb/upb_internal.h",
],
hdrs = [
"upb/json_decode.h",
@ -284,31 +286,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(
@ -321,6 +326,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"],
@ -328,6 +343,8 @@ cc_test(
deps = [
":test_cpp_upb_proto",
":test_cpp_upb_proto_reflection",
":timestamp_upb_proto",
":timestamp_upb_proto_reflection",
"//:json",
"//:port",
"//:reflection",

@ -25,6 +25,8 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
licenses(["notice"])
py_binary(
name = "amalgamate",
srcs = ["amalgamate.py"],

@ -89,9 +89,9 @@ target_link_libraries(mini_table
upb)
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)
@ -118,6 +118,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
@ -125,6 +126,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

@ -36,6 +36,8 @@ load(
"py_wheel",
)
licenses(["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",

@ -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,
)

@ -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"],

@ -50,6 +50,18 @@
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

@ -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";

@ -354,7 +354,6 @@ class TypedIntTable {
} // namespace upb
bool benchmark = false;
#define CPU_TIME_PER_TEST 0.5
using std::vector;

@ -1,26 +1,27 @@
load(
"//bazel:upb_proto_library.bzl",
"upb_proto_library",
"upb_proto_reflection_library",
)
licenses(["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",
],
)

@ -313,7 +313,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) {
@ -324,13 +324,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:

Loading…
Cancel
Save