google-protobuf 3.21.10 → 3.25.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +23 -70
- data/ext/google/protobuf_c/convert.h +3 -28
- data/ext/google/protobuf_c/defs.c +178 -55
- data/ext/google/protobuf_c/defs.h +3 -28
- data/ext/google/protobuf_c/extconf.rb +4 -4
- data/ext/google/protobuf_c/glue.c +56 -0
- data/ext/google/protobuf_c/map.c +54 -70
- data/ext/google/protobuf_c/map.h +6 -28
- data/ext/google/protobuf_c/message.c +178 -161
- data/ext/google/protobuf_c/message.h +10 -28
- data/ext/google/protobuf_c/protobuf.c +39 -176
- data/ext/google/protobuf_c/protobuf.h +24 -32
- data/ext/google/protobuf_c/repeated_field.c +28 -29
- data/ext/google/protobuf_c/repeated_field.h +6 -28
- data/ext/google/protobuf_c/ruby-upb.c +12326 -9027
- data/ext/google/protobuf_c/ruby-upb.h +11950 -4518
- data/ext/google/protobuf_c/shared_convert.c +64 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +65 -0
- data/ext/google/protobuf_c/shared_message.h +25 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +1 -1
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +13 -1
- data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
- data/lib/google/protobuf/any_pb.rb +24 -5
- data/lib/google/protobuf/api_pb.rb +26 -23
- data/lib/google/protobuf/descriptor_dsl.rb +0 -0
- data/lib/google/protobuf/descriptor_pb.rb +43 -226
- data/lib/google/protobuf/duration_pb.rb +24 -5
- data/lib/google/protobuf/empty_pb.rb +24 -3
- data/lib/google/protobuf/ffi/descriptor.rb +165 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
- data/lib/google/protobuf/ffi/ffi.rb +213 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +407 -0
- data/lib/google/protobuf/ffi/message.rb +662 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
- data/lib/google/protobuf/field_mask_pb.rb +24 -4
- data/lib/google/protobuf/message_exts.rb +8 -26
- data/lib/google/protobuf/object_cache.rb +97 -0
- data/lib/google/protobuf/plugin_pb.rb +47 -0
- data/lib/google/protobuf/repeated_field.rb +3 -26
- data/lib/google/protobuf/source_context_pb.rb +24 -4
- data/lib/google/protobuf/struct_pb.rb +24 -20
- data/lib/google/protobuf/timestamp_pb.rb +24 -5
- data/lib/google/protobuf/type_pb.rb +26 -68
- data/lib/google/protobuf/well_known_types.rb +5 -34
- data/lib/google/protobuf/wrappers_pb.rb +24 -28
- data/lib/google/protobuf.rb +27 -45
- data/lib/google/protobuf_ffi.rb +50 -0
- data/lib/google/protobuf_native.rb +20 -0
- data/lib/google/tasks/ffi.rake +102 -0
- metadata +75 -12
- data/tests/basic.rb +0 -739
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
data/ext/google/protobuf_c/map.c
CHANGED
@@ -1,32 +1,9 @@
|
|
1
1
|
// Protocol Buffers - Google's data interchange format
|
2
2
|
// Copyright 2014 Google Inc. All rights reserved.
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
4
3
|
//
|
5
|
-
//
|
6
|
-
//
|
7
|
-
//
|
8
|
-
//
|
9
|
-
// * Redistributions of source code must retain the above copyright
|
10
|
-
// notice, this list of conditions and the following disclaimer.
|
11
|
-
// * Redistributions in binary form must reproduce the above
|
12
|
-
// copyright notice, this list of conditions and the following disclaimer
|
13
|
-
// in the documentation and/or other materials provided with the
|
14
|
-
// distribution.
|
15
|
-
// * Neither the name of Google Inc. nor the names of its
|
16
|
-
// contributors may be used to endorse or promote products derived from
|
17
|
-
// this software without specific prior written permission.
|
18
|
-
//
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
4
|
+
// Use of this source code is governed by a BSD-style
|
5
|
+
// license that can be found in the LICENSE file or at
|
6
|
+
// https://developers.google.com/open-source/licenses/bsd
|
30
7
|
|
31
8
|
#include "convert.h"
|
32
9
|
#include "defs.h"
|
@@ -93,7 +70,6 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
|
|
93
70
|
if (val == Qnil) {
|
94
71
|
val = Map_alloc(cMap);
|
95
72
|
Map* self;
|
96
|
-
ObjectCache_Add(map, val);
|
97
73
|
TypedData_Get_Struct(val, Map, &Map_type, self);
|
98
74
|
self->map = map;
|
99
75
|
self->arena = arena;
|
@@ -103,6 +79,7 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
|
|
103
79
|
const upb_MessageDef* val_m = self->value_type_info.def.msgdef;
|
104
80
|
self->value_type_class = Descriptor_DefToClass(val_m);
|
105
81
|
}
|
82
|
+
return ObjectCache_TryAdd(map, val);
|
106
83
|
}
|
107
84
|
|
108
85
|
return val;
|
@@ -133,14 +110,13 @@ static upb_Map* Map_GetMutable(VALUE _self) {
|
|
133
110
|
VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type,
|
134
111
|
TypeInfo val_info) {
|
135
112
|
VALUE hash = rb_hash_new();
|
136
|
-
size_t iter = kUpb_Map_Begin;
|
137
113
|
TypeInfo key_info = TypeInfo_from_type(key_type);
|
138
114
|
|
139
115
|
if (!map) return hash;
|
140
116
|
|
141
|
-
|
142
|
-
|
143
|
-
|
117
|
+
size_t iter = kUpb_Map_Begin;
|
118
|
+
upb_MessageValue key, val;
|
119
|
+
while (upb_Map_Next(map, &key, &val, &iter)) {
|
144
120
|
VALUE key_val = Convert_UpbToRuby(key, key_info, Qnil);
|
145
121
|
VALUE val_val = Scalar_CreateHash(val, val_info);
|
146
122
|
rb_hash_aset(hash, key_val, val_val);
|
@@ -156,9 +132,8 @@ VALUE Map_deep_copy(VALUE obj) {
|
|
156
132
|
upb_Map* new_map =
|
157
133
|
upb_Map_New(arena, self->key_type, self->value_type_info.type);
|
158
134
|
size_t iter = kUpb_Map_Begin;
|
159
|
-
|
160
|
-
|
161
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
135
|
+
upb_MessageValue key, val;
|
136
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
162
137
|
upb_MessageValue val_copy =
|
163
138
|
Msgval_DeepCopy(val, self->value_type_info, arena);
|
164
139
|
upb_Map_Set(new_map, key, val_copy, arena);
|
@@ -202,9 +177,8 @@ void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type,
|
|
202
177
|
StringBuilder_Printf(b, "{");
|
203
178
|
if (map) {
|
204
179
|
size_t iter = kUpb_Map_Begin;
|
205
|
-
|
206
|
-
|
207
|
-
upb_MessageValue val = upb_MapIterator_Value(map, iter);
|
180
|
+
upb_MessageValue key, val;
|
181
|
+
while (upb_Map_Next(map, &key, &val, &iter)) {
|
208
182
|
if (first) {
|
209
183
|
first = false;
|
210
184
|
} else {
|
@@ -239,7 +213,6 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
239
213
|
Map* other = ruby_to_Map(hashmap);
|
240
214
|
upb_Arena* arena = Arena_get(self->arena);
|
241
215
|
upb_Message* self_msg = Map_GetMutable(_self);
|
242
|
-
size_t iter = kUpb_Map_Begin;
|
243
216
|
|
244
217
|
Arena_fuse(other->arena, arena);
|
245
218
|
|
@@ -249,9 +222,9 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
249
222
|
rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
|
250
223
|
}
|
251
224
|
|
252
|
-
|
253
|
-
|
254
|
-
|
225
|
+
size_t iter = kUpb_Map_Begin;
|
226
|
+
upb_MessageValue key, val;
|
227
|
+
while (upb_Map_Next(other->map, &key, &val, &iter)) {
|
255
228
|
upb_Map_Set(self_msg, key, val, arena);
|
256
229
|
}
|
257
230
|
} else {
|
@@ -323,7 +296,9 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
|
|
323
296
|
|
324
297
|
self->map = upb_Map_New(Arena_get(self->arena), self->key_type,
|
325
298
|
self->value_type_info.type);
|
326
|
-
|
299
|
+
VALUE stored = ObjectCache_TryAdd(self->map, _self);
|
300
|
+
(void)stored;
|
301
|
+
PBRUBY_ASSERT(stored == _self);
|
327
302
|
|
328
303
|
if (init_arg != Qnil) {
|
329
304
|
Map_merge_into_self(_self, init_arg);
|
@@ -343,10 +318,9 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
|
|
343
318
|
static VALUE Map_each(VALUE _self) {
|
344
319
|
Map* self = ruby_to_Map(_self);
|
345
320
|
size_t iter = kUpb_Map_Begin;
|
321
|
+
upb_MessageValue key, val;
|
346
322
|
|
347
|
-
while (
|
348
|
-
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
|
349
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
323
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
350
324
|
VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
|
351
325
|
VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
|
352
326
|
rb_yield_values(2, key_val, val_val);
|
@@ -365,9 +339,9 @@ static VALUE Map_keys(VALUE _self) {
|
|
365
339
|
Map* self = ruby_to_Map(_self);
|
366
340
|
size_t iter = kUpb_Map_Begin;
|
367
341
|
VALUE ret = rb_ary_new();
|
342
|
+
upb_MessageValue key, val;
|
368
343
|
|
369
|
-
while (
|
370
|
-
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
|
344
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
371
345
|
VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
|
372
346
|
rb_ary_push(ret, key_val);
|
373
347
|
}
|
@@ -385,9 +359,9 @@ static VALUE Map_values(VALUE _self) {
|
|
385
359
|
Map* self = ruby_to_Map(_self);
|
386
360
|
size_t iter = kUpb_Map_Begin;
|
387
361
|
VALUE ret = rb_ary_new();
|
362
|
+
upb_MessageValue key, val;
|
388
363
|
|
389
|
-
while (
|
390
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
364
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
391
365
|
VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
|
392
366
|
rb_ary_push(ret, val_val);
|
393
367
|
}
|
@@ -464,24 +438,17 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
|
|
464
438
|
*/
|
465
439
|
static VALUE Map_delete(VALUE _self, VALUE key) {
|
466
440
|
Map* self = ruby_to_Map(_self);
|
441
|
+
rb_check_frozen(_self);
|
442
|
+
|
467
443
|
upb_MessageValue key_upb =
|
468
444
|
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
|
469
445
|
upb_MessageValue val_upb;
|
470
|
-
VALUE ret;
|
471
|
-
|
472
|
-
rb_check_frozen(_self);
|
473
446
|
|
474
|
-
|
475
|
-
|
476
|
-
if (upb_Map_Get(self->map, key_upb, &val_upb)) {
|
477
|
-
ret = Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
|
447
|
+
if (upb_Map_Delete(self->map, key_upb, &val_upb)) {
|
448
|
+
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
|
478
449
|
} else {
|
479
|
-
|
450
|
+
return Qnil;
|
480
451
|
}
|
481
|
-
|
482
|
-
upb_Map_Delete(Map_GetMutable(_self), key_upb);
|
483
|
-
|
484
|
-
return ret;
|
485
452
|
}
|
486
453
|
|
487
454
|
/*
|
@@ -523,9 +490,8 @@ static VALUE Map_dup(VALUE _self) {
|
|
523
490
|
|
524
491
|
Arena_fuse(self->arena, arena);
|
525
492
|
|
526
|
-
|
527
|
-
|
528
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
493
|
+
upb_MessageValue key, val;
|
494
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
529
495
|
upb_Map_Set(new_map, key, val, arena);
|
530
496
|
}
|
531
497
|
|
@@ -574,9 +540,8 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
|
|
574
540
|
// For each member of self, check that an equal member exists at the same key
|
575
541
|
// in other.
|
576
542
|
size_t iter = kUpb_Map_Begin;
|
577
|
-
|
578
|
-
|
579
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
543
|
+
upb_MessageValue key, val;
|
544
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
580
545
|
upb_MessageValue other_val;
|
581
546
|
if (!upb_Map_Get(other->map, key, &other_val)) {
|
582
547
|
// Not present in other map.
|
@@ -607,6 +572,26 @@ static VALUE Map_freeze(VALUE _self) {
|
|
607
572
|
return _self;
|
608
573
|
}
|
609
574
|
|
575
|
+
/*
|
576
|
+
* Deep freezes the map and values recursively.
|
577
|
+
* Internal use only.
|
578
|
+
*/
|
579
|
+
VALUE Map_internal_deep_freeze(VALUE _self) {
|
580
|
+
Map* self = ruby_to_Map(_self);
|
581
|
+
Map_freeze(_self);
|
582
|
+
if (self->value_type_info.type == kUpb_CType_Message) {
|
583
|
+
size_t iter = kUpb_Map_Begin;
|
584
|
+
upb_MessageValue key, val;
|
585
|
+
|
586
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
587
|
+
VALUE val_val =
|
588
|
+
Convert_UpbToRuby(val, self->value_type_info, self->arena);
|
589
|
+
Message_internal_deep_freeze(val_val);
|
590
|
+
}
|
591
|
+
}
|
592
|
+
return _self;
|
593
|
+
}
|
594
|
+
|
610
595
|
/*
|
611
596
|
* call-seq:
|
612
597
|
* Map.hash => hash_value
|
@@ -619,9 +604,8 @@ VALUE Map_hash(VALUE _self) {
|
|
619
604
|
|
620
605
|
size_t iter = kUpb_Map_Begin;
|
621
606
|
TypeInfo key_info = {self->key_type};
|
622
|
-
|
623
|
-
|
624
|
-
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
|
607
|
+
upb_MessageValue key, val;
|
608
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
625
609
|
hash = Msgval_GetHash(key, key_info, hash);
|
626
610
|
hash = Msgval_GetHash(val, self->value_type_info, hash);
|
627
611
|
}
|
data/ext/google/protobuf_c/map.h
CHANGED
@@ -1,38 +1,13 @@
|
|
1
1
|
// Protocol Buffers - Google's data interchange format
|
2
2
|
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
4
3
|
//
|
5
|
-
//
|
6
|
-
//
|
7
|
-
//
|
8
|
-
//
|
9
|
-
// * Redistributions of source code must retain the above copyright
|
10
|
-
// notice, this list of conditions and the following disclaimer.
|
11
|
-
// * Redistributions in binary form must reproduce the above
|
12
|
-
// copyright notice, this list of conditions and the following disclaimer
|
13
|
-
// in the documentation and/or other materials provided with the
|
14
|
-
// distribution.
|
15
|
-
// * Neither the name of Google Inc. nor the names of its
|
16
|
-
// contributors may be used to endorse or promote products derived from
|
17
|
-
// this software without specific prior written permission.
|
18
|
-
//
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
4
|
+
// Use of this source code is governed by a BSD-style
|
5
|
+
// license that can be found in the LICENSE file or at
|
6
|
+
// https://developers.google.com/open-source/licenses/bsd
|
30
7
|
|
31
8
|
#ifndef RUBY_PROTOBUF_MAP_H_
|
32
9
|
#define RUBY_PROTOBUF_MAP_H_
|
33
10
|
|
34
|
-
#include <ruby/ruby.h>
|
35
|
-
|
36
11
|
#include "protobuf.h"
|
37
12
|
#include "ruby-upb.h"
|
38
13
|
|
@@ -63,4 +38,7 @@ extern VALUE cMap;
|
|
63
38
|
// Call at startup to register all types in this module.
|
64
39
|
void Map_register(VALUE module);
|
65
40
|
|
41
|
+
// Recursively freeze map
|
42
|
+
VALUE Map_internal_deep_freeze(VALUE _self);
|
43
|
+
|
66
44
|
#endif // RUBY_PROTOBUF_MAP_H_
|