Skip to content

Commit

Permalink
Squashed 'third_party/upb/' changes from 92e63da733..382d5afc60
Browse files Browse the repository at this point in the history
382d5afc60 Merge pull request grpc#306 from haberman/bigendian
efefbffc80 Fixed binary encoding and decoding for big-endian machines.
5d3083013c Merge pull request grpc#304 from haberman/upb-assume
55dd9d3e41 Fixed UPB_ASSUME() for non-GCC, non-MSVC platforms.
e4c8afd0d4 Merge pull request grpc#303 from haberman/packed-def
8284321780 Fixed upb_fielddef_packed() to have the correct default.
ed86d98f53 Merge pull request grpc#302 from haberman/verify-utf8
8e26a33bcb Added a test for UTF-8 parse checking and added missing error reporting.
2c666bc8f6 Use C-style comment instead of C++.
a77ea639d5 Verify UTF-8 when parsing proto3 string fields.
7f19072206 Merge pull request grpc#301 from haberman/rm-pop
bfdfe5a914 Removed unused push/pop functions.
1479f2d7ca Merge pull request grpc#299 from haberman/google3-fixes
8f11ec57d2 Applied changes from google3.
7172b981dd Merge pull request grpc#297 from haberman/bugfixes
ffe40c9f94 Only run Valgrind if it is present.
922c126b8b Fixed unit test errors that were causing Valgrind failures.
086a68d191 Fixed memory leak that could occur after upb_arena_fuse().
35abcc248b Added test that should trigger a memory leak.
7d726c8da6 JSON parser: Bugfix for float/double in quotes.
74c60c757b Merge pull request grpc#296 from haberman/php-fixes
efe11c6c50 Removed excess logging statement.
81c2aa753e Fixes for the PHP C Extension.

git-subtree-dir: third_party/upb
git-subtree-split: 382d5afc60e05470c23e8de19b19fc5ad231e732
  • Loading branch information
veblush committed Aug 3, 2020
1 parent b48f821 commit 6d7d35f
Show file tree
Hide file tree
Showing 21 changed files with 304 additions and 110 deletions.
34 changes: 34 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,33 @@ cc_library(
}),
)

upb_amalgamation(
name = "gen_ruby_amalgamation",
prefix = "ruby-",
outs = [
"ruby-upb.c",
"ruby-upb.h",
],
amalgamator = ":amalgamate",
libs = [
":upb",
":descriptor_upb_proto",
":reflection",
":port",
":json",
],
)

cc_library(
name = "ruby_amalgamation",
srcs = ["ruby-upb.c"],
hdrs = ["ruby-upb.h"],
copts = select({
":windows": [],
"//conditions:default": COPTS,
}),
)

# Lua ##########################################################################

cc_library(
Expand Down Expand Up @@ -765,6 +792,7 @@ cc_test(
"upb/bindings/lua/upb.lua",
":descriptor_proto_lua",
":test_messages_proto3_proto_lua",
":test_messages_proto2_proto_lua",
":test_proto_lua",
"@com_google_protobuf//:conformance_proto",
"@com_google_protobuf//:descriptor_proto",
Expand Down Expand Up @@ -807,6 +835,12 @@ lua_proto_library(
deps = ["@com_google_protobuf//:test_messages_proto3_proto"],
)

lua_proto_library(
name = "test_messages_proto2_proto_lua",
testonly = 1,
deps = ["@com_google_protobuf//:test_messages_proto2_proto"],
)

# Test the CMake build #########################################################

filegroup(
Expand Down
3 changes: 3 additions & 0 deletions bazel/upb_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ _WrappedGeneratedSrcsInfo = provider(fields = ["srcs"])
_WrappedDefsGeneratedSrcsInfo = provider(fields = ["srcs"])

def _compile_upb_protos(ctx, proto_info, proto_sources, ext):
if len(proto_sources) == 0:
return GeneratedSrcsInfo(srcs = [], hdrs = [])

srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources]
hdrs = [_generate_output_file(ctx, name, ext + ".h") for name in proto_sources]
transitive_sets = proto_info.transitive_descriptor_sets.to_list()
Expand Down
72 changes: 36 additions & 36 deletions generated_for_cmake/google/protobuf/descriptor.upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6]
};

