google-protobuf 4.28.2 → 4.31.0

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +3 -10
  3. data/ext/google/protobuf_c/defs.c +193 -3
  4. data/ext/google/protobuf_c/extconf.rb +18 -2
  5. data/ext/google/protobuf_c/glue.c +63 -0
  6. data/ext/google/protobuf_c/map.c +2 -2
  7. data/ext/google/protobuf_c/message.c +16 -8
  8. data/ext/google/protobuf_c/protobuf.c +2 -3
  9. data/ext/google/protobuf_c/protobuf.h +0 -6
  10. data/ext/google/protobuf_c/ruby-upb.c +7821 -6141
  11. data/ext/google/protobuf_c/ruby-upb.h +3812 -2627
  12. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +15 -275
  13. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
  14. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
  15. data/lib/google/protobuf/any_pb.rb +1 -1
  16. data/lib/google/protobuf/api_pb.rb +1 -1
  17. data/lib/google/protobuf/descriptor_pb.rb +6 -2
  18. data/lib/google/protobuf/duration_pb.rb +1 -1
  19. data/lib/google/protobuf/empty_pb.rb +1 -1
  20. data/lib/google/protobuf/ffi/descriptor.rb +10 -0
  21. data/lib/google/protobuf/ffi/descriptor_pool.rb +3 -1
  22. data/lib/google/protobuf/ffi/enum_descriptor.rb +10 -0
  23. data/lib/google/protobuf/ffi/ffi.rb +4 -0
  24. data/lib/google/protobuf/ffi/field_descriptor.rb +16 -0
  25. data/lib/google/protobuf/ffi/file_descriptor.rb +36 -0
  26. data/lib/google/protobuf/ffi/internal/convert.rb +1 -5
  27. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +2 -1
  28. data/lib/google/protobuf/ffi/map.rb +2 -2
  29. data/lib/google/protobuf/ffi/message.rb +5 -3
  30. data/lib/google/protobuf/ffi/method_descriptor.rb +11 -1
  31. data/lib/google/protobuf/ffi/oneof_descriptor.rb +10 -0
  32. data/lib/google/protobuf/ffi/service_descriptor.rb +11 -1
  33. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  34. data/lib/google/protobuf/message_exts.rb +4 -0
  35. data/lib/google/protobuf/plugin_pb.rb +1 -1
  36. data/lib/google/protobuf/source_context_pb.rb +1 -1
  37. data/lib/google/protobuf/struct_pb.rb +1 -1
  38. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  39. data/lib/google/protobuf/type_pb.rb +1 -1
  40. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  41. data/lib/google/protobuf_ffi.rb +3 -2
  42. metadata +23 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50f7cd8abfe74257e6fa183325ec76d6590fa2e650139a7e8c06be67b1a37265
4
- data.tar.gz: f19365b4373475b2c7d7570aceaa993cb0718fe37525ca392df3a2629dc48f85
3
+ metadata.gz: 8beb9c4c89cd4307d14eca13725b70e1f1ca50b2deaaf57b9fa61dbda74477d4
4
+ data.tar.gz: ff5c2e3d8974962ec8d04b41dda0821e79ba023113938154acf51fb969cf7b57
5
5
  SHA512:
6
- metadata.gz: cb6543ae37709a2a1e57498a2c4125bf1f8dca38efb0e80ca65389e34ef2a9b7613a5a57923d485f4dc0011bfe37a538480d1e2e999eb0f84945a10bef561c10
7
- data.tar.gz: 051b5e72dc158ecb34e8a0627be5e7efe17245f1c6be5487d8c04ff746701138a62439e479633c0479f722c62d694b6ca5f32f06193e341f8067759c187aa578
6
+ metadata.gz: 42fc3b93d2af725331f75109a259a013306d92f6a2ce0cff7407a1558b255fb21d757d8f9ce82f21e0c05a9678d3761d7647e276965c6dbeba761ad3bd2973d6
7
+ data.tar.gz: ca54aed8fbc7e7a254d26c585ab194f5e466dc9e1d68bcc0b715961e368d7a80433fecd6b131cccfbfd9b90689517b01dd3e7860481e1f306f4530e151b44efa
@@ -112,16 +112,9 @@ VALUE Convert_CheckStringUtf8(VALUE str) {
112
112
  // not mean that it is *valid* UTF-8. We have to check separately
113
113
  // whether it is valid.
114
114
  if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
115
- // TODO: For now
116
- // we only warn for this case. We will remove the warning and throw an
117
- // exception below in the 30.x release
118
-
119
- rb_warn(
120
- "String is invalid UTF-8. This will be an error in a future "
121
- "version.");
122
- // VALUE exc = rb_const_get_at(
123
- // rb_cEncoding, rb_intern("InvalidByteSequenceError"));
124
- // rb_raise(exc, "String is invalid UTF-8");
115
+ VALUE exc = rb_const_get_at(
116
+ rb_cEncoding, rb_intern("InvalidByteSequenceError"));
117
+ rb_raise(exc, "String is invalid UTF-8");
125
118
  }
