google-protobuf 3.20.0 → 4.34.1
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 +60 -86
- data/ext/google/protobuf_c/convert.h +3 -28
- data/ext/google/protobuf_c/defs.c +961 -157
- data/ext/google/protobuf_c/defs.h +3 -28
- data/ext/google/protobuf_c/extconf.rb +21 -11
- data/ext/google/protobuf_c/glue.c +135 -0
- data/ext/google/protobuf_c/map.c +187 -121
- data/ext/google/protobuf_c/map.h +12 -30
- data/ext/google/protobuf_c/message.c +354 -294
- data/ext/google/protobuf_c/message.h +11 -33
- data/ext/google/protobuf_c/protobuf.c +65 -188
- data/ext/google/protobuf_c/protobuf.h +21 -41
- data/ext/google/protobuf_c/repeated_field.c +145 -74
- data/ext/google/protobuf_c/repeated_field.h +11 -29
- data/ext/google/protobuf_c/ruby-upb.c +15734 -8866
- data/ext/google/protobuf_c/ruby-upb.h +16769 -4511
- data/ext/google/protobuf_c/shared_convert.c +69 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +37 -0
- data/ext/google/protobuf_c/shared_message.h +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +20 -7
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/lib/google/protobuf/any_pb.rb +6 -8
- data/lib/google/protobuf/api_pb.rb +6 -26
- data/lib/google/protobuf/descriptor_pb.rb +27 -226
- data/lib/google/protobuf/duration_pb.rb +6 -8
- data/lib/google/protobuf/empty_pb.rb +6 -6
- data/lib/google/protobuf/ffi/descriptor.rb +175 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +83 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +183 -0
- data/lib/google/protobuf/ffi/ffi.rb +213 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +346 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +85 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +292 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +36 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +433 -0
- data/lib/google/protobuf/ffi/message.rb +783 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +107 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
- data/lib/google/protobuf/field_mask_pb.rb +6 -7
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +12 -26
- data/lib/google/protobuf/plugin_pb.rb +25 -0
- data/lib/google/protobuf/repeated_field.rb +22 -33
- data/lib/google/protobuf/source_context_pb.rb +6 -7
- data/lib/google/protobuf/struct_pb.rb +6 -23
- data/lib/google/protobuf/timestamp_pb.rb +6 -8
- data/lib/google/protobuf/type_pb.rb +6 -71
- data/lib/google/protobuf/well_known_types.rb +5 -34
- data/lib/google/protobuf/wrappers_pb.rb +6 -31
- data/lib/google/protobuf.rb +27 -45
- data/lib/google/protobuf_ffi.rb +52 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +103 -32
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/ext/google/protobuf_c/wrap_memcpy.c +0 -52
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
- data/tests/basic.rb +0 -670
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
|
@@ -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 "repeated_field.h"
|
|
32
9
|
|
|
@@ -67,8 +44,9 @@ static RepeatedField* ruby_to_RepeatedField(VALUE _self) {
|
|
|
67
44
|
}
|
|
68
45
|
|
|
69
46
|
static upb_Array* RepeatedField_GetMutable(VALUE _self) {
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
const upb_Array* array = ruby_to_RepeatedField(_self)->array;
|
|
48
|
+
Protobuf_CheckNotFrozen(_self, upb_Array_IsFrozen(array));
|
|
49
|
+
return (upb_Array*)array;
|
|
72
50
|
}
|
|
73
51
|
|
|
74
52
|
VALUE RepeatedField_alloc(VALUE klass) {
|
|
@@ -79,15 +57,37 @@ VALUE RepeatedField_alloc(VALUE klass) {
|
|
|
79
57
|
return TypedData_Wrap_Struct(klass, &RepeatedField_type, self);
|
|
80
58
|
}
|
|
81
59
|
|
|
82
|
-
VALUE
|
|
60
|
+
VALUE RepeatedField_EmptyFrozen(const upb_FieldDef* f) {
|
|
61
|
+
PBRUBY_ASSERT(upb_FieldDef_IsRepeated(f));
|
|
62
|
+
VALUE val = ObjectCache_Get(f);
|
|
63
|
+
|
|
64
|
+
if (val == Qnil) {
|
|
65
|
+
val = RepeatedField_alloc(cRepeatedField);
|
|
66
|
+
RepeatedField* self;
|
|
67
|
+
TypedData_Get_Struct(val, RepeatedField, &RepeatedField_type, self);
|
|
68
|
+
self->arena = Arena_new();
|
|
69
|
+
TypeInfo type_info = TypeInfo_get(f);
|
|
70
|
+
self->array = upb_Array_New(Arena_get(self->arena), type_info.type);
|
|
71
|
+
self->type_info = type_info;
|
|
72
|
+
if (self->type_info.type == kUpb_CType_Message) {
|
|
73
|
+
self->type_class = Descriptor_DefToClass(type_info.def.msgdef);
|
|
74
|
+
}
|
|
75
|
+
val = ObjectCache_TryAdd(f, RepeatedField_freeze(val));
|
|
76
|
+
}
|
|
77
|
+
PBRUBY_ASSERT(RB_OBJ_FROZEN(val));
|
|
78
|
+
PBRUBY_ASSERT(upb_Array_IsFrozen(ruby_to_RepeatedField(val)->array));
|
|
79
|
+
return val;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
VALUE RepeatedField_GetRubyWrapper(const upb_Array* array, TypeInfo type_info,
|
|
83
83
|
VALUE arena) {
|
|
84
84
|
PBRUBY_ASSERT(array);
|
|
85
|
+
PBRUBY_ASSERT(arena != Qnil);
|
|
85
86
|
VALUE val = ObjectCache_Get(array);
|
|
86
87
|
|
|
87
88
|
if (val == Qnil) {
|
|
88
89
|
val = RepeatedField_alloc(cRepeatedField);
|
|
89
90
|
RepeatedField* self;
|
|
90
|
-
ObjectCache_Add(array, val);
|
|
91
91
|
TypedData_Get_Struct(val, RepeatedField, &RepeatedField_type, self);
|
|
92
92
|
self->array = array;
|
|
93
93
|
self->arena = arena;
|
|
@@ -95,11 +95,13 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info,
|
|
|
95
95
|
if (self->type_info.type == kUpb_CType_Message) {
|
|
96
96
|
self->type_class = Descriptor_DefToClass(type_info.def.msgdef);
|
|
97
97
|
}
|
|
98
|
+
val = ObjectCache_TryAdd(array, val);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.type == type_info.type);
|
|
101
102
|
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.def.msgdef ==
|
|
102
103
|
type_info.def.msgdef);
|
|
104
|
+
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->array == array);
|
|
103
105
|
return val;
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -190,13 +192,20 @@ static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) {
|
|
|
190
192
|
return ary;
|
|
191
193
|
}
|
|
192
194
|
|
|
195
|
+
/**
|
|
196
|
+
* ruby-doc: RepeatedField
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
|
|
193
200
|
/*
|
|
194
|
-
*
|
|
195
|
-
* RepeatedField.each(&block)
|
|
201
|
+
* ruby-doc: RepeatedField#each
|
|
196
202
|
*
|
|
197
203
|
* Invokes the block once for each element of the repeated field. RepeatedField
|
|
198
204
|
* also includes Enumerable; combined with this method, the repeated field thus
|
|
199
205
|
* acts like an ordinary Ruby sequence.
|
|
206
|
+
*
|
|
207
|
+
* @yield [Object]
|
|
208
|
+
* @return [self]
|
|
200
209
|
*/
|
|
201
210
|
static VALUE RepeatedField_each(VALUE _self) {
|
|
202
211
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -212,10 +221,12 @@ static VALUE RepeatedField_each(VALUE _self) {
|
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
/*
|
|
215
|
-
*
|
|
216
|
-
* RepeatedField.[](index) => value
|
|
224
|
+
* ruby-doc: RepeatedField#[]
|
|
217
225
|
*
|
|
218
226
|
* Accesses the element at the given index. Returns nil on out-of-bounds
|
|
227
|
+
*
|
|
228
|
+
* @param index [Integer]
|
|
229
|
+
* @return [Object,nil]
|
|
219
230
|
*/
|
|
220
231
|
static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
|
|
221
232
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -260,11 +271,14 @@ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
|
|
|
260
271
|
}
|
|
261
272
|
|
|
262
273
|
/*
|
|
263
|
-
*
|
|
264
|
-
* RepeatedField.[]=(index, value)
|
|
274
|
+
* ruby-doc: RepeatedField#[]=
|
|
265
275
|
*
|
|
266
276
|
* Sets the element at the given index. On out-of-bounds assignments, extends
|
|
267
277
|
* the array and fills the hole (if any) with default values.
|
|
278
|
+
*
|
|
279
|
+
* @param index [Integer]
|
|
280
|
+
* @param value [Object
|
|
281
|
+
* @return [nil]
|
|
268
282
|
*/
|
|
269
283
|
static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
270
284
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -284,7 +298,7 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
|
284
298
|
memset(&fill, 0, sizeof(fill));
|
|
285
299
|
for (int i = size; i < index; i++) {
|
|
286
300
|
// Fill default values.
|
|
287
|
-
// TODO
|
|
301
|
+
// TODO: should this happen at the upb level?
|
|
288
302
|
upb_Array_Set(array, i, fill);
|
|
289
303
|
}
|
|
290
304
|
}
|
|
@@ -294,10 +308,12 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
|
294
308
|
}
|
|
295
309
|
|
|
296
310
|
/*
|
|
297
|
-
*
|
|
298
|
-
* RepeatedField.push(value, ...)
|
|
311
|
+
* ruby-doc: RepeatedField#push
|
|
299
312
|
*
|
|
300
313
|
* Adds a new element to the repeated field.
|
|
314
|
+
*
|
|
315
|
+
* @param value [Object]
|
|
316
|
+
* @return [self]
|
|
301
317
|
*/
|
|
302
318
|
static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) {
|
|
303
319
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -315,10 +331,12 @@ static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) {
|
|
|
315
331
|
}
|
|
316
332
|
|
|
317
333
|
/*
|
|
318
|
-
*
|
|
319
|
-
* RepeatedField.<<(value)
|
|
334
|
+
* ruby-doc: RepeatedField#<<
|
|
320
335
|
*
|
|
321
336
|
* Adds a new element to the repeated field.
|
|
337
|
+
*
|
|
338
|
+
* @param value [Object]
|
|
339
|
+
* @return [self]
|
|
322
340
|
*/
|
|
323
341
|
static VALUE RepeatedField_push(VALUE _self, VALUE val) {
|
|
324
342
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -353,10 +371,12 @@ static VALUE RepeatedField_pop_one(VALUE _self) {
|
|
|
353
371
|
}
|
|
354
372
|
|
|
355
373
|
/*
|
|
356
|
-
*
|
|
357
|
-
* RepeatedField.replace(list)
|
|
374
|
+
* ruby-doc: RepeatedField#replace
|
|
358
375
|
*
|
|
359
376
|
* Replaces the contents of the repeated field with the given list of elements.
|
|
377
|
+
*
|
|
378
|
+
* @param list [Array]
|
|
379
|
+
* @return [Array]
|
|
360
380
|
*/
|
|
361
381
|
static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
362
382
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -374,10 +394,11 @@ static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
|
374
394
|
}
|
|
375
395
|
|
|
376
396
|
/*
|
|
377
|
-
*
|
|
378
|
-
* RepeatedField.clear
|
|
397
|
+
* ruby-doc: RepeatedField#clear
|
|
379
398
|
*
|
|
380
399
|
* Clears (removes all elements from) this repeated field.
|
|
400
|
+
*
|
|
401
|
+
* @return [self]
|
|
381
402
|
*/
|
|
382
403
|
static VALUE RepeatedField_clear(VALUE _self) {
|
|
383
404
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -387,10 +408,11 @@ static VALUE RepeatedField_clear(VALUE _self) {
|
|
|
387
408
|
}
|
|
388
409
|
|
|
389
410
|
/*
|
|
390
|
-
*
|
|
391
|
-
* RepeatedField.length
|
|
411
|
+
* ruby-doc: RepeatedField#length
|
|
392
412
|
*
|
|
393
413
|
* Returns the length of this repeated field.
|
|
414
|
+
*
|
|
415
|
+
* @return [Integer]
|
|
394
416
|
*/
|
|
395
417
|
static VALUE RepeatedField_length(VALUE _self) {
|
|
396
418
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -398,11 +420,12 @@ static VALUE RepeatedField_length(VALUE _self) {
|
|
|
398
420
|
}
|
|
399
421
|
|
|
400
422
|
/*
|
|
401
|
-
*
|
|
402
|
-
* RepeatedField.dup => repeated_field
|
|
423
|
+
* ruby-doc: RepeatedField#dup
|
|
403
424
|
*
|
|
404
425
|
* Duplicates this repeated field with a shallow copy. References to all
|
|
405
426
|
* non-primitive element objects (e.g., submessages) are shared.
|
|
427
|
+
*
|
|
428
|
+
* @return [RepeatedField]
|
|
406
429
|
*/
|
|
407
430
|
static VALUE RepeatedField_dup(VALUE _self) {
|
|
408
431
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -424,11 +447,12 @@ static VALUE RepeatedField_dup(VALUE _self) {
|
|
|
424
447
|
}
|
|
425
448
|
|
|
426
449
|
/*
|
|
427
|
-
*
|
|
428
|
-
* RepeatedField.to_ary => array
|
|
450
|
+
* ruby-doc: RepeatedField#to_ary
|
|
429
451
|
*
|
|
430
452
|
* Used when converted implicitly into array, e.g. compared to an Array.
|
|
431
453
|
* Also called as a fallback of Object#to_a
|
|
454
|
+
*
|
|
455
|
+
* @return [Array]
|
|
432
456
|
*/
|
|
433
457
|
VALUE RepeatedField_to_ary(VALUE _self) {
|
|
434
458
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -446,8 +470,7 @@ VALUE RepeatedField_to_ary(VALUE _self) {
|
|
|
446
470
|
}
|
|
447
471
|
|
|
448
472
|
/*
|
|
449
|
-
*
|
|
450
|
-
* RepeatedField.==(other) => boolean
|
|
473
|
+
* ruby-doc: RepeatedField#==
|
|
451
474
|
*
|
|
452
475
|
* Compares this repeated field to another. Repeated fields are equal if their
|
|
453
476
|
* element types are equal, their lengths are equal, and each element is equal.
|
|
@@ -457,6 +480,9 @@ VALUE RepeatedField_to_ary(VALUE _self) {
|
|
|
457
480
|
* Repeated fields with dissimilar element types are never equal, even if value
|
|
458
481
|
* comparison (for example, between integers and floats) would have otherwise
|
|
459
482
|
* indicated that every element has equal value.
|
|
483
|
+
*
|
|
484
|
+
* @param other [RepeatedField]
|
|
485
|
+
* @return [Boolean]
|
|
460
486
|
*/
|
|
461
487
|
VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
462
488
|
RepeatedField* self;
|
|
@@ -493,26 +519,59 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
|
493
519
|
}
|
|
494
520
|
|
|
495
521
|
/*
|
|
496
|
-
*
|
|
497
|
-
* RepeatedField.freeze => self
|
|
522
|
+
* ruby-doc: RepeatedField#frozen?
|
|
498
523
|
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
524
|
+
* Returns true if the repeated field is frozen in either Ruby or the underlying
|
|
525
|
+
* representation. Freezes the Ruby repeated field object if it is not already
|
|
526
|
+
* frozen in Ruby but it is frozen in the underlying representation.
|
|
527
|
+
*
|
|
528
|
+
* @return [Boolean]
|
|
501
529
|
*/
|
|
502
|
-
|
|
530
|
+
VALUE RepeatedField_frozen(VALUE _self) {
|
|
503
531
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
504
|
-
if (!
|
|
505
|
-
|
|
506
|
-
|
|
532
|
+
if (!upb_Array_IsFrozen(self->array)) {
|
|
533
|
+
PBRUBY_ASSERT(!RB_OBJ_FROZEN(_self));
|
|
534
|
+
return Qfalse;
|
|
507
535
|
}
|
|
536
|
+
|
|
537
|
+
// Lazily freeze the Ruby wrapper.
|
|
538
|
+
if (!RB_OBJ_FROZEN(_self)) RB_OBJ_FREEZE(_self);
|
|
539
|
+
return Qtrue;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/*
|
|
543
|
+
* ruby-doc: RepeatedField#freeze
|
|
544
|
+
*
|
|
545
|
+
* Freezes the repeated field object. We have to intercept this so we can freeze
|
|
546
|
+
* the underlying representation, not just the Ruby wrapper.
|
|
547
|
+
*
|
|
548
|
+
* @return [self]
|
|
549
|
+
*/
|
|
550
|
+
VALUE RepeatedField_freeze(VALUE _self) {
|
|
551
|
+
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
552
|
+
if (RB_OBJ_FROZEN(_self)) {
|
|
553
|
+
PBRUBY_ASSERT(upb_Array_IsFrozen(self->array));
|
|
554
|
+
return _self;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (!upb_Array_IsFrozen(self->array)) {
|
|
558
|
+
if (self->type_info.type == kUpb_CType_Message) {
|
|
559
|
+
upb_Array_Freeze(RepeatedField_GetMutable(_self),
|
|
560
|
+
upb_MessageDef_MiniTable(self->type_info.def.msgdef));
|
|
561
|
+
} else {
|
|
562
|
+
upb_Array_Freeze(RepeatedField_GetMutable(_self), NULL);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
RB_OBJ_FREEZE(_self);
|
|
508
566
|
return _self;
|
|
509
567
|
}
|
|
510
568
|
|
|
511
569
|
/*
|
|
512
|
-
*
|
|
513
|
-
* RepeatedField.hash => hash_value
|
|
570
|
+
* ruby-doc: RepeatedField#hash
|
|
514
571
|
*
|
|
515
572
|
* Returns a hash value computed from this repeated field's elements.
|
|
573
|
+
*
|
|
574
|
+
* @return [Integer]
|
|
516
575
|
*/
|
|
517
576
|
VALUE RepeatedField_hash(VALUE _self) {
|
|
518
577
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -528,12 +587,14 @@ VALUE RepeatedField_hash(VALUE _self) {
|
|
|
528
587
|
}
|
|
529
588
|
|
|
530
589
|
/*
|
|
531
|
-
*
|
|
532
|
-
* RepeatedField.+(other) => repeated field
|
|
590
|
+
* ruby-doc: RepeatedField#+
|
|
533
591
|
*
|
|
534
592
|
* Returns a new repeated field that contains the concatenated list of this
|
|
535
593
|
* repeated field's elements and other's elements. The other (second) list may
|
|
536
594
|
* be either another repeated field or a Ruby array.
|
|
595
|
+
*
|
|
596
|
+
* @param other [Array,RepeatedField]
|
|
597
|
+
* @return [RepeatedField]
|
|
537
598
|
*/
|
|
538
599
|
VALUE RepeatedField_plus(VALUE _self, VALUE list) {
|
|
539
600
|
VALUE dupped_ = RepeatedField_dup(_self);
|
|
@@ -573,10 +634,12 @@ VALUE RepeatedField_plus(VALUE _self, VALUE list) {
|
|
|
573
634
|
}
|
|
574
635
|
|
|
575
636
|
/*
|
|
576
|
-
*
|
|
577
|
-
* RepeatedField.concat(other) => self
|
|
637
|
+
* ruby-doc: RepeatedField#concat
|
|
578
638
|
*
|
|
579
639
|
* concats the passed in array to self. Returns a Ruby array.
|
|
640
|
+
*
|
|
641
|
+
* @param other [RepeatedField]
|
|
642
|
+
* @return [Array]
|
|
580
643
|
*/
|
|
581
644
|
VALUE RepeatedField_concat(VALUE _self, VALUE list) {
|
|
582
645
|
int i;
|
|
@@ -589,15 +652,21 @@ VALUE RepeatedField_concat(VALUE _self, VALUE list) {
|
|
|
589
652
|
}
|
|
590
653
|
|
|
591
654
|
/*
|
|
592
|
-
*
|
|
593
|
-
* RepeatedField.new(type, type_class = nil, initial_elems = [])
|
|
655
|
+
* ruby-doc: RepeatedField#initialize
|
|
594
656
|
*
|
|
595
657
|
* Creates a new repeated field. The provided type must be a Ruby symbol, and
|
|
596
|
-
* can take on the same values as those accepted by FieldDescriptor#type
|
|
658
|
+
* can take on the same values as those accepted by {FieldDescriptor#type=}. If
|
|
597
659
|
* the type is :message or :enum, type_class must be non-nil, and must be the
|
|
598
|
-
* Ruby class or module returned by Descriptor#msgclass or
|
|
599
|
-
* EnumDescriptor#enummodule, respectively. An initial list of elements may
|
|
600
|
-
* be provided.
|
|
660
|
+
* Ruby class or module returned by {Descriptor#msgclass} or
|
|
661
|
+
* {EnumDescriptor#enummodule}, respectively. An initial list of elements may
|
|
662
|
+
* also be provided.
|
|
663
|
+
*
|
|
664
|
+
* @param type [Symbol]
|
|
665
|
+
* @param type_class [Class<AbstractMessage>, Module]
|
|
666
|
+
* @paramdefault type_class nil
|
|
667
|
+
* @param initial_elems [Array]
|
|
668
|
+
* @paramdefault initial_elems []
|
|
669
|
+
* @return [RepeatedField]
|
|
601
670
|
*/
|
|
602
671
|
VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) {
|
|
603
672
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -613,7 +682,8 @@ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) {
|
|
|
613
682
|
|
|
614
683
|
self->type_info = TypeInfo_FromClass(argc, argv, 0, &self->type_class, &ary);
|
|
615
684
|
self->array = upb_Array_New(arena, self->type_info.type);
|
|
616
|
-
|
|
685
|
+
VALUE stored_val = ObjectCache_TryAdd(self->array, _self);
|
|
686
|
+
PBRUBY_ASSERT(stored_val == _self);
|
|
617
687
|
|
|
618
688
|
if (ary != Qnil) {
|
|
619
689
|
if (!RB_TYPE_P(ary, T_ARRAY)) {
|
|
@@ -650,6 +720,7 @@ void RepeatedField_register(VALUE module) {
|
|
|
650
720
|
rb_define_method(klass, "==", RepeatedField_eq, 1);
|
|
651
721
|
rb_define_method(klass, "to_ary", RepeatedField_to_ary, 0);
|
|
652
722
|
rb_define_method(klass, "freeze", RepeatedField_freeze, 0);
|
|
723
|
+
rb_define_method(klass, "frozen?", RepeatedField_frozen, 0);
|
|
653
724
|
rb_define_method(klass, "hash", RepeatedField_hash, 0);
|
|
654
725
|
rb_define_method(klass, "+", RepeatedField_plus, 1);
|
|
655
726
|
rb_define_method(klass, "concat", RepeatedField_concat, 1);
|
|
@@ -1,44 +1,23 @@
|
|
|
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_REPEATED_FIELD_H_
|
|
32
9
|
#define RUBY_PROTOBUF_REPEATED_FIELD_H_
|
|
33
10
|
|
|
34
|
-
#include <ruby/ruby.h>
|
|
35
|
-
|
|
36
11
|
#include "protobuf.h"
|
|
37
12
|
#include "ruby-upb.h"
|
|
38
13
|
|
|
14
|
+
// Returns a frozen sentinel Ruby wrapper object for an empty upb_Array of the
|
|
15
|
+
// type specified by the field. Creates one if it doesn't exist.
|
|
16
|
+
VALUE RepeatedField_EmptyFrozen(const upb_FieldDef* f);
|
|
17
|
+
|
|
39
18
|
// Returns a Ruby wrapper object for the given upb_Array, which will be created
|
|
40
19
|
// if one does not exist already.
|
|
41
|
-
VALUE RepeatedField_GetRubyWrapper(upb_Array* msg, TypeInfo type_info,
|
|
20
|
+
VALUE RepeatedField_GetRubyWrapper(const upb_Array* msg, TypeInfo type_info,
|
|
42
21
|
VALUE arena);
|
|
43
22
|
|
|
44
23
|
// Gets the underlying upb_Array for this Ruby RepeatedField object, which must
|
|
@@ -60,4 +39,7 @@ extern VALUE cRepeatedField;
|
|
|
60
39
|
// Call at startup to register all types in this module.
|
|
61
40
|
void RepeatedField_register(VALUE module);
|
|
62
41
|
|
|
42
|
+
// Recursively freeze RepeatedField.
|
|
43
|
+
VALUE RepeatedField_freeze(VALUE _self);
|
|
44
|
+
|
|
63
45
|
#endif // RUBY_PROTOBUF_REPEATED_FIELD_H_
|