static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{2, UPB_SIZE(12, 24), 2, 0, 9, 1},
{3, UPB_SIZE(36, 72), 0, 0, 9, 3},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(12, 24), 2, 0, 12, 1},
{3, UPB_SIZE(36, 72), 0, 0, 12, 3},
{4, UPB_SIZE(40, 80), 0, 0, 11, 3},
{5, UPB_SIZE(44, 88), 0, 1, 11, 3},
{6, UPB_SIZE(48, 96), 0, 4, 11, 3},
Expand All @@ -47,7 +47,7 @@ static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12]
{9, UPB_SIZE(32, 64), 5, 5, 11, 1},
{10, UPB_SIZE(56, 112), 0, 0, 5, 3},
{11, UPB_SIZE(60, 120), 0, 0, 5, 3},
{12, UPB_SIZE(20, 40), 3, 0, 9, 1},
{12, UPB_SIZE(20, 40), 3, 0, 12, 1},
};

const upb_msglayout google_protobuf_FileDescriptorProto_msginit = {
Expand All @@ -67,7 +67,7 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = {
};

static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 4, 11, 3},
{3, UPB_SIZE(20, 40), 0, 0, 11, 3},
{4, UPB_SIZE(24, 48), 0, 3, 11, 3},
Expand All @@ -76,7 +76,7 @@ static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
{7, UPB_SIZE(12, 24), 2, 5, 11, 1},
{8, UPB_SIZE(36, 72), 0, 6, 11, 3},
{9, UPB_SIZE(40, 80), 0, 2, 11, 3},
{10, UPB_SIZE(44, 88), 0, 0, 9, 3},
{10, UPB_SIZE(44, 88), 0, 0, 12, 3},
};

const upb_msglayout google_protobuf_DescriptorProto_msginit = {
Expand Down Expand Up @@ -131,16 +131,16 @@ static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1
};

static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = {
{1, UPB_SIZE(36, 40), 6, 0, 9, 1},
{2, UPB_SIZE(44, 56), 7, 0, 9, 1},
{1, UPB_SIZE(36, 40), 6, 0, 12, 1},
{2, UPB_SIZE(44, 56), 7, 0, 12, 1},
{3, UPB_SIZE(24, 24), 3, 0, 5, 1},
{4, UPB_SIZE(8, 8), 1, 0, 14, 1},
{5, UPB_SIZE(16, 16), 2, 0, 14, 1},
{6, UPB_SIZE(52, 72), 8, 0, 9, 1},
{7, UPB_SIZE(60, 88), 9, 0, 9, 1},
{6, UPB_SIZE(52, 72), 8, 0, 12, 1},
{7, UPB_SIZE(60, 88), 9, 0, 12, 1},
{8, UPB_SIZE(76, 120), 11, 0, 11, 1},
{9, UPB_SIZE(28, 28), 4, 0, 5, 1},
{10, UPB_SIZE(68, 104), 10, 0, 9, 1},
{10, UPB_SIZE(68, 104), 10, 0, 12, 1},
{17, UPB_SIZE(32, 32), 5, 0, 8, 1},
};

Expand All @@ -155,7 +155,7 @@ static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1
};

static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(12, 24), 2, 0, 11, 1},
};

Expand All @@ -172,11 +172,11 @@ static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3]
};

static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 2, 11, 3},
{3, UPB_SIZE(12, 24), 2, 1, 11, 1},
{4, UPB_SIZE(20, 40), 0, 0, 11, 3},
{5, UPB_SIZE(24, 48), 0, 0, 9, 3},
{5, UPB_SIZE(24, 48), 0, 0, 12, 3},
};

const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = {
Expand All @@ -201,7 +201,7 @@ static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_subms
};

static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = {
{1, UPB_SIZE(8, 8), 2, 0, 9, 1},
{1, UPB_SIZE(8, 8), 2, 0, 12, 1},
{2, UPB_SIZE(4, 4), 1, 0, 5, 1},
{3, UPB_SIZE(16, 24), 3, 0, 11, 1},
};
Expand All @@ -218,7 +218,7 @@ static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs
};

static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 0, 11, 3},
{3, UPB_SIZE(12, 24), 2, 1, 11, 1},
};
Expand All @@ -234,9 +234,9 @@ static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[
};