126
119
  } else {
127
120
  // Note: this will not duplicate underlying string data unless
@@ -7,7 +7,6 @@
7
7
 
8
8
  #include <ctype.h>
9
9
  #include <errno.h>
10
- #include <ruby/version.h>
11
10
 
12
11
  #include "convert.h"
13
12
  #include "message.h"
@@ -147,8 +146,8 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
147
146
  * call-seq:
148
147
  * DescriptorPool.lookup(name) => descriptor
149
148
  *
150
- * Finds a Descriptor, EnumDescriptor or FieldDescriptor by name and returns it,
151
- * or nil if none exists with the given name.
149
+ * Finds a Descriptor, EnumDescriptor, FieldDescriptor or ServiceDescriptor by
150
+ * name and returns it, or nil if none exists with the given name.
152
151
  */
153
152
  static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
154
153
  DescriptorPool* self = ruby_to_DescriptorPool(_self);
@@ -157,6 +156,7 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
157
156
  const upb_EnumDef* enumdef;
158
157
  const upb_FieldDef* fielddef;
159
158
  const upb_ServiceDef* servicedef;
159
+ const upb_FileDef* filedef;
160
160
 
161
161
  msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
162
162
  if (msgdef) {
@@ -178,6 +178,11 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
178
178
  return get_servicedef_obj(_self, servicedef);
179
179
  }
180
180
 
181
+ filedef = upb_DefPool_FindFileByName(self->symtab, name_str);
182
+ if (filedef) {
183
+ return get_filedef_obj(_self, filedef);
184
+ }
185
+
181
186
  return Qnil;
182
187
  }
183
188
 
@@ -452,6 +457,27 @@ static VALUE Descriptor_options(VALUE _self) {
452
457
  return message_options;
453
458
  }
454
459
 
