Added staleness test to keep ruby-upb.{c,h} amalgamation files in sync with upb repo (#10496)

* Added staleness test for ruby-upb.{c,h} and updated.

* Removed file comment markers, too much trouble for too little benefit.

* Ran clang-format.

* Updated ruby-upb.{c,h}.

* Added missing table code to amalgamation.

* Updated to latest upb, patch no longer needed.

* Reverted changes to third_party sub-modules.

* Added missing unicode file.

* Removed conformance failures for Ruby.
pull/10693/head
Joshua Haberman 2 years ago committed by GitHub
parent c705fbbb53
commit d3995ec400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      conformance/failure_list_ruby.txt
  2. 5
      protobuf_deps.bzl
  3. 24
      ruby/BUILD.bazel
  4. 64
      ruby/ext/google/protobuf_c/message.c
  5. 19138
      ruby/ext/google/protobuf_c/ruby-upb.c
  6. 9315
      ruby/ext/google/protobuf_c/ruby-upb.h
  7. 10
      upb.patch

@ -56,6 +56,3 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOu
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Required.Proto3.JsonInput.DurationNegativeNanos.JsonOutput
Required.Proto3.JsonInput.DurationNegativeNanos.ProtobufOutput
Required.Proto3.JsonInput.DurationNegativeSeconds.JsonOutput

@ -115,6 +115,7 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "ce3a28f75c8a52a5ea31f6ecf72467a9d6461cb1",
sha256 = "716c0c0e6b0bbafa7e64a9184b248fcd100eebb01b0e1aded61c7bc3d81d837e",
commit = "128ac1c9354fd25e765db0d16550ed485f7d130f",
sha256 = "3466942800f7b513b6a3418004bc389b3316a6ca7d3aa6682a81bdce58aac824",
patches = ["@com_google_protobuf//:upb.patch"],
)

@ -3,6 +3,7 @@
# See also code generation logic under /src/google/protobuf/compiler/ruby.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_test")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf.bzl", "internal_ruby_proto_library")
@ -161,6 +162,29 @@ conformance_test(
}),
)
genrule(
name = "copy_ruby_amalgamation_h",
srcs = ["@upb//:ruby-upb.h"],
outs = ["generated-in/ext/google/protobuf_c/ruby-upb.h"],
cmd = "cp $< $@",
)
genrule(
name = "copy_ruby_amalgamation_c",
srcs = ["@upb//:ruby-upb.c"],
outs = ["generated-in/ext/google/protobuf_c/ruby-upb.c"],
cmd = "cp $< $@",
)
staleness_test(
name = "test_amalgamation_staleness",
outs = [
"ext/google/protobuf_c/ruby-upb.h",
"ext/google/protobuf_c/ruby-upb.c",
],
generated_pattern = "generated-in/%s",
)
################################################################################
# Distribution files
################################################################################

@ -696,15 +696,20 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
if (m1 == m2) return true;
size_t size1, size2;
int encode_opts = kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic;
int encode_opts =
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
upb_Arena* arena_tmp = upb_Arena_New();
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
// Compare deterministically serialized payloads with no unknown fields.
char* data1 = upb_Encode(m1, layout, encode_opts, arena_tmp, &size1);
char* data2 = upb_Encode(m2, layout, encode_opts, arena_tmp, &size2);
if (data1 && data2) {
char* data1;
char* data2;
upb_EncodeStatus status1 =
upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
upb_EncodeStatus status2 =
upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
upb_Arena_Free(arena_tmp);
return ret;
@ -736,15 +741,16 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
uint64_t seed) {
upb_Arena* arena = upb_Arena_New();
const char* data;
char* data;
size_t size;
// Hash a deterministically serialized payloads with no unknown fields.
data = upb_Encode(msg, upb_MessageDef_MiniTable(m),
kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic, arena,
&size);
upb_EncodeStatus status = upb_Encode(
msg, upb_MessageDef_MiniTable(m),
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
&data, &size);
if (data) {
if (status == kUpb_EncodeStatus_Ok) {
uint64_t ret = _upb_Hash(data, size, seed);
upb_Arena_Free(arena);
return ret;
@ -970,7 +976,8 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
VALUE depth =
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
@ -984,9 +991,10 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
VALUE msg_rb = initialize_rb_class_with_no_args(klass);
Message* msg = ruby_to_Message(msg_rb);
upb_DecodeStatus status = upb_Decode(
RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena));
upb_DecodeStatus status =
upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
Arena_get(msg->arena));
if (status != kUpb_DecodeStatus_Ok) {
rb_raise(cParseError, "Error occurred during parsing");
@ -1070,7 +1078,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
Message* msg = ruby_to_Message(argv[0]);
int options = 0;
const char* data;
char* data;
size_t size;
if (CLASS_OF(argv[0]) != klass) {
@ -1086,19 +1094,21 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
if (TYPE(hash_args) != T_HASH) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
VALUE depth =
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
}
}
upb_Arena *arena = upb_Arena_New();
upb_Arena* arena = upb_Arena_New();
data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef),
options, arena, &size);
upb_EncodeStatus status =
upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), options,
arena, &data, &size);
if (data) {
if (status == kUpb_EncodeStatus_Ok) {
VALUE ret = rb_str_new(data, size);
rb_enc_associate(ret, rb_ascii8bit_encoding());
upb_Arena_Free(arena);
@ -1136,7 +1146,8 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
if (argc == 2) {
VALUE hash_args = argv[1];
if (TYPE(hash_args) != T_HASH) {
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1, rb_str_new2("to_h")))) {
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1,
rb_str_new2("to_h")))) {
hash_args = rb_funcall(hash_args, rb_intern("to_h"), 0);
} else {
rb_raise(rb_eArgError, "Expected hash arguments.");
@ -1295,11 +1306,13 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
size_t size;
char* data = upb_Encode(msg, layout, 0, tmp_arena, &size);
upb_Message* new_msg = upb_Message_New(m, arena);
char* data;
if (!data || upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
kUpb_EncodeStatus_Ok ||
upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
upb_Arena_Free(tmp_arena);
rb_raise(cParseError, "Error occurred copying proto");
}
@ -1399,7 +1412,8 @@ static void Message_define_class(VALUE klass) {
void Message_register(VALUE protobuf) {
cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
cAbstractMessage = rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
cAbstractMessage =
rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
Message_define_class(cAbstractMessage);
rb_gc_register_address(&cAbstractMessage);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,10 @@
--- BUILD
+++ BUILD
@@ -1022,6 +1022,7 @@ upb_amalgamation(
":reflection",
":table_internal",
":upb",
+ ":unicode_internal",
],
prefix = "ruby-",
strip_import_prefix = ["src"],
Loading…
Cancel
Save