google-protobuf 4.27.4-java → 4.28.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 +74 -35
- data/ext/google/protobuf_c/message.h +1 -1
- data/ext/google/protobuf_c/protobuf.c +11 -9
- data/ext/google/protobuf_c/protobuf.h +3 -7
- data/ext/google/protobuf_c/ruby-upb.c +570 -275
- data/ext/google/protobuf_c/ruby-upb.h +1341 -584
- data/lib/google/protobuf/descriptor_pb.rb +1 -1
- data/lib/google/protobuf/ffi/descriptor.rb +1 -2
- data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
- data/lib/google/protobuf/ffi/internal/convert.rb +13 -6
- data/lib/google/protobuf/ffi/map.rb +45 -21
- data/lib/google/protobuf/ffi/message.rb +182 -60
- data/lib/google/protobuf/ffi/repeated_field.rb +42 -16
- data/lib/google/protobuf_java.jar +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87fca9e13b188341993930859a5ea3010689d9f0e3b81ef57a2fd73588367e3e
|
4
|
+
data.tar.gz: abf62cb750b18d4a3babcb63b004ebd6296485a7245fd8c80b7e8d28ea287c27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c353b75905155d6ff1a1f33f9f9d19a99873a92cf44830f1f8ee6d2211650489f6ffd6edca2e0e65e6789ada2ad0d100f4693148cb363ddff04a72d25de542a6
|
7
|
+
data.tar.gz: 2bddb36eee37c72c4d1eca916d183fa7a38550bfa110a9363827f1785abfaed55cb25b21e3c29c90a84e4dbaf07fdebbda623861870ceecea39c51009b2f53f7
|
@@ -80,11 +80,13 @@ const upb_Message* Message_Get(VALUE msg_rb, const upb_MessageDef** m) {
|
|
80
80
|
}
|
81
81
|
|
82
82
|
upb_Message* Message_GetMutable(VALUE msg_rb, const upb_MessageDef** m) {
|
83
|
-
|
84
|
-
|
83
|
+
const upb_Message* upb_msg = Message_Get(msg_rb, m);
|
84
|
+
Protobuf_CheckNotFrozen(msg_rb, upb_Message_IsFrozen(upb_msg));
|
85
|
+
return (upb_Message*)upb_msg;
|
85
86
|
}
|
86
87
|
|
87
|
-
void Message_InitPtr(VALUE self_, upb_Message* msg, VALUE arena) {
|
88
|
+
void Message_InitPtr(VALUE self_, const upb_Message* msg, VALUE arena) {
|
89
|
+
PBRUBY_ASSERT(arena != Qnil);
|
88
90
|
Message* self = ruby_to_Message(self_);
|
89
91
|
self->msg = msg;
|
90
92
|
RB_OBJ_WRITE(self_, &self->arena, arena);
|
@@ -105,7 +107,7 @@ void Message_CheckClass(VALUE klass) {
|
|
105
107
|
}
|
106
108
|
}
|
107
109
|
|
108
|
-
VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m,
|
110
|
+
VALUE Message_GetRubyWrapper(const upb_Message* msg, const upb_MessageDef* m,
|
109
111
|
VALUE arena) {
|
110
112
|
if (msg == NULL) return Qnil;
|
111
113
|
|
@@ -116,7 +118,6 @@ VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m,
|
|
116
118
|
val = Message_alloc(klass);
|
117
119
|
Message_InitPtr(val, msg, arena);
|
118
120
|
}
|
119
|
-
|
120
121
|
return val;
|
121
122
|
}
|
122
123
|
|
@@ -248,7 +249,7 @@ static int extract_method_call(VALUE method_name, Message* self,
|
|
248
249
|
static VALUE Message_oneof_accessor(VALUE _self, const upb_OneofDef* o,
|
249
250
|
int accessor_type) {
|
250
251
|
Message* self = ruby_to_Message(_self);
|
251
|
-
const upb_FieldDef* oneof_field =
|
252
|
+
const upb_FieldDef* oneof_field = upb_Message_WhichOneofByDef(self->msg, o);
|
252
253
|
|
253
254
|
switch (accessor_type) {
|
254
255
|
case METHOD_PRESENCE:
|
@@ -288,13 +289,42 @@ static void Message_setfield(upb_Message* msg, const upb_FieldDef* f, VALUE val,
|
|
288
289
|
upb_Message_SetFieldByDef(msg, f, msgval, arena);
|
289
290
|
}
|
290
291
|
|
292
|
+
VALUE Message_getfield_frozen(const upb_Message* msg, const upb_FieldDef* f,
|
293
|
+
VALUE arena) {
|
294
|
+
upb_MessageValue msgval = upb_Message_GetFieldByDef(msg, f);
|
295
|
+
if (upb_FieldDef_IsMap(f)) {
|
296
|
+
if (msgval.map_val == NULL) {
|
297
|
+
return Map_EmptyFrozen(f);
|
298
|
+
}
|
299
|
+
const upb_FieldDef* key_f = map_field_key(f);
|
300
|
+
const upb_FieldDef* val_f = map_field_value(f);
|
301
|
+
upb_CType key_type = upb_FieldDef_CType(key_f);
|
302
|
+
TypeInfo value_type_info = TypeInfo_get(val_f);
|
303
|
+
return Map_GetRubyWrapper(msgval.map_val, key_type, value_type_info, arena);
|
304
|
+
}
|
305
|
+
if (upb_FieldDef_IsRepeated(f)) {
|
306
|
+
if (msgval.array_val == NULL) {
|
307
|
+
return RepeatedField_EmptyFrozen(f);
|
308
|
+
}
|
309
|
+
return RepeatedField_GetRubyWrapper(msgval.array_val, TypeInfo_get(f),
|
310
|
+
arena);
|
311
|
+
}
|
312
|
+
VALUE ret;
|
313
|
+
if (upb_FieldDef_IsSubMessage(f)) {
|
314
|
+
const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
|
315
|
+
ret = Message_GetRubyWrapper(msgval.msg_val, m, arena);
|
316
|
+
} else {
|
317
|
+
ret = Convert_UpbToRuby(msgval, TypeInfo_get(f), Qnil);
|
318
|
+
}
|
319
|
+
return ret;
|
320
|
+
}
|
321
|
+
|
291
322
|
VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
|
292
323
|
Message* self = ruby_to_Message(_self);
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
upb_Message* msg = (upb_Message*)self->msg;
|
324
|
+
if (upb_Message_IsFrozen(self->msg)) {
|
325
|
+
return Message_getfield_frozen(self->msg, f, self->arena);
|
326
|
+
}
|
327
|
+
upb_Message* msg = Message_GetMutable(_self, NULL);
|
298
328
|
upb_Arena* arena = Arena_get(self->arena);
|
299
329
|
if (upb_FieldDef_IsMap(f)) {
|
300
330
|
upb_Map* map = upb_Message_Mutable(msg, f, arena).map;
|
@@ -307,12 +337,12 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
|
|
307
337
|
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
|
308
338
|
return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena);
|
309
339
|
} else if (upb_FieldDef_IsSubMessage(f)) {
|
310
|
-
if (!upb_Message_HasFieldByDef(
|
340
|
+
if (!upb_Message_HasFieldByDef(msg, f)) return Qnil;
|
311
341
|
upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
|
312
342
|
const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
|
313
343
|
return Message_GetRubyWrapper(submsg, m, self->arena);
|
314
344
|
} else {
|
315
|
-
upb_MessageValue msgval = upb_Message_GetFieldByDef(
|
345
|
+
upb_MessageValue msgval = upb_Message_GetFieldByDef(msg, f);
|
316
346
|
return Convert_UpbToRuby(msgval, TypeInfo_get(f), self->arena);
|
317
347
|
}
|
318
348
|
}
|
@@ -436,7 +466,6 @@ static VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
|
|
436
466
|
if (argc != 2) {
|
437
467
|
rb_raise(rb_eArgError, "Expected 2 arguments, received %d", argc);
|
438
468
|
}
|
439
|
-
rb_check_frozen(_self);
|
440
469
|
break;
|
441
470
|
default:
|
442
471
|
if (argc != 1) {
|
@@ -812,33 +841,42 @@ static VALUE Message_to_h(VALUE _self) {
|
|
812
841
|
|
813
842
|
/*
|
814
843
|
* call-seq:
|
815
|
-
* Message.
|
844
|
+
* Message.frozen? => bool
|
816
845
|
*
|
817
|
-
*
|
818
|
-
* Ruby object
|
846
|
+
* Returns true if the message is frozen in either Ruby or the underlying
|
847
|
+
* representation. Freezes the Ruby message object if it is not already frozen
|
848
|
+
* in Ruby but it is frozen in the underlying representation.
|
819
849
|
*/
|
820
|
-
VALUE
|
850
|
+
VALUE Message_frozen(VALUE _self) {
|
821
851
|
Message* self = ruby_to_Message(_self);
|
852
|
+
if (!upb_Message_IsFrozen(self->msg)) {
|
853
|
+
PBRUBY_ASSERT(!RB_OBJ_FROZEN(_self));
|
854
|
+
return Qfalse;
|
855
|
+
}
|
822
856
|
|
823
|
-
|
824
|
-
|
825
|
-
|
857
|
+
// Lazily freeze the Ruby wrapper.
|
858
|
+
if (!RB_OBJ_FROZEN(_self)) RB_OBJ_FREEZE(_self);
|
859
|
+
return Qtrue;
|
860
|
+
}
|
826
861
|
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
}
|
840
|
-
}
|
862
|
+
/*
|
863
|
+
* call-seq:
|
864
|
+
* Message.freeze => self
|
865
|
+
*
|
866
|
+
* Freezes the message object. We have to intercept this so we can freeze the
|
867
|
+
* underlying representation, not just the Ruby wrapper.
|
868
|
+
*/
|
869
|
+
VALUE Message_freeze(VALUE _self) {
|
870
|
+
Message* self = ruby_to_Message(_self);
|
871
|
+
if (RB_OBJ_FROZEN(_self)) {
|
872
|
+
PBRUBY_ASSERT(upb_Message_IsFrozen(self->msg));
|
873
|
+
return _self;
|
841
874
|
}
|
875
|
+
if (!upb_Message_IsFrozen(self->msg)) {
|
876
|
+
upb_Message_Freeze(Message_GetMutable(_self, NULL),
|
877
|
+
upb_MessageDef_MiniTable(self->msgdef));
|
878
|
+
}
|
879
|
+
RB_OBJ_FREEZE(_self);
|
842
880
|
return _self;
|
843
881
|
}
|
844
882
|
|
@@ -1352,6 +1390,7 @@ static void Message_define_class(VALUE klass) {
|
|
1352
1390
|
rb_define_method(klass, "==", Message_eq, 1);
|
1353
1391
|
rb_define_method(klass, "eql?", Message_eq, 1);
|
1354
1392
|
rb_define_method(klass, "freeze", Message_freeze, 0);
|
1393
|
+
rb_define_method(klass, "frozen?", Message_frozen, 0);
|
1355
1394
|
rb_define_method(klass, "hash", Message_hash, 0);
|
1356
1395
|
rb_define_method(klass, "to_h", Message_to_h, 0);
|
1357
1396
|
rb_define_method(klass, "inspect", Message_inspect, 0);
|
@@ -36,7 +36,7 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
|
|
36
36
|
|
37
37
|
// Gets or constructs a Ruby wrapper object for the given message. The wrapper
|
38
38
|
// object will reference |arena| and ensure that it outlives this object.
|
39
|
-
VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m,
|
39
|
+
VALUE Message_GetRubyWrapper(const upb_Message* msg, const upb_MessageDef* m,
|
40
40
|
VALUE arena);
|
41
41
|
|
42
42
|
// Gets the given field from this message.
|
@@ -221,15 +221,6 @@ void Arena_fuse(VALUE _arena, upb_Arena *other) {
|
|
221
221
|
|
222
222
|
VALUE Arena_new() { return Arena_alloc(cArena); }
|
223
223
|
|
224
|
-
void Arena_Pin(VALUE _arena, VALUE obj) {
|
225
|
-
Arena *arena;
|
226
|
-
TypedData_Get_Struct(_arena, Arena, &Arena_type, arena);
|
227
|
-
if (arena->pinned_objs == Qnil) {
|
228
|
-
RB_OBJ_WRITE(_arena, &arena->pinned_objs, rb_ary_new());
|
229
|
-
}
|
230
|
-
rb_ary_push(arena->pinned_objs, obj);
|
231
|
-
}
|
232
|
-
|
233
224
|
void Arena_register(VALUE module) {
|
234
225
|
VALUE internal = rb_define_module_under(module, "Internal");
|
235
226
|
VALUE klass = rb_define_class_under(internal, "Arena", rb_cObject);
|
@@ -354,3 +345,14 @@ __attribute__((visibility("default"))) void Init_protobuf_c() {
|
|
354
345
|
rb_define_singleton_method(protobuf, "deep_copy", Google_Protobuf_deep_copy,
|
355
346
|
1);
|
356
347
|
}
|
348
|
+
|
349
|
+
// -----------------------------------------------------------------------------
|
350
|
+
// Utilities
|
351
|
+
// -----------------------------------------------------------------------------
|
352
|
+
|
353
|
+
// Raises a Ruby error if val is frozen in Ruby or UPB.
|
354
|
+
void Protobuf_CheckNotFrozen(VALUE val, bool upb_frozen) {
|
355
|
+
if (RB_UNLIKELY(rb_obj_frozen_p(val)||upb_frozen)) {
|
356
|
+
rb_error_frozen_object(val);
|
357
|
+
}
|
358
|
+
}
|
@@ -50,13 +50,6 @@ upb_Arena* Arena_get(VALUE arena);
|
|
50
50
|
// possible.
|
51
51
|
void Arena_fuse(VALUE arena, upb_Arena* other);
|
52
52
|
|
53
|
-
// Pins this Ruby object to the lifetime of this arena, so that as long as the
|
54
|
-
// arena is alive this object will not be collected.
|
55
|
-
//
|
56
|
-
// We use this to guarantee that the "frozen" bit on the object will be
|
57
|
-
// remembered, even if the user drops their reference to this precise object.
|
58
|
-
void Arena_Pin(VALUE arena, VALUE obj);
|
59
|
-
|
60
53
|
// -----------------------------------------------------------------------------
|
61
54
|
// ObjectCache
|
62
55
|
// -----------------------------------------------------------------------------
|
@@ -105,6 +98,9 @@ extern VALUE cTypeError;
|
|
105
98
|
rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr)
|
106
99
|
#endif
|
107
100
|
|
101
|
+
// Raises a Ruby error if val is frozen in Ruby or upb_frozen is true.
|
102
|
+
void Protobuf_CheckNotFrozen(VALUE val, bool upb_frozen);
|
103
|
+
|
108
104
|
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
|
109
105
|
|
110
106
|
#define UPB_UNUSED(var) (void)var
|