460
+ /*
461
+ * call-seq:
462
+ * Descriptor.to_proto => DescriptorProto
463
+ *
464
+ * Returns the `DescriptorProto` of this `Descriptor`.
465
+ */
466
+ static VALUE Descriptor_to_proto(VALUE _self) {
467
+ Descriptor* self = ruby_to_Descriptor(_self);
468
+ upb_Arena* arena = upb_Arena_New();
469
+ google_protobuf_DescriptorProto* proto =
470
+ upb_MessageDef_ToProto(self->msgdef, arena);
471
+ size_t size;
472
+ const char* serialized =
473
+ google_protobuf_DescriptorProto_serialize(proto, arena, &size);
474
+ VALUE proto_class = rb_path2class("Google::Protobuf::DescriptorProto");
475
+ VALUE proto_rb =
476
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
477
+ upb_Arena_Free(arena);
478
+ return proto_rb;
479
+ }
480
+
455
481
  static void Descriptor_register(VALUE module) {
456
482
  VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
457
483
  rb_define_alloc_func(klass, Descriptor_alloc);
@@ -464,6 +490,7 @@ static void Descriptor_register(VALUE module) {
464
490
  rb_define_method(klass, "name", Descriptor_name, 0);
465
491
  rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
466
492
  rb_define_method(klass, "options", Descriptor_options, 0);
493
+ rb_define_method(klass, "to_proto", Descriptor_to_proto, 0);
467
494
  rb_include_module(klass, rb_mEnumerable);
468
495
  rb_gc_register_address(&cDescriptor);
469
496
  cDescriptor = klass;
@@ -559,12 +586,37 @@ static VALUE FileDescriptor_options(VALUE _self) {
559
586
  return file_options;
560
587
  }
561
588
 
589
+ /*
590
+ * call-seq:
591
+ * FileDescriptor.to_proto => FileDescriptorProto
592
+ *
593
+ * Returns the `FileDescriptorProto` of this `FileDescriptor`.
594
+ */
595
+ static VALUE FileDescriptor_to_proto(VALUE _self) {
596
+ FileDescriptor* self = ruby_to_FileDescriptor(_self);
597
+ upb_Arena* arena = upb_Arena_New();
598
+ google_protobuf_FileDescriptorProto* file_proto =
599
+ upb_FileDef_ToProto(self->filedef, arena);
600
+
601
+ size_t size;
602
+ const char* serialized =
603
+ google_protobuf_FileDescriptorProto_serialize(file_proto, arena, &size);
604
+
605
+ VALUE file_proto_class =
606
+ rb_path2class("Google::Protobuf::FileDescriptorProto");
607
+ VALUE proto_rb =
608
+ Message_decode_bytes(size, serialized, 0, file_proto_class, false);
609
+ upb_Arena_Free(arena);
610
+ return proto_rb;
611
+ }
612
+
562
613
  static void FileDescriptor_register(VALUE module) {
563
614
  VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
564
615
  rb_define_alloc_func(klass, FileDescriptor_alloc);
565
616
  rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
566
617
  rb_define_method(klass, "name", FileDescriptor_name, 0);
567
618
  rb_define_method(klass, "options", FileDescriptor_options, 0);
619
+ rb_define_method(klass, "to_proto", FileDescriptor_to_proto, 0);
568
620
  rb_gc_register_address(&cFileDescriptor);
569
621
  cFileDescriptor = klass;
570
622
  }
@@ -746,6 +798,28 @@ static VALUE FieldDescriptor_has_presence(VALUE _self) {
746
798
  return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse;
747
799
  }
748
800
 
801
+ /*
802
+ * call-seq:
803
+ * FieldDescriptor.required? => bool
804
+ *
805
+ * Returns whether this is a required field.
806
+ */
807
+ static VALUE FieldDescriptor_is_required(VALUE _self) {
808
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
809
+ return upb_FieldDef_IsRequired(self->fielddef) ? Qtrue : Qfalse;
810
+ }
811
+
812
+ /*
813
+ * call-seq:
814
+ * FieldDescriptor.repeated? => bool
815
+ *
816
+ * Returns whether this is a repeated field.
817
+ */
818
+ static VALUE FieldDescriptor_is_repeated(VALUE _self) {
819
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
820
+ return upb_FieldDef_IsRepeated(self->fielddef) ? Qtrue : Qfalse;
821
+ }
822
+
749
823
  /*
750
824
  * call-seq:
751
825
  * FieldDescriptor.is_packed? => bool
@@ -771,6 +845,8 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
771
845
  }
772
846
 
773
847
  /*
848
+ * DEPRECATED: Use repeated? or required? instead.
849
+ *
774
850
  * call-seq:
775
851
  * FieldDescriptor.label => label
776
852
  *
@@ -957,6 +1033,27 @@ static VALUE FieldDescriptor_options(VALUE _self) {
957
1033
  return field_options;
958
1034
  }
959
1035
 
1036
+ /*
1037
+ * call-seq:
1038
+ * FieldDescriptor.to_proto => FieldDescriptorProto
1039
+ *
1040
+ * Returns the `FieldDescriptorProto` of this `FieldDescriptor`.
1041
+ */
1042
+ static VALUE FieldDescriptor_to_proto(VALUE _self) {
1043
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
1044
+ upb_Arena* arena = upb_Arena_New();
1045
+ google_protobuf_FieldDescriptorProto* proto =
1046
+ upb_FieldDef_ToProto(self->fielddef, arena);
1047
+ size_t size;
1048
+ const char* serialized =
1049
+ google_protobuf_FieldDescriptorProto_serialize(proto, arena, &size);
1050
+ VALUE proto_class = rb_path2class("Google::Protobuf::FieldDescriptorProto");
1051
+ VALUE proto_rb =
1052
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1053
+ upb_Arena_Free(arena);
1054
+ return proto_rb;
1055
+ }
1056
+
960
1057
  static void FieldDescriptor_register(VALUE module) {
961
1058
  VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
962
1059
  rb_define_alloc_func(klass, FieldDescriptor_alloc);
@@ -965,6 +1062,8 @@ static void FieldDescriptor_register(VALUE module) {
965
1062
  rb_define_method(klass, "type", FieldDescriptor__type, 0);
966
1063
  rb_define_method(klass, "default", FieldDescriptor_default, 0);
967
1064
  rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0);
1065
+ rb_define_method(klass, "required?", FieldDescriptor_is_required, 0);
1066
+ rb_define_method(klass, "repeated?", FieldDescriptor_is_repeated, 0);
968
1067
  rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
969
1068
  rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
970
1069
  rb_define_method(klass, "label", FieldDescriptor_label, 0);
@@ -976,6 +1075,7 @@ static void FieldDescriptor_register(VALUE module) {
976
1075
  rb_define_method(klass, "get", FieldDescriptor_get, 1);
977
1076
  rb_define_method(klass, "set", FieldDescriptor_set, 2);
978
1077
  rb_define_method(klass, "options", FieldDescriptor_options, 0);
1078
+ rb_define_method(klass, "to_proto", FieldDescriptor_to_proto, 0);
979
1079
  rb_gc_register_address(&cFieldDescriptor);
980
1080
  cFieldDescriptor = klass;
981
1081
  }
@@ -1094,6 +1194,27 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
1094
1194
  return oneof_options;
1095
1195
  }
1096
1196
 
1197
+ /*
1198
+ * call-seq:
1199
+ * OneofDescriptor.to_proto => OneofDescriptorProto
1200
+ *
1201
+ * Returns the `OneofDescriptorProto` of this `OneofDescriptor`.
1202
+ */
1203
+ static VALUE OneOfDescriptor_to_proto(VALUE _self) {
1204
+ OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
1205
+ upb_Arena* arena = upb_Arena_New();
1206
+ google_protobuf_OneofDescriptorProto* proto =
1207
+ upb_OneofDef_ToProto(self->oneofdef, arena);
1208
+ size_t size;
1209
+ const char* serialized =
1210
+ google_protobuf_OneofDescriptorProto_serialize(proto, arena, &size);
1211
+ VALUE proto_class = rb_path2class("Google::Protobuf::OneofDescriptorProto");
1212
+ VALUE proto_rb =
1213
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1214
+ upb_Arena_Free(arena);
1215
+ return proto_rb;
1216
+ }
1217
+
1097
1218
  static void OneofDescriptor_register(VALUE module) {
1098
1219
  VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
1099
1220
  rb_define_alloc_func(klass, OneofDescriptor_alloc);
@@ -1101,6 +1222,7 @@ static void OneofDescriptor_register(VALUE module) {
1101
1222
  rb_define_method(klass, "name", OneofDescriptor_name, 0);
1102
1223
  rb_define_method(klass, "each", OneofDescriptor_each, 0);
1103
1224
  rb_define_method(klass, "options", OneOfDescriptor_options, 0);
1225
+ rb_define_method(klass, "to_proto", OneOfDescriptor_to_proto, 0);
1104
1226
  rb_include_module(klass, rb_mEnumerable);
1105
1227
  rb_gc_register_address(&cOneofDescriptor);
1106
1228
  cOneofDescriptor = klass;
@@ -1299,6 +1421,29 @@ static VALUE EnumDescriptor_options(VALUE _self) {
1299
1421
  return enum_options;
1300
1422
  }
1301
1423
 
1424
+ /*
1425
+ * call-seq:
1426
+ * EnumDescriptor.to_proto => EnumDescriptorProto
1427
+ *
1428
+ * Returns the `EnumDescriptorProto` of this `EnumDescriptor`.
1429
+ */
1430
+ static VALUE EnumDescriptor_to_proto(VALUE _self) {
1431
+ EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
1432
+ upb_Arena* arena = upb_Arena_New();
1433
+ google_protobuf_EnumDescriptorProto* proto =
1434
+ upb_EnumDef_ToProto(self->enumdef, arena);
1435
+
1436
+ size_t size;
1437
+ const char* serialized =
1438
+ google_protobuf_EnumDescriptorProto_serialize(proto, arena, &size);
1439
+
1440
+ VALUE proto_class = rb_path2class("Google::Protobuf::EnumDescriptorProto");
1441
+ VALUE proto_rb =
1442
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1443
+ upb_Arena_Free(arena);
1444
+ return proto_rb;
1445
+ }
1446
+
1302
1447
  static void EnumDescriptor_register(VALUE module) {
1303
1448
  VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
1304
1449
  rb_define_alloc_func(klass, EnumDescriptor_alloc);
@@ -1311,6 +1456,7 @@ static void EnumDescriptor_register(VALUE module) {
1311
1456
  rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
1312
1457
  rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
1313
1458
  rb_define_method(klass, "options", EnumDescriptor_options, 0);
1459
+ rb_define_method(klass, "to_proto", EnumDescriptor_to_proto, 0);
1314
1460
  rb_include_module(klass, rb_mEnumerable);
1315
1461
  rb_gc_register_address(&cEnumDescriptor);
1316
1462
  cEnumDescriptor = klass;
@@ -1439,6 +1585,27 @@ static VALUE ServiceDescriptor_options(VALUE _self) {
1439
1585
  return service_options;
1440
1586
  }
1441
1587
 
1588
+ /*
1589
+ * call-seq:
1590
+ * ServiceDescriptor.to_proto => ServiceDescriptorProto
1591
+ *
1592
+ * Returns the `ServiceDescriptorProto` of this `ServiceDescriptor`.
1593
+ */
1594
+ static VALUE ServiceDescriptor_to_proto(VALUE _self) {
1595
+ ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
1596
+ upb_Arena* arena = upb_Arena_New();
1597
+ google_protobuf_ServiceDescriptorProto* proto =
1598
+ upb_ServiceDef_ToProto(self->servicedef, arena);
1599
+ size_t size;
1600
+ const char* serialized =
1601
+ google_protobuf_ServiceDescriptorProto_serialize(proto, arena, &size);
1602
+ VALUE proto_class = rb_path2class("Google::Protobuf::ServiceDescriptorProto");
1603
+ VALUE proto_rb =
1604
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1605
+ upb_Arena_Free(arena);
1606
+ return proto_rb;
1607
+ }
1608
+
1442
1609
  static void ServiceDescriptor_register(VALUE module) {
1443
1610
  VALUE klass = rb_define_class_under(module, "ServiceDescriptor", rb_cObject);
1444
1611
  rb_define_alloc_func(klass, ServiceDescriptor_alloc);
@@ -1448,6 +1615,7 @@ static void ServiceDescriptor_register(VALUE module) {
1448
1615
  rb_define_method(klass, "file_descriptor", ServiceDescriptor_file_descriptor,
1449
1616
  0);
1450
1617
  rb_define_method(klass, "options", ServiceDescriptor_options, 0);
1618
+ rb_define_method(klass, "to_proto", ServiceDescriptor_to_proto, 0);
1451
1619
  rb_include_module(klass, rb_mEnumerable);
1452
1620
  rb_gc_register_address(&cServiceDescriptor);
1453
1621
  cServiceDescriptor = klass;
@@ -1581,6 +1749,27 @@ static VALUE MethodDescriptor_client_streaming(VALUE _self) {
1581
1749
  return upb_MethodDef_ClientStreaming(self->methoddef) ? Qtrue : Qfalse;
1582
1750
  }
1583
1751
 
1752
+ /*
1753
+ * call-seq:
1754
+ * MethodDescriptor.to_proto => MethodDescriptorProto
1755
+ *
1756
+ * Returns the `MethodDescriptorProto` of this `MethodDescriptor`.
1757
+ */
1758
+ static VALUE MethodDescriptor_to_proto(VALUE _self) {
1759
+ MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
1760
+ upb_Arena* arena = upb_Arena_New();
1761
+ google_protobuf_MethodDescriptorProto* proto =
1762
+ upb_MethodDef_ToProto(self->methoddef, arena);
1763
+ size_t size;
1764
+ const char* serialized =
1765
+ google_protobuf_MethodDescriptorProto_serialize(proto, arena, &size);
1766
+ VALUE proto_class = rb_path2class("Google::Protobuf::MethodDescriptorProto");
1767
+ VALUE proto_rb =
1768
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1769
+ upb_Arena_Free(arena);
1770
+ return proto_rb;
1771
+ }
1772
+
1584
1773
  /*
1585
1774
  * call-seq:
1586
1775
  * MethodDescriptor.server_streaming => bool
@@ -1604,6 +1793,7 @@ static void MethodDescriptor_register(VALUE module) {
1604
1793
  0);
1605
1794
  rb_define_method(klass, "server_streaming", MethodDescriptor_server_streaming,
1606
1795
  0);
1796
+ rb_define_method(klass, "to_proto", MethodDescriptor_to_proto, 0);
1607
1797
  rb_gc_register_address(&cMethodDescriptor);
1608
1798
  cMethodDescriptor = klass;
1609
1799
  }
@@ -6,10 +6,26 @@ ext_name = "google/protobuf_c"
6
6
 
7
7
  dir_config(ext_name)
8
8
 
9
+ if ENV["CC"]
10
+ RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
11
+ end
12
+
13
+ if ENV["CXX"]
14
+ RbConfig::CONFIG["CXX"] = RbConfig::MAKEFILE_CONFIG["CXX"] = ENV["CXX"]
15
+ end
16
+
17
+ if ENV["LD"]
18
+ RbConfig::CONFIG["LD"] = RbConfig::MAKEFILE_CONFIG["LD"] = ENV["LD"]
19
+ end
20
+
21
+ debug_enabled = ENV["PROTOBUF_CONFIG"] == "dbg"
22
+
23
+ additional_c_flags = debug_enabled ? "-O0 -fno-omit-frame-pointer -fvisibility=default -g" : "-O3 -DNDEBUG -fvisibility=hidden"
24
+
9
25
  if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /freebsd/
10
- $CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
26
+ $CFLAGS += " -std=gnu99 -Wall -Wsign-compare -Wno-declaration-after-statement #{additional_c_flags}"
11
27
  else
12
- $CFLAGS += " -std=gnu99 -O3 -DNDEBUG"
28
+ $CFLAGS += " -std=gnu99 #{additional_c_flags}"
13
29
  end
14
30
 
15
31
  if RUBY_PLATFORM =~ /linux/
@@ -26,6 +26,15 @@ char* EnumDescriptor_serialized_options(const upb_EnumDef* enumdef,
26
26
  return serialized;
27
27
  }
28
28
 
29
+ char* EnumDescriptor_serialized_to_proto(const upb_EnumDef* enumdef,
30
+ size_t* size, upb_Arena* arena) {
31
+ const google_protobuf_EnumDescriptorProto* file_proto =
32
+ upb_EnumDef_ToProto(enumdef, arena);
33
+ char* serialized =
34
+ google_protobuf_EnumDescriptorProto_serialize(file_proto, arena, size);
35
+ return serialized;
36
+ }
37
+
29
38
  char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
30
39
  size_t* size, upb_Arena* arena) {
31
40
  const google_protobuf_FileOptions* opts = upb_FileDef_Options(filedef);
@@ -33,6 +42,15 @@ char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
33
42
  return serialized;
34
43
  }
35
44
 
45
+ char* FileDescriptor_serialized_to_proto(const upb_FileDef* filedef,
46
+ size_t* size, upb_Arena* arena) {
47
+ const google_protobuf_FileDescriptorProto* file_proto =
48
+ upb_FileDef_ToProto(filedef, arena);
49
+ char* serialized =
50
+ google_protobuf_FileDescriptorProto_serialize(file_proto, arena, size);
51
+ return serialized;
52
+ }
53
+
36
54
  char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
37
55
  upb_Arena* arena) {
38
56
  const google_protobuf_MessageOptions* opts = upb_MessageDef_Options(msgdef);
@@ -41,6 +59,15 @@ char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
41
59
  return serialized;
42
60
  }
43
61
 
62
+ char* Descriptor_serialized_to_proto(const upb_MessageDef* msgdef, size_t* size,
63
+ upb_Arena* arena) {
64
+ const google_protobuf_DescriptorProto* proto =
65
+ upb_MessageDef_ToProto(msgdef, arena);
66
+ char* serialized =
67
+ google_protobuf_DescriptorProto_serialize(proto, arena, size);
68
+ return serialized;
69
+ }
70
+
44
71
  char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
45
72
  size_t* size, upb_Arena* arena) {
46
73
  const google_protobuf_OneofOptions* opts = upb_OneofDef_Options(oneofdef);
@@ -48,6 +75,15 @@ char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
48
75
  return serialized;
49
76
  }
50
77
 
78
+ char* OneOfDescriptor_serialized_to_proto(const upb_OneofDef* oneofdef,
79
+ size_t* size, upb_Arena* arena) {
80
+ const google_protobuf_OneofDescriptorProto* proto =
81
+ upb_OneofDef_ToProto(oneofdef, arena);
82
+ char* serialized =
83
+ google_protobuf_OneofDescriptorProto_serialize(proto, arena, size);
84
+ return serialized;
85
+ }
86
+
51
87
  char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
52
88
  size_t* size, upb_Arena* arena) {
53
89
  const google_protobuf_FieldOptions* opts = upb_FieldDef_Options(fielddef);
@@ -55,6 +91,15 @@ char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
55
91
  return serialized;
56
92
  }
57
93
 
94
+ char* FieldDescriptor_serialized_to_proto(const upb_FieldDef* fieldef,
95
+ size_t* size, upb_Arena* arena) {
96
+ const google_protobuf_FieldDescriptorProto* proto =
97
+ upb_FieldDef_ToProto(fieldef, arena);
98
+ char* serialized =
99
+ google_protobuf_FieldDescriptorProto_serialize(proto, arena, size);
100
+ return serialized;
101
+ }
102
+
58
103
  char* ServiceDescriptor_serialized_options(const upb_ServiceDef* servicedef,
59
104
  size_t* size, upb_Arena* arena) {
60
105
  const google_protobuf_ServiceOptions* opts =
@@ -64,9 +109,27 @@ char* ServiceDescriptor_serialized_options(const upb_ServiceDef* servicedef,
64
109
  return serialized;
65
110
  }
66
111
 
112
+ char* ServiceDescriptor_serialized_to_proto(const upb_ServiceDef* servicedef,
113
+ size_t* size, upb_Arena* arena) {
114
+ const google_protobuf_ServiceDescriptorProto* proto =
115
+ upb_ServiceDef_ToProto(servicedef, arena);
116
+ char* serialized =
117
+ google_protobuf_ServiceDescriptorProto_serialize(proto, arena, size);
118
+ return serialized;
119
+ }
120
+
67
121
  char* MethodDescriptor_serialized_options(const upb_MethodDef* methoddef,
68
122
  size_t* size, upb_Arena* arena) {
69
123
  const google_protobuf_MethodOptions* opts = upb_MethodDef_Options(methoddef);
70
124
  char* serialized = google_protobuf_MethodOptions_serialize(opts, arena, size);
71
125
  return serialized;
72
126
  }
127
+
128
+ char* MethodDescriptor_serialized_to_proto(const upb_MethodDef* methodef,
129
+ size_t* size, upb_Arena* arena) {
130
+ const google_protobuf_MethodDescriptorProto* proto =
131
+ upb_MethodDef_ToProto(methodef, arena);
132
+ char* serialized =
133
+ google_protobuf_MethodDescriptorProto_serialize(proto, arena, size);
134
+ return serialized;
135
+ }
@@ -650,8 +650,8 @@ VALUE Map_hash(VALUE _self) {
650
650
  TypeInfo key_info = {self->key_type};
651
651
  upb_MessageValue key, val;
652
652
  while (upb_Map_Next(self->map, &key, &val, &iter)) {
653
- hash = Msgval_GetHash(key, key_info, hash);
654
- hash = Msgval_GetHash(val, self->value_type_info, hash);
653
+ hash += Msgval_GetHash(key, key_info, 0);
654
+ hash += Msgval_GetHash(val, self->value_type_info, 0);
655
655
  }
656
656
 
657
657
  return LL2NUM(hash);
@@ -362,7 +362,8 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
362
362
  if (!upb_FieldDef_HasPresence(f)) {
363
363
  rb_raise(rb_eRuntimeError, "Field does not have presence.");
364
364
  }
365
- return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f);
365
+ return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f) ? Qtrue
366
+ : Qfalse;
366
367
  case METHOD_WRAPPER_GETTER: {
367
368
  Message* self = ruby_to_Message(_self);
368
369
  if (upb_Message_HasFieldByDef(self->msg, f)) {
@@ -397,7 +398,7 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
397
398
  upb_MessageValue msgval =
398
399
  upb_Message_GetFieldByDef(Message_Get(_self, NULL), f);
399
400
 
400
- if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
401
+ if (upb_FieldDef_IsRepeated(f)) {
401
402
  // Map repeated fields to a new type with ints
402
403
  VALUE arr = rb_ary_new();
403
404
  size_t i, n = upb_Array_Size(msgval.array_val);
@@ -591,7 +592,7 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
591
592
  if (upb_FieldDef_IsMap(f)) {
592
593
  upb_Map* map = upb_Message_Mutable(msg, f, arena).map;
593
594
  Map_InitFromValue(map, f, val, arena);
594
- } else if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
595
+ } else if (upb_FieldDef_IsRepeated(f)) {
595
596
  upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
596
597
  RepeatedField_InitFromValue(arr, f, val, arena);
597
598
  } else if (upb_FieldDef_IsSubMessage(f)) {
@@ -1038,11 +1039,18 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1038
1039
 
1039
1040
  upb_Status_Clear(&status);
1040
1041
  const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
1041
- if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data),
1042
- (upb_Message*)msg->msg, msg->msgdef, pool, options,
1043
- Arena_get(msg->arena), &status)) {
1044
- rb_raise(cParseError, "Error occurred during parsing: %s",
1045
- upb_Status_ErrorMessage(&status));
1042
+
1043
+ int result = upb_JsonDecodeDetectingNonconformance(
1044
+ RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
1045
+ msg->msgdef, pool, options, Arena_get(msg->arena), &status);
1046
+
1047
+ switch (result) {
1048
+ case kUpb_JsonDecodeResult_Ok:
1049
+ break;
1050
+ case kUpb_JsonDecodeResult_Error:
1051
+ rb_raise(cParseError, "Error occurred during parsing: %s",
1052
+ upb_Status_ErrorMessage(&status));
1053
+ break;
1046
1054
  }
1047
1055
 
1048
1056
  return msg_rb;
@@ -7,8 +7,6 @@
7
7
 
8
8
  #include "protobuf.h"
9
9
 
10
- #include <ruby/version.h>
11
-
12
10
  #include "defs.h"
13
11
  #include "map.h"
14
12
  #include "message.h"
@@ -288,7 +286,8 @@ VALUE ObjectCache_Get(const void *key) {
288
286
  static VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) {
289
287
  const upb_MessageDef *m;
290
288
  upb_Message *msg = Message_GetMutable(msg_rb, &m);
291
- if (!upb_Message_DiscardUnknown(msg, m, 128)) {
289
+ const upb_DefPool* ext_pool = upb_FileDef_Pool(upb_MessageDef_File(m));
290
+ if (!upb_Message_DiscardUnknown(msg, m, ext_pool, 128)) {
292
291
  rb_raise(rb_eRuntimeError, "Messages nested too deeply.");
293
292
  }
294
293
 
@@ -16,12 +16,6 @@
16
16
  #undef NDEBUG
17
17
  #endif
18
18
 
19
- #include <ruby/version.h>
20
-
21
- #if RUBY_API_VERSION_CODE < 20700
22
- #error Protobuf requires Ruby >= 2.7
23
- #endif
24
-
25
19
  #include <assert.h> // Must be included after the NDEBUG logic above.
26
20
  #include <ruby/encoding.h>
27
21
  #include <ruby/vm.h>