google-protobuf 4.36.2 → 4.37.0.rc.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/convert.c +8 -1
- data/ext/google/protobuf_c/defs.c +104 -1
- data/ext/google/protobuf_c/extconf.rb +6 -1
- data/ext/google/protobuf_c/map.c +31 -10
- data/ext/google/protobuf_c/map.h +2 -1
- data/ext/google/protobuf_c/message.c +199 -37
- data/ext/google/protobuf_c/message.h +2 -1
- data/ext/google/protobuf_c/protobuf.c +75 -6
- data/ext/google/protobuf_c/protobuf.h +1 -0
- data/ext/google/protobuf_c/repeated_field.c +39 -14
- data/ext/google/protobuf_c/ruby-upb.c +1324 -531
- data/ext/google/protobuf_c/ruby-upb.h +2282 -805
- data/ext/google/protobuf_c/shared_message.c +9 -1
- data/lib/google/protobuf/ffi/internal/convert.rb +32 -10
- data/lib/google/protobuf/ffi/map.rb +0 -1
- data/lib/google/protobuf/ffi/message.rb +10 -2
- data/lib/google/protobuf/ffi/repeated_field.rb +9 -1
- data/lib/google/protobuf/json_enumvalue_options_pb.rb +1 -1
- data/lib/google/protobuf/json_options_pb.rb +1 -1
- data/lib/google/protobuf/repeated_field.rb +2 -2
- metadata +19 -19
|
@@ -68,6 +68,7 @@ VALUE RepeatedField_EmptyFrozen(const upb_FieldDef* f) {
|
|
|
68
68
|
self->arena = Arena_new();
|
|
69
69
|
TypeInfo type_info = TypeInfo_get(f);
|
|
70
70
|
self->array = upb_Array_New(Arena_get(self->arena), type_info.type);
|
|
71
|
+
if (!self->array) Arena_raise_oom();
|
|
71
72
|
self->type_info = type_info;
|
|
72
73
|
if (self->type_info.type == kUpb_CType_Message) {
|
|
73
74
|
self->type_class = Descriptor_DefToClass(type_info.def.msgdef);
|
|
@@ -108,6 +109,7 @@ VALUE RepeatedField_GetRubyWrapper(const upb_Array* array, TypeInfo type_info,
|
|
|
108
109
|
static VALUE RepeatedField_new_this_type(RepeatedField* from) {
|
|
109
110
|
VALUE arena_rb = Arena_new();
|
|
110
111
|
upb_Array* array = upb_Array_New(Arena_get(arena_rb), from->type_info.type);
|
|
112
|
+
if (!array) Arena_raise_oom();
|
|
111
113
|
VALUE ret = RepeatedField_GetRubyWrapper(array, from->type_info, arena_rb);
|
|
112
114
|
PBRUBY_ASSERT(ruby_to_RepeatedField(ret)->type_class == from->type_class);
|
|
113
115
|
return ret;
|
|
@@ -138,7 +140,9 @@ VALUE RepeatedField_deep_copy(VALUE _self) {
|
|
|
138
140
|
upb_Arena* arena = Arena_get(arena_rb);
|
|
139
141
|
size_t elements = upb_Array_Size(self->array);
|
|
140
142
|
|
|
141
|
-
upb_Array_Resize(new_array, elements, arena)
|
|
143
|
+
if (!upb_Array_Resize(new_array, elements, arena)) {
|
|
144
|
+
Arena_raise_oom();
|
|
145
|
+
}
|
|
142
146
|
|
|
143
147
|
size_t size = upb_Array_Size(self->array);
|
|
144
148
|
for (size_t i = 0; i < size; i++) {
|
|
@@ -216,10 +220,10 @@ static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) {
|
|
|
216
220
|
*/
|
|
217
221
|
static VALUE RepeatedField_each(VALUE _self) {
|
|
218
222
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
219
|
-
int size = upb_Array_Size(self->array);
|
|
220
|
-
int i;
|
|
221
223
|
|
|
222
|
-
|
|
224
|
+
// The size is re-read every iteration: the block can clear or shrink the
|
|
225
|
+
// field, and a cached size would then index past the end of the upb array.
|
|
226
|
+
for (size_t i = 0; i < upb_Array_Size(self->array); i++) {
|
|
223
227
|
upb_MessageValue msgval = upb_Array_Get(self->array, i);
|
|
224
228
|
VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
|
|
225
229
|
rb_yield(val);
|
|
@@ -289,8 +293,6 @@ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
|
|
|
289
293
|
*/
|
|
290
294
|
static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
291
295
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
292
|
-
int size = upb_Array_Size(self->array);
|
|
293
|
-
upb_Array* array = RepeatedField_GetMutable(_self);
|
|
294
296
|
upb_Arena* arena = Arena_get(self->arena);
|
|
295
297
|
upb_MessageValue msgval = Convert_RubyToUpb(val, "", self->type_info, arena);
|
|
296
298
|
|
|
@@ -299,8 +301,16 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
|
299
301
|
return Qnil;
|
|
300
302
|
}
|
|
301
303
|
|
|
304
|
+
// The array and its size are read only after the conversions above, which
|
|
305
|
+
// can run Ruby code (index_position calls the index's to_int) that clears,
|
|
306
|
+
// shrinks or freezes the field.
|
|
307
|
+
upb_Array* array = RepeatedField_GetMutable(_self);
|
|
308
|
+
int size = upb_Array_Size(array);
|
|
309
|
+
|
|
302
310
|
if (index >= size) {
|
|
303
|
-
upb_Array_Resize(array, index + 1, arena)
|
|
311
|
+
if (!upb_Array_Resize(array, index + 1, arena)) {
|
|
312
|
+
Arena_raise_oom();
|
|
313
|
+
}
|
|
304
314
|
upb_MessageValue fill;
|
|
305
315
|
memset(&fill, 0, sizeof(fill));
|
|
306
316
|
for (int i = size; i < index; i++) {
|
|
@@ -331,7 +341,9 @@ static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) {
|
|
|
331
341
|
for (i = 0; i < argc; i++) {
|
|
332
342
|
upb_MessageValue msgval =
|
|
333
343
|
Convert_RubyToUpb(argv[i], "", self->type_info, arena);
|
|
334
|
-
upb_Array_Append(array, msgval, arena)
|
|
344
|
+
if (!upb_Array_Append(array, msgval, arena)) {
|
|
345
|
+
Arena_raise_oom();
|
|
346
|
+
}
|
|
335
347
|
}
|
|
336
348
|
|
|
337
349
|
return _self;
|
|
@@ -351,7 +363,9 @@ static VALUE RepeatedField_push(VALUE _self, VALUE val) {
|
|
|
351
363
|
upb_Array* array = RepeatedField_GetMutable(_self);
|
|
352
364
|
|
|
353
365
|
upb_MessageValue msgval = Convert_RubyToUpb(val, "", self->type_info, arena);
|
|
354
|
-
upb_Array_Append(array, msgval, arena)
|
|
366
|
+
if (!upb_Array_Append(array, msgval, arena)) {
|
|
367
|
+
Arena_raise_oom();
|
|
368
|
+
}
|
|
355
369
|
|
|
356
370
|
return _self;
|
|
357
371
|
}
|
|
@@ -373,7 +387,9 @@ static VALUE RepeatedField_pop_one(VALUE _self) {
|
|
|
373
387
|
last = upb_Array_Get(self->array, size - 1);
|
|
374
388
|
ret = Convert_UpbToRuby(last, self->type_info, self->arena);
|
|
375
389
|
|
|
376
|
-
upb_Array_Resize(array, size - 1, Arena_get(self->arena))
|
|
390
|
+
if (!upb_Array_Resize(array, size - 1, Arena_get(self->arena))) {
|
|
391
|
+
Arena_raise_oom();
|
|
392
|
+
}
|
|
377
393
|
return ret;
|
|
378
394
|
}
|
|
379
395
|
|
|
@@ -391,7 +407,9 @@ static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
|
391
407
|
int i;
|
|
392
408
|
|
|
393
409
|
Check_Type(list, T_ARRAY);
|
|
394
|
-
upb_Array_Resize(array, 0, Arena_get(self->arena))
|
|
410
|
+
if (!upb_Array_Resize(array, 0, Arena_get(self->arena))) {
|
|
411
|
+
Arena_raise_oom();
|
|
412
|
+
}
|
|
395
413
|
|
|
396
414
|
for (i = 0; i < RARRAY_LEN(list); i++) {
|
|
397
415
|
RepeatedField_push(_self, rb_ary_entry(list, i));
|
|
@@ -410,7 +428,9 @@ static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
|
410
428
|
static VALUE RepeatedField_clear(VALUE _self) {
|
|
411
429
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
412
430
|
upb_Array* array = RepeatedField_GetMutable(_self);
|
|
413
|
-
upb_Array_Resize(array, 0, Arena_get(self->arena))
|
|
431
|
+
if (!upb_Array_Resize(array, 0, Arena_get(self->arena))) {
|
|
432
|
+
Arena_raise_oom();
|
|
433
|
+
}
|
|
414
434
|
return _self;
|
|
415
435
|
}
|
|
416
436
|
|
|
@@ -447,7 +467,9 @@ static VALUE RepeatedField_dup(VALUE _self) {
|
|
|
447
467
|
|
|
448
468
|
for (i = 0; i < size; i++) {
|
|
449
469
|
upb_MessageValue msgval = upb_Array_Get(self->array, i);
|
|
450
|
-
upb_Array_Append(new_array, msgval, arena)
|
|
470
|
+
if (!upb_Array_Append(new_array, msgval, arena)) {
|
|
471
|
+
Arena_raise_oom();
|
|
472
|
+
}
|
|
451
473
|
}
|
|
452
474
|
|
|
453
475
|
return new_rptfield;
|
|
@@ -631,7 +653,9 @@ VALUE RepeatedField_plus(VALUE _self, VALUE list) {
|
|
|
631
653
|
|
|
632
654
|
for (i = 0; i < size; i++) {
|
|
633
655
|
upb_MessageValue msgval = upb_Array_Get(list_rptfield->array, i);
|
|
634
|
-
upb_Array_Append(dupped_array, msgval, arena)
|
|
656
|
+
if (!upb_Array_Append(dupped_array, msgval, arena)) {
|
|
657
|
+
Arena_raise_oom();
|
|
658
|
+
}
|
|
635
659
|
}
|
|
636
660
|
} else {
|
|
637
661
|
rb_raise(rb_eArgError, "Unknown type appending to RepeatedField");
|
|
@@ -689,6 +713,7 @@ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) {
|
|
|
689
713
|
|
|
690
714
|
self->type_info = TypeInfo_FromClass(argc, argv, 0, &self->type_class, &ary);
|
|
691
715
|
self->array = upb_Array_New(arena, self->type_info.type);
|
|
716
|
+
if (!self->array) Arena_raise_oom();
|
|
692
717
|
VALUE stored_val = ObjectCache_TryAdd(self->array, _self);
|
|
693
718
|
PBRUBY_ASSERT(stored_val == _self);
|
|
694
719
|
|