google-protobuf 3.7.0 → 3.12.0
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/defs.c +942 -833
- data/ext/google/protobuf_c/encode_decode.c +521 -300
- data/ext/google/protobuf_c/extconf.rb +2 -4
- data/ext/google/protobuf_c/map.c +41 -54
- data/ext/google/protobuf_c/message.c +212 -86
- data/ext/google/protobuf_c/protobuf.c +30 -15
- data/ext/google/protobuf_c/protobuf.h +114 -60
- data/ext/google/protobuf_c/repeated_field.c +55 -23
- data/ext/google/protobuf_c/storage.c +350 -171
- data/ext/google/protobuf_c/upb.c +5630 -9131
- data/ext/google/protobuf_c/upb.h +4590 -7568
- data/lib/google/protobuf/any_pb.rb +1 -1
- data/lib/google/protobuf/api_pb.rb +3 -3
- data/lib/google/protobuf/duration_pb.rb +1 -1
- data/lib/google/protobuf/empty_pb.rb +1 -1
- data/lib/google/protobuf/field_mask_pb.rb +1 -1
- data/lib/google/protobuf/source_context_pb.rb +1 -1
- data/lib/google/protobuf/struct_pb.rb +4 -4
- data/lib/google/protobuf/timestamp_pb.rb +1 -1
- data/lib/google/protobuf/type_pb.rb +8 -8
- data/lib/google/protobuf/well_known_types.rb +8 -2
- data/lib/google/protobuf/wrappers_pb.rb +9 -9
- data/lib/google/protobuf.rb +70 -0
- data/tests/basic.rb +250 -68
- data/tests/generated_code_test.rb +0 -0
- data/tests/stress.rb +0 -0
- metadata +18 -12
@@ -3,11 +3,9 @@
|
|
3
3
|
require 'mkmf'
|
4
4
|
|
5
5
|
if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
|
6
|
-
|
7
|
-
# https://stackoverflow.com/questions/35234152/strptime-giving-implicit-declaration-and-undefined-reference
|
8
|
-
$CFLAGS += " -std=c99 -O3 -DNDEBUG -D_XOPEN_SOURCE=700"
|
6
|
+
$CFLAGS += " -std=gnu90 -O3 -DNDEBUG -Wall -Wdeclaration-after-statement -Wsign-compare"
|
9
7
|
else
|
10
|
-
$CFLAGS += " -std=
|
8
|
+
$CFLAGS += " -std=gnu90 -O3 -DNDEBUG"
|
11
9
|
end
|
12
10
|
|
13
11
|
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -71,6 +71,9 @@ static VALUE table_key(Map* self, VALUE key,
|
|
71
71
|
case UPB_TYPE_BYTES:
|
72
72
|
case UPB_TYPE_STRING:
|
73
73
|
// Strings: use string content directly.
|
74
|
+
if (TYPE(key) == T_SYMBOL) {
|
75
|
+
key = rb_id2str(SYM2ID(key));
|
76
|
+
}
|
74
77
|
Check_Type(key, T_STRING);
|
75
78
|
key = native_slot_encode_and_freeze_string(self->key_type, key);
|
76
79
|
*out_key = RSTRING_PTR(key);
|
@@ -82,7 +85,7 @@ static VALUE table_key(Map* self, VALUE key,
|
|
82
85
|
case UPB_TYPE_INT64:
|
83
86
|
case UPB_TYPE_UINT32:
|
84
87
|
case UPB_TYPE_UINT64:
|
85
|
-
native_slot_set(self->key_type, Qnil, buf, key);
|
88
|
+
native_slot_set("", self->key_type, Qnil, buf, key);
|
86
89
|
*out_key = buf;
|
87
90
|
*out_length = native_slot_size(self->key_type);
|
88
91
|
break;
|
@@ -97,11 +100,11 @@ static VALUE table_key(Map* self, VALUE key,
|
|
97
100
|
return key;
|
98
101
|
}
|
99
102
|
|
100
|
-
static VALUE table_key_to_ruby(Map* self,
|
103
|
+
static VALUE table_key_to_ruby(Map* self, upb_strview key) {
|
101
104
|
switch (self->key_type) {
|
102
105
|
case UPB_TYPE_BYTES:
|
103
106
|
case UPB_TYPE_STRING: {
|
104
|
-
VALUE ret = rb_str_new(
|
107
|
+
VALUE ret = rb_str_new(key.data, key.size);
|
105
108
|
rb_enc_associate(ret,
|
106
109
|
(self->key_type == UPB_TYPE_BYTES) ?
|
107
110
|
kRubyString8bitEncoding : kRubyStringUtf8Encoding);
|
@@ -113,7 +116,7 @@ static VALUE table_key_to_ruby(Map* self, const char* buf, size_t length) {
|
|
113
116
|
case UPB_TYPE_INT64:
|
114
117
|
case UPB_TYPE_UINT32:
|
115
118
|
case UPB_TYPE_UINT64:
|
116
|
-
return native_slot_get(self->key_type, Qnil,
|
119
|
+
return native_slot_get(self->key_type, Qnil, key.data);
|
117
120
|
|
118
121
|
default:
|
119
122
|
assert(false);
|
@@ -286,9 +289,7 @@ VALUE Map_each(VALUE _self) {
|
|
286
289
|
for (upb_strtable_begin(&it, &self->table);
|
287
290
|
!upb_strtable_done(&it);
|
288
291
|
upb_strtable_next(&it)) {
|
289
|
-
|
290
|
-
VALUE key = table_key_to_ruby(
|
291
|
-
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
292
|
+
VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
|
292
293
|
|
293
294
|
upb_value v = upb_strtable_iter_value(&it);
|
294
295
|
void* mem = value_memory(&v);
|
@@ -316,9 +317,7 @@ VALUE Map_keys(VALUE _self) {
|
|
316
317
|
for (upb_strtable_begin(&it, &self->table);
|
317
318
|
!upb_strtable_done(&it);
|
318
319
|
upb_strtable_next(&it)) {
|
319
|
-
|
320
|
-
VALUE key = table_key_to_ruby(
|
321
|
-
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
320
|
+
VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
|
322
321
|
|
323
322
|
rb_ary_push(ret, key);
|
324
323
|
}
|
@@ -387,7 +386,6 @@ VALUE Map_index(VALUE _self, VALUE key) {
|
|
387
386
|
*/
|
388
387
|
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
|
389
388
|
Map* self = ruby_to_Map(_self);
|
390
|
-
|
391
389
|
char keybuf[TABLE_KEY_BUF_LENGTH];
|
392
390
|
const char* keyval = NULL;
|
393
391
|
size_t length = 0;
|
@@ -395,8 +393,15 @@ VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
|
|
395
393
|
void* mem;
|
396
394
|
key = table_key(self, key, keybuf, &keyval, &length);
|
397
395
|
|
396
|
+
rb_check_frozen(_self);
|
397
|
+
|
398
|
+
if (TYPE(value) == T_HASH) {
|
399
|
+
VALUE args[1] = { value };
|
400
|
+
value = rb_class_new_instance(1, args, self->value_type_class);
|
401
|
+
}
|
402
|
+
|
398
403
|
mem = value_memory(&v);
|
399
|
-
native_slot_set(self->value_type, self->value_type_class, mem, value);
|
404
|
+
native_slot_set("", self->value_type, self->value_type_class, mem, value);
|
400
405
|
|
401
406
|
// Replace any existing value by issuing a 'remove' operation first.
|
402
407
|
upb_strtable_remove2(&self->table, keyval, length, NULL);
|
@@ -439,13 +444,14 @@ VALUE Map_has_key(VALUE _self, VALUE key) {
|
|
439
444
|
*/
|
440
445
|
VALUE Map_delete(VALUE _self, VALUE key) {
|
441
446
|
Map* self = ruby_to_Map(_self);
|
442
|
-
|
443
447
|
char keybuf[TABLE_KEY_BUF_LENGTH];
|
444
448
|
const char* keyval = NULL;
|
445
449
|
size_t length = 0;
|
446
450
|
upb_value v;
|
447
451
|
key = table_key(self, key, keybuf, &keyval, &length);
|
448
452
|
|
453
|
+
rb_check_frozen(_self);
|
454
|
+
|
449
455
|
if (upb_strtable_remove2(&self->table, keyval, length, &v)) {
|
450
456
|
void* mem = value_memory(&v);
|
451
457
|
return native_slot_get(self->value_type, self->value_type_class, mem);
|
@@ -463,6 +469,8 @@ VALUE Map_delete(VALUE _self, VALUE key) {
|
|
463
469
|
VALUE Map_clear(VALUE _self) {
|
464
470
|
Map* self = ruby_to_Map(_self);
|
465
471
|
|
472
|
+
rb_check_frozen(_self);
|
473
|
+
|
466
474
|
// Uninit and reinit the table -- this is faster than iterating and doing a
|
467
475
|
// delete-lookup on each key.
|
468
476
|
upb_strtable_uninit(&self->table);
|
@@ -483,7 +491,7 @@ VALUE Map_length(VALUE _self) {
|
|
483
491
|
return ULL2NUM(upb_strtable_count(&self->table));
|
484
492
|
}
|
485
493
|
|
486
|
-
|
494
|
+
VALUE Map_new_this_type(VALUE _self) {
|
487
495
|
Map* self = ruby_to_Map(_self);
|
488
496
|
VALUE new_map = Qnil;
|
489
497
|
VALUE key_type = fieldtype_to_ruby(self->key_type);
|
@@ -514,17 +522,14 @@ VALUE Map_dup(VALUE _self) {
|
|
514
522
|
for (upb_strtable_begin(&it, &self->table);
|
515
523
|
!upb_strtable_done(&it);
|
516
524
|
upb_strtable_next(&it)) {
|
517
|
-
|
525
|
+
upb_strview k = upb_strtable_iter_key(&it);
|
518
526
|
upb_value v = upb_strtable_iter_value(&it);
|
519
527
|
void* mem = value_memory(&v);
|
520
528
|
upb_value dup;
|
521
529
|
void* dup_mem = value_memory(&dup);
|
522
530
|
native_slot_dup(self->value_type, dup_mem, mem);
|
523
531
|
|
524
|
-
if (!upb_strtable_insert2(&new_self->table,
|
525
|
-
upb_strtable_iter_key(&it),
|
526
|
-
upb_strtable_iter_keylength(&it),
|
527
|
-
dup)) {
|
532
|
+
if (!upb_strtable_insert2(&new_self->table, k.data, k.size, dup)) {
|
528
533
|
rb_raise(rb_eRuntimeError, "Error inserting value into new table");
|
529
534
|
}
|
530
535
|
}
|
@@ -542,17 +547,15 @@ VALUE Map_deep_copy(VALUE _self) {
|
|
542
547
|
for (upb_strtable_begin(&it, &self->table);
|
543
548
|
!upb_strtable_done(&it);
|
544
549
|
upb_strtable_next(&it)) {
|
545
|
-
|
550
|
+
upb_strview k = upb_strtable_iter_key(&it);
|
546
551
|
upb_value v = upb_strtable_iter_value(&it);
|
547
552
|
void* mem = value_memory(&v);
|
548
553
|
upb_value dup;
|
549
554
|
void* dup_mem = value_memory(&dup);
|
550
|
-
native_slot_deep_copy(self->value_type, dup_mem,
|
555
|
+
native_slot_deep_copy(self->value_type, self->value_type_class, dup_mem,
|
556
|
+
mem);
|
551
557
|
|
552
|
-
if (!upb_strtable_insert2(&new_self->table,
|
553
|
-
upb_strtable_iter_key(&it),
|
554
|
-
upb_strtable_iter_keylength(&it),
|
555
|
-
dup)) {
|
558
|
+
if (!upb_strtable_insert2(&new_self->table, k.data, k.size, dup)) {
|
556
559
|
rb_raise(rb_eRuntimeError, "Error inserting value into new table");
|
557
560
|
}
|
558
561
|
}
|
@@ -605,21 +608,19 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
|
|
605
608
|
for (upb_strtable_begin(&it, &self->table);
|
606
609
|
!upb_strtable_done(&it);
|
607
610
|
upb_strtable_next(&it)) {
|
608
|
-
|
611
|
+
upb_strview k = upb_strtable_iter_key(&it);
|
609
612
|
upb_value v = upb_strtable_iter_value(&it);
|
610
613
|
void* mem = value_memory(&v);
|
611
614
|
upb_value other_v;
|
612
615
|
void* other_mem = value_memory(&other_v);
|
613
616
|
|
614
|
-
if (!upb_strtable_lookup2(&other->table,
|
615
|
-
upb_strtable_iter_key(&it),
|
616
|
-
upb_strtable_iter_keylength(&it),
|
617
|
-
&other_v)) {
|
617
|
+
if (!upb_strtable_lookup2(&other->table, k.data, k.size, &other_v)) {
|
618
618
|
// Not present in other map.
|
619
619
|
return Qfalse;
|
620
620
|
}
|
621
621
|
|
622
|
-
if (!native_slot_eq(self->value_type, mem,
|
622
|
+
if (!native_slot_eq(self->value_type, self->value_type_class, mem,
|
623
|
+
other_mem)) {
|
623
624
|
// Present, but value not equal.
|
624
625
|
return Qfalse;
|
625
626
|
}
|
@@ -641,11 +642,9 @@ VALUE Map_hash(VALUE _self) {
|
|
641
642
|
VALUE hash_sym = rb_intern("hash");
|
642
643
|
|
643
644
|
upb_strtable_iter it;
|
644
|
-
for (upb_strtable_begin(&it, &self->table);
|
645
|
-
!upb_strtable_done(&it);
|
645
|
+
for (upb_strtable_begin(&it, &self->table); !upb_strtable_done(&it);
|
646
646
|
upb_strtable_next(&it)) {
|
647
|
-
VALUE key = table_key_to_ruby(
|
648
|
-
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
647
|
+
VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
|
649
648
|
|
650
649
|
upb_value v = upb_strtable_iter_value(&it);
|
651
650
|
void* mem = value_memory(&v);
|
@@ -673,8 +672,7 @@ VALUE Map_to_h(VALUE _self) {
|
|
673
672
|
for (upb_strtable_begin(&it, &self->table);
|
674
673
|
!upb_strtable_done(&it);
|
675
674
|
upb_strtable_next(&it)) {
|
676
|
-
VALUE key = table_key_to_ruby(
|
677
|
-
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
675
|
+
VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
|
678
676
|
upb_value v = upb_strtable_iter_value(&it);
|
679
677
|
void* mem = value_memory(&v);
|
680
678
|
VALUE value = native_slot_get(self->value_type,
|
@@ -706,11 +704,9 @@ VALUE Map_inspect(VALUE _self) {
|
|
706
704
|
VALUE inspect_sym = rb_intern("inspect");
|
707
705
|
|
708
706
|
upb_strtable_iter it;
|
709
|
-
for (upb_strtable_begin(&it, &self->table);
|
710
|
-
!upb_strtable_done(&it);
|
707
|
+
for (upb_strtable_begin(&it, &self->table); !upb_strtable_done(&it);
|
711
708
|
upb_strtable_next(&it)) {
|
712
|
-
VALUE key = table_key_to_ruby(
|
713
|
-
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
709
|
+
VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
|
714
710
|
|
715
711
|
upb_value v = upb_strtable_iter_value(&it);
|
716
712
|
void* mem = value_memory(&v);
|
@@ -771,20 +767,15 @@ VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
771
767
|
for (upb_strtable_begin(&it, &other->table);
|
772
768
|
!upb_strtable_done(&it);
|
773
769
|
upb_strtable_next(&it)) {
|
770
|
+
upb_strview k = upb_strtable_iter_key(&it);
|
774
771
|
|
775
772
|
// Replace any existing value by issuing a 'remove' operation first.
|
776
773
|
upb_value v;
|
777
774
|
upb_value oldv;
|
778
|
-
upb_strtable_remove2(&self->table,
|
779
|
-
upb_strtable_iter_key(&it),
|
780
|
-
upb_strtable_iter_keylength(&it),
|
781
|
-
&oldv);
|
775
|
+
upb_strtable_remove2(&self->table, k.data, k.size, &oldv);
|
782
776
|
|
783
777
|
v = upb_strtable_iter_value(&it);
|
784
|
-
upb_strtable_insert2(&self->table,
|
785
|
-
upb_strtable_iter_key(&it),
|
786
|
-
upb_strtable_iter_keylength(&it),
|
787
|
-
v);
|
778
|
+
upb_strtable_insert2(&self->table, k.data, k.size, v);
|
788
779
|
}
|
789
780
|
} else {
|
790
781
|
rb_raise(rb_eArgError, "Unknown type merging into Map");
|
@@ -808,10 +799,7 @@ bool Map_done(Map_iter* iter) {
|
|
808
799
|
}
|
809
800
|
|
810
801
|
VALUE Map_iter_key(Map_iter* iter) {
|
811
|
-
return table_key_to_ruby(
|
812
|
-
iter->self,
|
813
|
-
upb_strtable_iter_key(&iter->it),
|
814
|
-
upb_strtable_iter_keylength(&iter->it));
|
802
|
+
return table_key_to_ruby(iter->self, upb_strtable_iter_key(&iter->it));
|
815
803
|
}
|
816
804
|
|
817
805
|
VALUE Map_iter_value(Map_iter* iter) {
|
@@ -841,7 +829,6 @@ void Map_register(VALUE module) {
|
|
841
829
|
rb_define_method(klass, "dup", Map_dup, 0);
|
842
830
|
rb_define_method(klass, "==", Map_eq, 1);
|
843
831
|
rb_define_method(klass, "hash", Map_hash, 0);
|
844
|
-
rb_define_method(klass, "to_hash", Map_to_h, 0);
|
845
832
|
rb_define_method(klass, "to_h", Map_to_h, 0);
|
846
833
|
rb_define_method(klass, "inspect", Map_inspect, 0);
|
847
834
|
rb_define_method(klass, "merge", Map_merge, 1);
|