google-protobuf 3.14.0 → 3.21.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +361 -0
- data/ext/google/protobuf_c/convert.h +75 -0
- data/ext/google/protobuf_c/defs.c +576 -1662
- data/ext/google/protobuf_c/defs.h +107 -0
- data/ext/google/protobuf_c/extconf.rb +13 -6
- data/ext/google/protobuf_c/map.c +329 -463
- data/ext/google/protobuf_c/map.h +66 -0
- data/ext/google/protobuf_c/message.c +1010 -467
- data/ext/google/protobuf_c/message.h +104 -0
- data/ext/google/protobuf_c/protobuf.c +411 -67
- data/ext/google/protobuf_c/protobuf.h +49 -596
- data/ext/google/protobuf_c/repeated_field.c +299 -328
- data/ext/google/protobuf_c/repeated_field.h +63 -0
- data/ext/google/protobuf_c/ruby-upb.c +11115 -0
- data/ext/google/protobuf_c/ruby-upb.h +5612 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
- data/lib/google/protobuf/api_pb.rb +1 -0
- data/lib/google/protobuf/descriptor_dsl.rb +465 -0
- data/lib/google/protobuf/descriptor_pb.rb +269 -0
- data/lib/google/protobuf/message_exts.rb +2 -2
- data/lib/google/protobuf/repeated_field.rb +15 -2
- data/lib/google/protobuf/type_pb.rb +1 -0
- data/lib/google/protobuf/well_known_types.rb +12 -2
- data/lib/google/protobuf.rb +5 -73
- data/tests/basic.rb +209 -13
- data/tests/stress.rb +1 -1
- metadata +23 -32
- data/ext/google/protobuf_c/encode_decode.c +0 -1795
- data/ext/google/protobuf_c/storage.c +0 -1198
- data/ext/google/protobuf_c/upb.c +0 -13817
- data/ext/google/protobuf_c/upb.h +0 -6777
data/tests/basic.rb
CHANGED
@@ -31,6 +31,85 @@ module BasicTest
|
|
31
31
|
end
|
32
32
|
include CommonTests
|
33
33
|
|
34
|
+
def test_issue_8311_crash
|
35
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
36
|
+
add_file("inner.proto", :syntax => :proto3) do
|
37
|
+
add_message "Inner" do
|
38
|
+
# Removing either of these fixes the segfault.
|
39
|
+
optional :foo, :string, 1
|
40
|
+
optional :bar, :string, 2
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
46
|
+
add_file("outer.proto", :syntax => :proto3) do
|
47
|
+
add_message "Outer" do
|
48
|
+
repeated :inners, :message, 1, "Inner"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass
|
54
|
+
|
55
|
+
outer.new(
|
56
|
+
inners: []
|
57
|
+
)['inners'].to_s
|
58
|
+
|
59
|
+
assert_raise Google::Protobuf::TypeError do
|
60
|
+
outer.new(
|
61
|
+
inners: [nil]
|
62
|
+
).to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_issue_8559_crash
|
67
|
+
msg = TestMessage.new
|
68
|
+
msg.repeated_int32 = ::Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
|
69
|
+
|
70
|
+
# https://github.com/jruby/jruby/issues/6818 was fixed in JRuby 9.3.0.0
|
71
|
+
if cruby_or_jruby_9_3_or_higher?
|
72
|
+
GC.start(full_mark: true, immediate_sweep: true)
|
73
|
+
end
|
74
|
+
TestMessage.encode(msg)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_issue_9440
|
78
|
+
msg = HelloRequest.new
|
79
|
+
msg.id = 8
|
80
|
+
assert_equal 8, msg.id
|
81
|
+
msg.version = '1'
|
82
|
+
assert_equal 8, msg.id
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_issue_9507
|
86
|
+
pool = Google::Protobuf::DescriptorPool.new
|
87
|
+
pool.build do
|
88
|
+
add_message "NpeMessage" do
|
89
|
+
optional :type, :enum, 1, "TestEnum"
|
90
|
+
optional :other, :string, 2
|
91
|
+
end
|
92
|
+
add_enum "TestEnum" do
|
93
|
+
value :Something, 0
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
msgclass = pool.lookup("NpeMessage").msgclass
|
98
|
+
|
99
|
+
m = msgclass.new(
|
100
|
+
other: "foo" # must be set, but can be blank
|
101
|
+
)
|
102
|
+
|
103
|
+
begin
|
104
|
+
encoded = msgclass.encode(m)
|
105
|
+
rescue java.lang.NullPointerException
|
106
|
+
flunk "NPE rescued"
|
107
|
+
end
|
108
|
+
decoded = msgclass.decode(encoded)
|
109
|
+
decoded.inspect
|
110
|
+
decoded.to_proto
|
111
|
+
end
|
112
|
+
|
34
113
|
def test_has_field
|
35
114
|
m = TestSingularFields.new
|
36
115
|
assert !m.has_singular_msg?
|
@@ -97,7 +176,7 @@ module BasicTest
|
|
97
176
|
m = TestSingularFields.new
|
98
177
|
|
99
178
|
m.singular_int32 = -42
|
100
|
-
assert_equal -42, m.singular_int32
|
179
|
+
assert_equal( -42, m.singular_int32 )
|
101
180
|
m.clear_singular_int32
|
102
181
|
assert_equal 0, m.singular_int32
|
103
182
|
|
@@ -129,6 +208,17 @@ module BasicTest
|
|
129
208
|
assert_equal nil, m.singular_msg
|
130
209
|
end
|
131
210
|
|
211
|
+
def test_import_proto2
|
212
|
+
m = TestMessage.new
|
213
|
+
assert !m.has_optional_proto2_submessage?
|
214
|
+
m.optional_proto2_submessage = ::FooBar::Proto2::TestImportedMessage.new
|
215
|
+
assert m.has_optional_proto2_submessage?
|
216
|
+
assert TestMessage.descriptor.lookup('optional_proto2_submessage').has?(m)
|
217
|
+
|
218
|
+
m.clear_optional_proto2_submessage
|
219
|
+
assert !m.has_optional_proto2_submessage?
|
220
|
+
end
|
221
|
+
|
132
222
|
def test_clear_repeated_fields
|
133
223
|
m = TestMessage.new
|
134
224
|
|
@@ -216,7 +306,7 @@ module BasicTest
|
|
216
306
|
m.map_string_int32 = {}
|
217
307
|
end
|
218
308
|
|
219
|
-
assert_raise TypeError do
|
309
|
+
assert_raise Google::Protobuf::TypeError do
|
220
310
|
m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
|
221
311
|
end
|
222
312
|
end
|
@@ -241,8 +331,12 @@ module BasicTest
|
|
241
331
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
242
332
|
"b" => TestMessage2.new(:foo => 2)},
|
243
333
|
:map_string_enum => {"a" => :A, "b" => :B})
|
244
|
-
|
245
|
-
|
334
|
+
|
335
|
+
# JRuby doesn't keep consistent ordering so check for either version
|
336
|
+
expected_a = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}, map_string_enum: {\"b\"=>:B, \"a\"=>:A}>"
|
337
|
+
expected_b = "<BasicTest::MapMessage: map_string_int32: {\"a\"=>1, \"b\"=>2}, map_string_msg: {\"a\"=><BasicTest::TestMessage2: foo: 1>, \"b\"=><BasicTest::TestMessage2: foo: 2>}, map_string_enum: {\"a\"=>:A, \"b\"=>:B}>"
|
338
|
+
inspect_result = m.inspect
|
339
|
+
assert expected_a == inspect_result || expected_b == inspect_result, "Incorrect inspect result: #{inspect_result}"
|
246
340
|
end
|
247
341
|
|
248
342
|
def test_map_corruption
|
@@ -443,6 +537,8 @@ module BasicTest
|
|
443
537
|
:optional_int32=>0,
|
444
538
|
:optional_int64=>0,
|
445
539
|
:optional_msg=>nil,
|
540
|
+
:optional_msg2=>nil,
|
541
|
+
:optional_proto2_submessage=>nil,
|
446
542
|
:optional_string=>"foo",
|
447
543
|
:optional_uint32=>0,
|
448
544
|
:optional_uint64=>0,
|
@@ -475,14 +571,12 @@ module BasicTest
|
|
475
571
|
|
476
572
|
|
477
573
|
def test_json_maps
|
478
|
-
# TODO: Fix JSON in JRuby version.
|
479
|
-
return if RUBY_PLATFORM == "java"
|
480
574
|
m = MapMessage.new(:map_string_int32 => {"a" => 1})
|
481
575
|
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
|
482
576
|
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
|
483
|
-
assert_equal JSON.parse(MapMessage.encode_json(m), :symbolize_names => true), expected
|
577
|
+
assert_equal JSON.parse(MapMessage.encode_json(m, :emit_defaults=>true), :symbolize_names => true), expected
|
484
578
|
|
485
|
-
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
|
579
|
+
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults=>true)
|
486
580
|
assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
|
487
581
|
|
488
582
|
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
@@ -490,9 +584,7 @@ module BasicTest
|
|
490
584
|
end
|
491
585
|
|
492
586
|
def test_json_maps_emit_defaults_submsg
|
493
|
-
|
494
|
-
return if RUBY_PLATFORM == "java"
|
495
|
-
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
|
587
|
+
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new(foo: 0)})
|
496
588
|
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
|
497
589
|
|
498
590
|
actual = MapMessage.encode_json(m, :emit_defaults => true)
|
@@ -500,9 +592,29 @@ module BasicTest
|
|
500
592
|
assert_equal JSON.parse(actual, :symbolize_names => true), expected
|
501
593
|
end
|
502
594
|
|
595
|
+
def test_json_emit_defaults_submsg
|
596
|
+
m = TestSingularFields.new(singular_msg: proto_module::TestMessage2.new)
|
597
|
+
|
598
|
+
expected = {
|
599
|
+
singularInt32: 0,
|
600
|
+
singularInt64: "0",
|
601
|
+
singularUint32: 0,
|
602
|
+
singularUint64: "0",
|
603
|
+
singularBool: false,
|
604
|
+
singularFloat: 0,
|
605
|
+
singularDouble: 0,
|
606
|
+
singularString: "",
|
607
|
+
singularBytes: "",
|
608
|
+
singularMsg: {},
|
609
|
+
singularEnum: "Default",
|
610
|
+
}
|
611
|
+
|
612
|
+
actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
|
613
|
+
|
614
|
+
assert_equal expected, JSON.parse(actual, :symbolize_names => true)
|
615
|
+
end
|
616
|
+
|
503
617
|
def test_respond_to
|
504
|
-
# This test fails with JRuby 1.7.23, likely because of an old JRuby bug.
|
505
|
-
return if RUBY_PLATFORM == "java"
|
506
618
|
msg = MapMessage.new
|
507
619
|
assert msg.respond_to?(:map_string_int32)
|
508
620
|
assert !msg.respond_to?(:bacon)
|
@@ -539,5 +651,89 @@ module BasicTest
|
|
539
651
|
assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
|
540
652
|
assert_raise(FrozenErrorType) { m.map_string_int32.clear }
|
541
653
|
end
|
654
|
+
|
655
|
+
def test_map_length
|
656
|
+
m = proto_module::MapMessage.new
|
657
|
+
assert_equal 0, m.map_string_int32.length
|
658
|
+
assert_equal 0, m.map_string_msg.length
|
659
|
+
assert_equal 0, m.map_string_int32.size
|
660
|
+
assert_equal 0, m.map_string_msg.size
|
661
|
+
|
662
|
+
m.map_string_int32['a'] = 1
|
663
|
+
m.map_string_int32['b'] = 2
|
664
|
+
m.map_string_msg['a'] = proto_module::TestMessage2.new
|
665
|
+
assert_equal 2, m.map_string_int32.length
|
666
|
+
assert_equal 1, m.map_string_msg.length
|
667
|
+
assert_equal 2, m.map_string_int32.size
|
668
|
+
assert_equal 1, m.map_string_msg.size
|
669
|
+
end
|
670
|
+
|
671
|
+
def test_string_with_singleton_class_enabled
|
672
|
+
str = 'foobar'
|
673
|
+
# NOTE: Accessing a singleton class of an object changes its low level class representation
|
674
|
+
# as far as the C API's CLASS_OF() method concerned, exposing the issue
|
675
|
+
str.singleton_class
|
676
|
+
m = proto_module::TestMessage.new(
|
677
|
+
optional_string: str,
|
678
|
+
optional_bytes: str
|
679
|
+
)
|
680
|
+
|
681
|
+
assert_equal str, m.optional_string
|
682
|
+
assert_equal str, m.optional_bytes
|
683
|
+
end
|
684
|
+
|
685
|
+
def test_utf8
|
686
|
+
m = proto_module::TestMessage.new(
|
687
|
+
optional_string: "µpb",
|
688
|
+
)
|
689
|
+
m2 = proto_module::TestMessage.decode(proto_module::TestMessage.encode(m))
|
690
|
+
assert_equal m2, m
|
691
|
+
end
|
692
|
+
|
693
|
+
def test_map_fields_respond_to? # regression test for issue 9202
|
694
|
+
msg = proto_module::MapMessage.new
|
695
|
+
assert msg.respond_to?(:map_string_int32=)
|
696
|
+
msg.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
|
697
|
+
assert msg.respond_to?(:map_string_int32)
|
698
|
+
assert_equal( Google::Protobuf::Map.new(:string, :int32), msg.map_string_int32 )
|
699
|
+
assert msg.respond_to?(:clear_map_string_int32)
|
700
|
+
msg.clear_map_string_int32
|
701
|
+
|
702
|
+
assert !msg.respond_to?(:has_map_string_int32?)
|
703
|
+
assert_raise NoMethodError do
|
704
|
+
msg.has_map_string_int32?
|
705
|
+
end
|
706
|
+
assert !msg.respond_to?(:map_string_int32_as_value)
|
707
|
+
assert_raise NoMethodError do
|
708
|
+
msg.map_string_int32_as_value
|
709
|
+
end
|
710
|
+
assert !msg.respond_to?(:map_string_int32_as_value=)
|
711
|
+
assert_raise NoMethodError do
|
712
|
+
msg.map_string_int32_as_value = :boom
|
713
|
+
end
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_oneof_fields_respond_to? # regression test for issue 9202
|
718
|
+
msg = proto_module::OneofMessage.new
|
719
|
+
# `has_` prefix + "?" suffix actions should only work for oneofs fields.
|
720
|
+
assert msg.has_my_oneof?
|
721
|
+
assert msg.respond_to? :has_my_oneof?
|
722
|
+
assert !msg.respond_to?( :has_a? )
|
723
|
+
assert_raise NoMethodError do
|
724
|
+
msg.has_a?
|
725
|
+
end
|
726
|
+
assert !msg.respond_to?( :has_b? )
|
727
|
+
assert_raise NoMethodError do
|
728
|
+
msg.has_b?
|
729
|
+
end
|
730
|
+
assert !msg.respond_to?( :has_c? )
|
731
|
+
assert_raise NoMethodError do
|
732
|
+
msg.has_c?
|
733
|
+
end
|
734
|
+
assert !msg.respond_to?( :has_d? )
|
735
|
+
assert_raise NoMethodError do
|
736
|
+
msg.has_d?
|
737
|
+
end
|
542
738
|
end
|
543
739
|
end
|
data/tests/stress.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.1
|
20
|
-
- - "<"
|
17
|
+
- - '='
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 1.2.1
|
23
20
|
type: :development
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0.1
|
30
|
-
- - "<"
|
24
|
+
- - '='
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 1.2.1
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rake-compiler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,20 +58,6 @@ dependencies:
|
|
64
58
|
- - ">="
|
65
59
|
- !ruby/object:Gem::Version
|
66
60
|
version: 3.0.9
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: rubygems-tasks
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: 0.2.4
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 0.2.4
|
81
61
|
description: Protocol Buffers are Google's data interchange format.
|
82
62
|
email: protobuf@googlegroups.com
|
83
63
|
executables: []
|
@@ -85,21 +65,32 @@ extensions:
|
|
85
65
|
- ext/google/protobuf_c/extconf.rb
|
86
66
|
extra_rdoc_files: []
|
87
67
|
files:
|
68
|
+
- ext/google/protobuf_c/convert.c
|
69
|
+
- ext/google/protobuf_c/convert.h
|
88
70
|
- ext/google/protobuf_c/defs.c
|
89
|
-
- ext/google/protobuf_c/
|
71
|
+
- ext/google/protobuf_c/defs.h
|
90
72
|
- ext/google/protobuf_c/extconf.rb
|
91
73
|
- ext/google/protobuf_c/map.c
|
74
|
+
- ext/google/protobuf_c/map.h
|
92
75
|
- ext/google/protobuf_c/message.c
|
76
|
+
- ext/google/protobuf_c/message.h
|
93
77
|
- ext/google/protobuf_c/protobuf.c
|
94
78
|
- ext/google/protobuf_c/protobuf.h
|
95
79
|
- ext/google/protobuf_c/repeated_field.c
|
96
|
-
- ext/google/protobuf_c/
|
97
|
-
- ext/google/protobuf_c/upb.c
|
98
|
-
- ext/google/protobuf_c/upb.h
|
80
|
+
- ext/google/protobuf_c/repeated_field.h
|
81
|
+
- ext/google/protobuf_c/ruby-upb.c
|
82
|
+
- ext/google/protobuf_c/ruby-upb.h
|
83
|
+
- ext/google/protobuf_c/third_party/utf8_range/LICENSE
|
84
|
+
- ext/google/protobuf_c/third_party/utf8_range/naive.c
|
85
|
+
- ext/google/protobuf_c/third_party/utf8_range/range2-neon.c
|
86
|
+
- ext/google/protobuf_c/third_party/utf8_range/range2-sse.c
|
87
|
+
- ext/google/protobuf_c/third_party/utf8_range/utf8_range.h
|
99
88
|
- ext/google/protobuf_c/wrap_memcpy.c
|
100
89
|
- lib/google/protobuf.rb
|
101
90
|
- lib/google/protobuf/any_pb.rb
|
102
91
|
- lib/google/protobuf/api_pb.rb
|
92
|
+
- lib/google/protobuf/descriptor_dsl.rb
|
93
|
+
- lib/google/protobuf/descriptor_pb.rb
|
103
94
|
- lib/google/protobuf/duration_pb.rb
|
104
95
|
- lib/google/protobuf/empty_pb.rb
|
105
96
|
- lib/google/protobuf/field_mask_pb.rb
|
@@ -118,7 +109,7 @@ homepage: https://developers.google.com/protocol-buffers
|
|
118
109
|
licenses:
|
119
110
|
- BSD-3-Clause
|
120
111
|
metadata:
|
121
|
-
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.
|
112
|
+
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.21.0/ruby
|
122
113
|
post_install_message:
|
123
114
|
rdoc_options: []
|
124
115
|
require_paths:
|
@@ -134,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
125
|
- !ruby/object:Gem::Version
|
135
126
|
version: '0'
|
136
127
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.3.14
|
138
129
|
signing_key:
|
139
130
|
specification_version: 4
|
140
131
|
summary: Protocol Buffers
|