google-protobuf 3.25.6-java → 4.26.0-java
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/message.c +33 -72
- data/ext/google/protobuf_c/message.h +1 -1
- data/ext/google/protobuf_c/protobuf.c +19 -6
- data/ext/google/protobuf_c/ruby-upb.c +11792 -10825
- data/ext/google/protobuf_c/ruby-upb.h +5162 -4240
- data/ext/google/protobuf_c/shared_convert.c +2 -0
- data/ext/google/protobuf_c/shared_message.c +8 -7
- 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 +2 -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 +2 -3
- data/lib/google/protobuf/ffi/enum_descriptor.rb +1 -1
- data/lib/google/protobuf/ffi/ffi.rb +3 -1
- data/lib/google/protobuf/ffi/field_descriptor.rb +10 -1
- data/lib/google/protobuf/ffi/file_descriptor.rb +1 -13
- data/lib/google/protobuf/ffi/internal/convert.rb +7 -23
- data/lib/google/protobuf/ffi/map.rb +13 -11
- data/lib/google/protobuf/ffi/message.rb +10 -13
- data/lib/google/protobuf/ffi/object_cache.rb +3 -3
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +1 -1
- data/lib/google/protobuf/ffi/repeated_field.rb +12 -10
- 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 +1 -2
- 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 +1 -2
- data/lib/google/protobuf_java.jar +0 -0
- data/lib/google/protobuf_native.rb +0 -1
- data/lib/google/tasks/ffi.rake +1 -3
- metadata +8 -11
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44727ad9cc1321fcc3b3c2972e81203a02e71aaa3cac276c59d611b7c82fd854
|
4
|
+
data.tar.gz: 3792a43a19d66ed1e2cd0b8fba5c96423468b85a2b0c3a121d2a82a36537399f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad3375cea93abb128d052c328962de00341a87db926db8b94701059d01f0a36e444633caca126399fc1866a9f31bdb0b15fabbb702a6f3945c1195db1893e34
|
7
|
+
data.tar.gz: cf09131f3248c7c1886725c7bdabe9af23857933bd0792861781d720a976d107a70bdbe81cab105a88c73802f240d7fbbeb00d307b2c35d991bbadcc38435a00
|
@@ -44,9 +44,11 @@ static void Message_mark(void* _self) {
|
|
44
44
|
rb_gc_mark(self->arena);
|
45
45
|
}
|
46
46
|
|
47
|
+
static size_t Message_memsize(const void* _self) { return sizeof(Message); }
|
48
|
+
|
47
49
|
static rb_data_type_t Message_type = {
|
48
50
|
"Google::Protobuf::Message",
|
49
|
-
{Message_mark, RUBY_DEFAULT_FREE,
|
51
|
+
{Message_mark, RUBY_DEFAULT_FREE, Message_memsize},
|
50
52
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
51
53
|
};
|
52
54
|
|
@@ -661,11 +663,8 @@ static VALUE Message_dup(VALUE _self) {
|
|
661
663
|
Message* self = ruby_to_Message(_self);
|
662
664
|
VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
|
663
665
|
Message* new_msg_self = ruby_to_Message(new_msg);
|
664
|
-
|
665
|
-
|
666
|
-
// TODO
|
667
|
-
// TODO
|
668
|
-
memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
|
666
|
+
const upb_MiniTable* m = upb_MessageDef_MiniTable(self->msgdef);
|
667
|
+
upb_Message_ShallowCopy((upb_Message*)new_msg_self->msg, self->msg, m);
|
669
668
|
Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
|
670
669
|
return new_msg;
|
671
670
|
}
|
@@ -769,58 +768,34 @@ static VALUE Message_CreateHash(const upb_Message* msg,
|
|
769
768
|
if (!msg) return Qnil;
|
770
769
|
|
771
770
|
VALUE hash = rb_hash_new();
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
// This is unfortunate, we should key behaviors off field attributes (like
|
777
|
-
// whether a field has presence), not proto2 vs. proto3. We should see if we
|
778
|
-
// can change this without breaking users.
|
779
|
-
is_proto2 = upb_MessageDef_Syntax(m) == kUpb_Syntax_Proto2;
|
780
|
-
|
781
|
-
for (int i = 0; i < n; i++) {
|
782
|
-
const upb_FieldDef* field = upb_MessageDef_Field(m, i);
|
783
|
-
TypeInfo type_info = TypeInfo_get(field);
|
784
|
-
upb_MessageValue msgval;
|
785
|
-
VALUE msg_value;
|
786
|
-
VALUE msg_key;
|
787
|
-
|
788
|
-
if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
|
789
|
-
!upb_FieldDef_IsRepeated(field) &&
|
790
|
-
!upb_Message_HasFieldByDef(msg, field)) {
|
791
|
-
// TODO: Legacy behavior, remove when we fix the is_proto2 differences.
|
792
|
-
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
793
|
-
rb_hash_aset(hash, msg_key, Qnil);
|
794
|
-
continue;
|
795
|
-
}
|
771
|
+
size_t iter = kUpb_Message_Begin;
|
772
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(m));
|
773
|
+
const upb_FieldDef* field;
|
774
|
+
upb_MessageValue val;
|
796
775
|
|
797
|
-
|
798
|
-
if (
|
799
|
-
|
776
|
+
while (upb_Message_Next(msg, m, pool, &field, &val, &iter)) {
|
777
|
+
if (upb_FieldDef_IsExtension(field)) {
|
778
|
+
// TODO: allow extensions once we have decided what naming scheme the
|
779
|
+
// symbol should use. eg. :"[pkg.ext]"
|
800
780
|
continue;
|
801
781
|
}
|
802
782
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
// Proto2 omits empty map/repeated filds also.
|
783
|
+
TypeInfo type_info = TypeInfo_get(field);
|
784
|
+
VALUE msg_value;
|
807
785
|
|
808
786
|
if (upb_FieldDef_IsMap(field)) {
|
809
787
|
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field);
|
810
788
|
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
|
811
789
|
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
|
812
790
|
upb_CType key_type = upb_FieldDef_CType(key_f);
|
813
|
-
msg_value = Map_CreateHash(
|
791
|
+
msg_value = Map_CreateHash(val.map_val, key_type, TypeInfo_get(val_f));
|
814
792
|
} else if (upb_FieldDef_IsRepeated(field)) {
|
815
|
-
|
816
|
-
(!msgval.array_val || upb_Array_Size(msgval.array_val) == 0)) {
|
817
|
-
continue;
|
818
|
-
}
|
819
|
-
msg_value = RepeatedField_CreateArray(msgval.array_val, type_info);
|
793
|
+
msg_value = RepeatedField_CreateArray(val.array_val, type_info);
|
820
794
|
} else {
|
821
|
-
msg_value = Scalar_CreateHash(
|
795
|
+
msg_value = Scalar_CreateHash(val, type_info);
|
822
796
|
}
|
823
797
|
|
798
|
+
VALUE msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
824
799
|
rb_hash_aset(hash, msg_key, msg_value);
|
825
800
|
}
|
826
801
|
|
@@ -853,22 +828,12 @@ static VALUE Message_to_h(VALUE _self) {
|
|
853
828
|
* Freezes the message object. We have to intercept this so we can pin the
|
854
829
|
* Ruby object into memory so we don't forget it's frozen.
|
855
830
|
*/
|
856
|
-
|
831
|
+
VALUE Message_freeze(VALUE _self) {
|
857
832
|
Message* self = ruby_to_Message(_self);
|
858
|
-
if (!RB_OBJ_FROZEN(_self)) {
|
859
|
-
Arena_Pin(self->arena, _self);
|
860
|
-
RB_OBJ_FREEZE(_self);
|
861
|
-
}
|
862
|
-
return _self;
|
863
|
-
}
|
864
833
|
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
*/
|
869
|
-
VALUE Message_internal_deep_freeze(VALUE _self) {
|
870
|
-
Message* self = ruby_to_Message(_self);
|
871
|
-
Message_freeze(_self);
|
834
|
+
if (RB_OBJ_FROZEN(_self)) return _self;
|
835
|
+
Arena_Pin(self->arena, _self);
|
836
|
+
RB_OBJ_FREEZE(_self);
|
872
837
|
|
873
838
|
int n = upb_MessageDef_FieldCount(self->msgdef);
|
874
839
|
for (int i = 0; i < n; i++) {
|
@@ -877,11 +842,11 @@ VALUE Message_internal_deep_freeze(VALUE _self) {
|
|
877
842
|
|
878
843
|
if (field != Qnil) {
|
879
844
|
if (upb_FieldDef_IsMap(f)) {
|
880
|
-
|
845
|
+
Map_freeze(field);
|
881
846
|
} else if (upb_FieldDef_IsRepeated(f)) {
|
882
|
-
|
847
|
+
RepeatedField_freeze(field);
|
883
848
|
} else if (upb_FieldDef_IsSubMessage(f)) {
|
884
|
-
|
849
|
+
Message_freeze(field);
|
885
850
|
}
|
886
851
|
}
|
887
852
|
}
|
@@ -990,7 +955,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
|
990
955
|
rb_raise(cParseError, "Error occurred during parsing");
|
991
956
|
}
|
992
957
|
if (freeze) {
|
993
|
-
|
958
|
+
Message_freeze(msg_rb);
|
994
959
|
}
|
995
960
|
return msg_rb;
|
996
961
|
}
|
@@ -1012,9 +977,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1012
977
|
int options = 0;
|
1013
978
|
upb_Status status;
|
1014
979
|
|
1015
|
-
// TODO: use this message's pool instead.
|
1016
|
-
const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
|
1017
|
-
|
1018
980
|
if (argc < 1 || argc > 2) {
|
1019
981
|
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
|
1020
982
|
}
|
@@ -1048,8 +1010,9 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1048
1010
|
}
|
1049
1011
|
|
1050
1012
|
upb_Status_Clear(&status);
|
1013
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
|
1051
1014
|
if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data),
|
1052
|
-
(upb_Message*)msg->msg, msg->msgdef,
|
1015
|
+
(upb_Message*)msg->msg, msg->msgdef, pool, options,
|
1053
1016
|
Arena_get(msg->arena), &status)) {
|
1054
1017
|
rb_raise(cParseError, "Error occurred during parsing: %s",
|
1055
1018
|
upb_Status_ErrorMessage(&status));
|
@@ -1128,9 +1091,6 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1128
1091
|
size_t size;
|
1129
1092
|
upb_Status status;
|
1130
1093
|
|
1131
|
-
// TODO: use this message's pool instead.
|
1132
|
-
const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
|
1133
|
-
|
1134
1094
|
if (argc < 1 || argc > 2) {
|
1135
1095
|
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
|
1136
1096
|
}
|
@@ -1165,8 +1125,9 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1165
1125
|
}
|
1166
1126
|
|
1167
1127
|
upb_Status_Clear(&status);
|
1168
|
-
|
1169
|
-
|
1128
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
|
1129
|
+
size = upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf, sizeof(buf),
|
1130
|
+
&status);
|
1170
1131
|
|
1171
1132
|
if (!upb_Status_IsOk(&status)) {
|
1172
1133
|
rb_raise(cParseError, "Error occurred during encoding: %s",
|
@@ -1176,7 +1137,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1176
1137
|
VALUE ret;
|
1177
1138
|
if (size >= sizeof(buf)) {
|
1178
1139
|
char* buf2 = malloc(size + 1);
|
1179
|
-
upb_JsonEncode(msg->msg, msg->msgdef,
|
1140
|
+
upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf2, size + 1,
|
1180
1141
|
&status);
|
1181
1142
|
ret = rb_str_new(buf2, size);
|
1182
1143
|
free(buf2);
|
@@ -78,7 +78,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
|
78
78
|
VALUE klass, bool freeze);
|
79
79
|
|
80
80
|
// Recursively freeze message
|
81
|
-
VALUE
|
81
|
+
VALUE Message_freeze(VALUE _self);
|
82
82
|
|
83
83
|
// Call at startup to register all types in this module.
|
84
84
|
void Message_register(VALUE protobuf);
|
@@ -164,11 +164,23 @@ static void Arena_free(void *data) {
|
|
164
164
|
xfree(arena);
|
165
165
|
}
|
166
166
|
|
167
|
+
static size_t Arena_memsize(const void *data) {
|
168
|
+
const Arena *arena = data;
|
169
|
+
size_t fused_count;
|
170
|
+
size_t memsize = upb_Arena_SpaceAllocated(arena->arena, &fused_count);
|
171
|
+
if (fused_count > 1) {
|
172
|
+
// If other arena were fused we attribute an equal
|
173
|
+
// share of memory usage to each one.
|
174
|
+
memsize /= fused_count;
|
175
|
+
}
|
176
|
+
return memsize + sizeof(Arena);
|
177
|
+
}
|
178
|
+
|
167
179
|
static VALUE cArena;
|
168
180
|
|
169
181
|
const rb_data_type_t Arena_type = {
|
170
182
|
"Google::Protobuf::Internal::Arena",
|
171
|
-
{Arena_mark, Arena_free,
|
183
|
+
{Arena_mark, Arena_free, Arena_memsize},
|
172
184
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
173
185
|
};
|
174
186
|
|
@@ -241,16 +253,17 @@ static void ObjectCache_Init(VALUE protobuf) {
|
|
241
253
|
item_try_add = rb_intern("try_add");
|
242
254
|
|
243
255
|
rb_gc_register_address(&weak_obj_cache);
|
256
|
+
VALUE internal = rb_const_get(protobuf, rb_intern("Internal"));
|
244
257
|
#if SIZEOF_LONG >= SIZEOF_VALUE
|
245
|
-
VALUE cache_class = rb_const_get(
|
258
|
+
VALUE cache_class = rb_const_get(internal, rb_intern("ObjectCache"));
|
246
259
|
#else
|
247
|
-
VALUE cache_class = rb_const_get(
|
260
|
+
VALUE cache_class = rb_const_get(internal, rb_intern("LegacyObjectCache"));
|
248
261
|
#endif
|
249
262
|
|
250
263
|
weak_obj_cache = rb_class_new_instance(0, NULL, cache_class);
|
251
|
-
rb_const_set(
|
252
|
-
rb_const_set(
|
253
|
-
rb_const_set(
|
264
|
+
rb_const_set(internal, rb_intern("OBJECT_CACHE"), weak_obj_cache);
|
265
|
+
rb_const_set(internal, rb_intern("SIZEOF_LONG"), INT2NUM(SIZEOF_LONG));
|
266
|
+
rb_const_set(internal, rb_intern("SIZEOF_VALUE"), INT2NUM(SIZEOF_VALUE));
|
254
267
|
}
|
255
268
|
|
256
269
|
static VALUE ObjectCache_GetKey(const void *key) {
|