static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = {
{1, UPB_SIZE(4, 8), 3, 0, 9, 1},
{2, UPB_SIZE(12, 24), 4, 0, 9, 1},
{3, UPB_SIZE(20, 40), 5, 0, 9, 1},
{1, UPB_SIZE(4, 8), 3, 0, 12, 1},
{2, UPB_SIZE(12, 24), 4, 0, 12, 1},
{3, UPB_SIZE(20, 40), 5, 0, 12, 1},
{4, UPB_SIZE(28, 56), 6, 0, 11, 1},
{5, UPB_SIZE(1, 1), 1, 0, 8, 1},
{6, UPB_SIZE(2, 2), 2, 0, 8, 1},
Expand All @@ -253,26 +253,26 @@ static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = {
};

static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = {
{1, UPB_SIZE(28, 32), 11, 0, 9, 1},
{8, UPB_SIZE(36, 48), 12, 0, 9, 1},
{1, UPB_SIZE(28, 32), 11, 0, 12, 1},
{8, UPB_SIZE(36, 48), 12, 0, 12, 1},
{9, UPB_SIZE(8, 8), 1, 0, 14, 1},
{10, UPB_SIZE(16, 16), 2, 0, 8, 1},
{11, UPB_SIZE(44, 64), 13, 0, 9, 1},
{11, UPB_SIZE(44, 64), 13, 0, 12, 1},
{16, UPB_SIZE(17, 17), 3, 0, 8, 1},
{17, UPB_SIZE(18, 18), 4, 0, 8, 1},
{18, UPB_SIZE(19, 19), 5, 0, 8, 1},
{20, UPB_SIZE(20, 20), 6, 0, 8, 1},
{23, UPB_SIZE(21, 21), 7, 0, 8, 1},
{27, UPB_SIZE(22, 22), 8, 0, 8, 1},
{31, UPB_SIZE(23, 23), 9, 0, 8, 1},
{36, UPB_SIZE(52, 80), 14, 0, 9, 1},
{37, UPB_SIZE(60, 96), 15, 0, 9, 1},
{39, UPB_SIZE(68, 112), 16, 0, 9, 1},
{40, UPB_SIZE(76, 128), 17, 0, 9, 1},
{41, UPB_SIZE(84, 144), 18, 0, 9, 1},
{36, UPB_SIZE(52, 80), 14, 0, 12, 1},
{37, UPB_SIZE(60, 96), 15, 0, 12, 1},
{39, UPB_SIZE(68, 112), 16, 0, 12, 1},
{40, UPB_SIZE(76, 128), 17, 0, 12, 1},
{41, UPB_SIZE(84, 144), 18, 0, 12, 1},
{42, UPB_SIZE(24, 24), 10, 0, 8, 1},
{44, UPB_SIZE(92, 160), 19, 0, 9, 1},
{45, UPB_SIZE(100, 176), 20, 0, 9, 1},
{44, UPB_SIZE(92, 160), 19, 0, 12, 1},
{45, UPB_SIZE(100, 176), 20, 0, 12, 1},
{999, UPB_SIZE(108, 192), 0, 0, 11, 3},
};

Expand Down Expand Up @@ -402,12 +402,12 @@ static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1]

static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = {
{2, UPB_SIZE(56, 80), 0, 0, 11, 3},
{3, UPB_SIZE(32, 32), 4, 0, 9, 1},
{3, UPB_SIZE(32, 32), 4, 0, 12, 1},
{4, UPB_SIZE(8, 8), 1, 0, 4, 1},
{5, UPB_SIZE(16, 16), 2, 0, 3, 1},
{6, UPB_SIZE(24, 24), 3, 0, 1, 1},
{7, UPB_SIZE(40, 48), 5, 0, 12, 1},
{8, UPB_SIZE(48, 64), 6, 0, 9, 1},
{8, UPB_SIZE(48, 64), 6, 0, 12, 1},
};

const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
Expand All @@ -417,7 +417,7 @@ const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
};

static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = {
{1, UPB_SIZE(4, 8), 2, 0, 9, 2},
{1, UPB_SIZE(4, 8), 2, 0, 12, 2},
{2, UPB_SIZE(1, 1), 1, 0, 8, 2},
};

Expand All @@ -444,9 +444,9 @@ const upb_msglayout google_protobuf_SourceCodeInfo_msginit = {
static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
{1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED},
{2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED},
{3, UPB_SIZE(4, 8), 1, 0, 9, 1},
{4, UPB_SIZE(12, 24), 2, 0, 9, 1},
{6, UPB_SIZE(28, 56), 0, 0, 9, 3},
{3, UPB_SIZE(4, 8), 1, 0, 12, 1},
{4, UPB_SIZE(12, 24), 2, 0, 12, 1},
{6, UPB_SIZE(28, 56), 0, 0, 12, 3},
};

