google-protobuf 3.25.0 → 4.28.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +46 -18
- data/ext/google/protobuf_c/defs.c +499 -25
- data/ext/google/protobuf_c/extconf.rb +1 -1
- data/ext/google/protobuf_c/glue.c +53 -2
- data/ext/google/protobuf_c/map.c +82 -17
- data/ext/google/protobuf_c/map.h +9 -2
- data/ext/google/protobuf_c/message.c +130 -100
- data/ext/google/protobuf_c/message.h +8 -5
- data/ext/google/protobuf_c/protobuf.c +30 -15
- data/ext/google/protobuf_c/protobuf.h +3 -7
- data/ext/google/protobuf_c/repeated_field.c +64 -10
- data/ext/google/protobuf_c/repeated_field.h +8 -1
- data/ext/google/protobuf_c/ruby-upb.c +13047 -10836
- data/ext/google/protobuf_c/ruby-upb.h +11112 -9026
- data/ext/google/protobuf_c/shared_convert.c +10 -5
- data/ext/google/protobuf_c/shared_convert.h +2 -2
- data/ext/google/protobuf_c/shared_message.c +3 -31
- data/ext/google/protobuf_c/shared_message.h +0 -4
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
- data/lib/google/protobuf/any_pb.rb +1 -22
- data/lib/google/protobuf/api_pb.rb +1 -24
- data/lib/google/protobuf/descriptor_pb.rb +3 -23
- data/lib/google/protobuf/duration_pb.rb +1 -22
- data/lib/google/protobuf/empty_pb.rb +1 -22
- data/lib/google/protobuf/ffi/descriptor.rb +13 -2
- data/lib/google/protobuf/ffi/descriptor_pool.rb +16 -9
- data/lib/google/protobuf/ffi/enum_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/ffi.rb +3 -6
- data/lib/google/protobuf/ffi/field_descriptor.rb +37 -16
- data/lib/google/protobuf/ffi/file_descriptor.rb +13 -12
- data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
- data/lib/google/protobuf/ffi/internal/convert.rb +21 -30
- data/lib/google/protobuf/ffi/map.rb +50 -13
- data/lib/google/protobuf/ffi/message.rb +196 -56
- data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
- data/lib/google/protobuf/ffi/object_cache.rb +3 -3
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +20 -11
- data/lib/google/protobuf/ffi/repeated_field.rb +50 -142
- data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
- data/lib/google/protobuf/field_mask_pb.rb +1 -22
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/plugin_pb.rb +2 -24
- data/lib/google/protobuf/repeated_field.rb +4 -5
- data/lib/google/protobuf/source_context_pb.rb +1 -22
- data/lib/google/protobuf/struct_pb.rb +1 -22
- data/lib/google/protobuf/timestamp_pb.rb +1 -22
- data/lib/google/protobuf/type_pb.rb +1 -24
- data/lib/google/protobuf/wrappers_pb.rb +1 -22
- data/lib/google/protobuf.rb +1 -1
- data/lib/google/protobuf_ffi.rb +3 -2
- data/lib/google/protobuf_native.rb +0 -1
- data/lib/google/tasks/ffi.rake +1 -3
- metadata +25 -12
- 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/lib/google/protobuf/descriptor_dsl.rb +0 -465
- data/lib/google/protobuf/object_cache.rb +0 -97
@@ -44,8 +44,9 @@ static RepeatedField* ruby_to_RepeatedField(VALUE _self) {
|
|
44
44
|
}
|
45
45
|
|
46
46
|
static upb_Array* RepeatedField_GetMutable(VALUE _self) {
|
47
|
-
|
48
|
-
|
47
|
+
const upb_Array* array = ruby_to_RepeatedField(_self)->array;
|
48
|
+
Protobuf_CheckNotFrozen(_self, upb_Array_IsFrozen(array));
|
49
|
+
return (upb_Array*)array;
|
49
50
|
}
|
50
51
|
|
51
52
|
VALUE RepeatedField_alloc(VALUE klass) {
|
@@ -56,9 +57,32 @@ VALUE RepeatedField_alloc(VALUE klass) {
|
|
56
57
|
return TypedData_Wrap_Struct(klass, &RepeatedField_type, self);
|
57
58
|
}
|
58
59
|
|
59
|
-
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,
|
60
83
|
VALUE arena) {
|
61
84
|
PBRUBY_ASSERT(array);
|
85
|
+
PBRUBY_ASSERT(arena != Qnil);
|
62
86
|
VALUE val = ObjectCache_Get(array);
|
63
87
|
|
64
88
|
if (val == Qnil) {
|
@@ -78,7 +102,6 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info,
|
|
78
102
|
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.def.msgdef ==
|
79
103
|
type_info.def.msgdef);
|
80
104
|
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->array == array);
|
81
|
-
|
82
105
|
return val;
|
83
106
|
}
|
84
107
|
|
@@ -471,19 +494,49 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
471
494
|
return Qtrue;
|
472
495
|
}
|
473
496
|
|
497
|
+
/*
|
498
|
+
* call-seq:
|
499
|
+
* RepeatedField.frozen? => bool
|
500
|
+
*
|
501
|
+
* Returns true if the repeated field is frozen in either Ruby or the underlying
|
502
|
+
* representation. Freezes the Ruby repeated field object if it is not already
|
503
|
+
* frozen in Ruby but it is frozen in the underlying representation.
|
504
|
+
*/
|
505
|
+
VALUE RepeatedField_frozen(VALUE _self) {
|
506
|
+
RepeatedField* self = ruby_to_RepeatedField(_self);
|
507
|
+
if (!upb_Array_IsFrozen(self->array)) {
|
508
|
+
PBRUBY_ASSERT(!RB_OBJ_FROZEN(_self));
|
509
|
+
return Qfalse;
|
510
|
+
}
|
511
|
+
|
512
|
+
// Lazily freeze the Ruby wrapper.
|
513
|
+
if (!RB_OBJ_FROZEN(_self)) RB_OBJ_FREEZE(_self);
|
514
|
+
return Qtrue;
|
515
|
+
}
|
516
|
+
|
474
517
|
/*
|
475
518
|
* call-seq:
|
476
519
|
* RepeatedField.freeze => self
|
477
520
|
*
|
478
|
-
* Freezes the repeated field. We have to intercept this so we can
|
479
|
-
*
|
521
|
+
* Freezes the repeated field object. We have to intercept this so we can freeze
|
522
|
+
* the underlying representation, not just the Ruby wrapper.
|
480
523
|
*/
|
481
|
-
|
524
|
+
VALUE RepeatedField_freeze(VALUE _self) {
|
482
525
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
483
|
-
if (
|
484
|
-
|
485
|
-
|
526
|
+
if (RB_OBJ_FROZEN(_self)) {
|
527
|
+
PBRUBY_ASSERT(upb_Array_IsFrozen(self->array));
|
528
|
+
return _self;
|
529
|
+
}
|
530
|
+
|
531
|
+
if (!upb_Array_IsFrozen(self->array)) {
|
532
|
+
if (self->type_info.type == kUpb_CType_Message) {
|
533
|
+
upb_Array_Freeze(RepeatedField_GetMutable(_self),
|
534
|
+
upb_MessageDef_MiniTable(self->type_info.def.msgdef));
|
535
|
+
} else {
|
536
|
+
upb_Array_Freeze(RepeatedField_GetMutable(_self), NULL);
|
537
|
+
}
|
486
538
|
}
|
539
|
+
RB_OBJ_FREEZE(_self);
|
487
540
|
return _self;
|
488
541
|
}
|
489
542
|
|
@@ -630,6 +683,7 @@ void RepeatedField_register(VALUE module) {
|
|
630
683
|
rb_define_method(klass, "==", RepeatedField_eq, 1);
|
631
684
|
rb_define_method(klass, "to_ary", RepeatedField_to_ary, 0);
|
632
685
|
rb_define_method(klass, "freeze", RepeatedField_freeze, 0);
|
686
|
+
rb_define_method(klass, "frozen?", RepeatedField_frozen, 0);
|
633
687
|
rb_define_method(klass, "hash", RepeatedField_hash, 0);
|
634
688
|
rb_define_method(klass, "+", RepeatedField_plus, 1);
|
635
689
|
rb_define_method(klass, "concat", RepeatedField_concat, 1);
|
@@ -11,9 +11,13 @@
|
|
11
11
|
#include "protobuf.h"
|
12
12
|
#include "ruby-upb.h"
|
13
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
|
+
|
14
18
|
// Returns a Ruby wrapper object for the given upb_Array, which will be created
|
15
19
|
// if one does not exist already.
|
16
|
-
VALUE RepeatedField_GetRubyWrapper(upb_Array* msg, TypeInfo type_info,
|
20
|
+
VALUE RepeatedField_GetRubyWrapper(const upb_Array* msg, TypeInfo type_info,
|
17
21
|
VALUE arena);
|
18
22
|
|
19
23
|
// Gets the underlying upb_Array for this Ruby RepeatedField object, which must
|
@@ -35,4 +39,7 @@ extern VALUE cRepeatedField;
|
|
35
39
|
// Call at startup to register all types in this module.
|
36
40
|
void RepeatedField_register(VALUE module);
|
37
41
|
|
42
|
+
// Recursively freeze RepeatedField.
|
43
|
+
VALUE RepeatedField_freeze(VALUE _self);
|
44
|
+
|
38
45
|
#endif // RUBY_PROTOBUF_REPEATED_FIELD_H_
|