const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = {
Expand All @@ -471,7 +471,7 @@ const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = {

static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
{1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED},
{2, UPB_SIZE(12, 16), 3, 0, 9, 1},
{2, UPB_SIZE(12, 16), 3, 0, 12, 1},
{3, UPB_SIZE(4, 4), 1, 0, 5, 1},
{4, UPB_SIZE(8, 8), 2, 0, 5, 1},
};
Expand Down
5 changes: 5 additions & 0 deletions kokoro/ubuntu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ if [[ $(uname) = "Linux" ]]; then

# For some reason kokoro doesn't have Clang available right now.
#CC=clang CXX=clang++ bazel test -c dbg --copt=-fsanitize=undefined --copt=-fno-sanitize=function,vptr --linkopt=-fsanitize=undefined --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 -- :all -:test_lua

fi

if which valgrind; then
bazel test --run_under='valgrind --leak-check=full --error-exitcode=1' :all -- -:test_conformance_upb -:cmake_build
fi
17 changes: 17 additions & 0 deletions tests/bindings/lua/test_upb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local upb = require "lupb"
local lunit = require "lunit"
local upb_test = require "tests.test_pb"
local test_messages_proto3 = require "google.protobuf.test_messages_proto3_pb"
local test_messages_proto2 = require "google.protobuf.test_messages_proto2_pb"
local descriptor = require "google.protobuf.descriptor_pb"

if _VERSION >= 'Lua 5.2' then
Expand Down Expand Up @@ -69,6 +70,22 @@ function test_msg_map()
assert_equal(12, msg2.map_int32_int32[6])
end

function test_utf8()
local proto2_msg = test_messages_proto2.TestAllTypesProto2()
proto2_msg.optional_string = "\xff"
local serialized = upb.encode(proto2_msg)

-- Decoding invalid UTF-8 succeeds in proto2.
upb.decode(test_messages_proto2.TestAllTypesProto2, serialized)

-- Decoding invalid UTF-8 fails in proto2.
assert_error_match("Error decoding protobuf", function()
upb.decode(test_messages_proto3.TestAllTypesProto3, serialized)
end)

-- TOOD(haberman): should proto3 accessors also check UTF-8 at set time?
end

function test_string_double_map()
msg = upb_test.MapTest()
msg.map_string_double["one"] = 1.0
Expand Down
17 changes: 14 additions & 3 deletions tests/test_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static const int kExpectedHandlerData = 1232323;

class StringBufTesterBase {
public:
static const int kFieldNumber = 3;
static constexpr int kFieldNumber = 3;

StringBufTesterBase() : seen_(false), handler_data_val_(0) {}

Expand Down Expand Up @@ -286,7 +286,7 @@ class StartMsgTesterBase {
public:
// We don't need the FieldDef it will create, but the test harness still
// requires that we provide one.
static const int kFieldNumber = 3;
static constexpr int kFieldNumber = 3;

StartMsgTesterBase() : seen_(false), handler_data_val_(0) {}

Expand Down Expand Up @@ -437,7 +437,7 @@ class StartMsgTesterBoolMethodWithHandlerData : public StartMsgTesterBase {

class Int32ValueTesterBase {
public:
static const int kFieldNumber = 1;
static constexpr int kFieldNumber = 1;

Int32ValueTesterBase() : seen_(false), val_(0), handler_data_val_(0) {}

Expand Down Expand Up @@ -939,6 +939,17 @@ void TestArena() {
upb_arena_malloc(arena.ptr(), 1000000);
}
ASSERT(n == 0);

{
// Test fuse.
upb::Arena arena1;
upb::Arena arena2;

arena1.Fuse(arena2);

upb_arena_malloc(arena1.ptr(), 10000);
upb_arena_malloc(arena2.ptr(), 10000);
}
}

extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generated_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void test_scalars() {

static void check_string_map_empty(
protobuf_test_messages_proto3_TestAllTypesProto3 *msg) {
size_t iter;
size_t iter = UPB_MAP_BEGIN;

ASSERT(
protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_size(
Expand Down Expand Up @@ -212,7 +212,7 @@ static void test_string_map() {

static void check_int32_map_empty(
protobuf_test_messages_proto3_TestAllTypesProto3 *msg) {
size_t iter;
size_t iter = UPB_MAP_BEGIN;

ASSERT(
protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_size(
Expand Down
Loading

0 comments on commit 6d7d35f

Please sign in to comment.