google-protobuf 3.24.1 → 3.25.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +23 -70
  4. data/ext/google/protobuf_c/convert.h +3 -26
  5. data/ext/google/protobuf_c/defs.c +142 -30
  6. data/ext/google/protobuf_c/defs.h +3 -26
  7. data/ext/google/protobuf_c/extconf.rb +2 -1
  8. data/ext/google/protobuf_c/glue.c +56 -0
  9. data/ext/google/protobuf_c/map.c +23 -26
  10. data/ext/google/protobuf_c/map.h +6 -26
  11. data/ext/google/protobuf_c/message.c +67 -77
  12. data/ext/google/protobuf_c/message.h +10 -26
  13. data/ext/google/protobuf_c/protobuf.c +3 -26
  14. data/ext/google/protobuf_c/protobuf.h +3 -26
  15. data/ext/google/protobuf_c/repeated_field.c +23 -27
  16. data/ext/google/protobuf_c/repeated_field.h +6 -26
  17. data/ext/google/protobuf_c/ruby-upb.c +8351 -8160
  18. data/ext/google/protobuf_c/ruby-upb.h +4077 -3784
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  24. data/lib/google/protobuf/any_pb.rb +1 -1
  25. data/lib/google/protobuf/api_pb.rb +1 -1
  26. data/lib/google/protobuf/descriptor_pb.rb +6 -3
  27. data/lib/google/protobuf/duration_pb.rb +1 -1
  28. data/lib/google/protobuf/empty_pb.rb +1 -1
  29. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  30. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  31. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  32. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  33. data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
  34. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  35. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  36. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  37. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  38. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  39. data/lib/google/protobuf/ffi/map.rb +407 -0
  40. data/lib/google/protobuf/ffi/message.rb +662 -0
  41. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  42. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  43. data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
  44. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  45. data/lib/google/protobuf/message_exts.rb +3 -26
  46. data/lib/google/protobuf/object_cache.rb +3 -26
  47. data/lib/google/protobuf/plugin_pb.rb +1 -1
  48. data/lib/google/protobuf/repeated_field.rb +3 -26
  49. data/lib/google/protobuf/source_context_pb.rb +1 -1
  50. data/lib/google/protobuf/struct_pb.rb +1 -1
  51. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  52. data/lib/google/protobuf/type_pb.rb +1 -1
  53. data/lib/google/protobuf/well_known_types.rb +3 -26
  54. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  55. data/lib/google/protobuf.rb +26 -45
  56. data/lib/google/protobuf_ffi.rb +50 -0
  57. data/lib/google/protobuf_native.rb +20 -0
  58. data/lib/google/tasks/ffi.rake +102 -0
  59. metadata +70 -3
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_MAP_H_
32
9
  #define RUBY_PROTOBUF_MAP_H_
@@ -61,4 +38,7 @@ extern VALUE cMap;
61
38
  // Call at startup to register all types in this module.
62
39
  void Map_register(VALUE module);
63
40
 
41
+ // Recursively freeze map
42
+ VALUE Map_internal_deep_freeze(VALUE _self);
43
+
64
44
  #endif // RUBY_PROTOBUF_MAP_H_
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include "message.h"
32
9
 
@@ -35,6 +12,7 @@
35
12
  #include "map.h"
36
13
  #include "protobuf.h"
37
14
  #include "repeated_field.h"
15
+ #include "shared_message.h"
38
16
 
39
17
  static VALUE cParseError = Qnil;
40
18
  static VALUE cAbstractMessage = Qnil;
@@ -684,8 +662,8 @@ static VALUE Message_dup(VALUE _self) {
684
662
  Message* new_msg_self = ruby_to_Message(new_msg);
685
663
  size_t size = upb_MessageDef_MiniTable(self->msgdef)->size;
686
664
 
687
- // TODO(copy unknown fields?)
688
- // TODO(use official upb msg copy function)
665
+ // TODO
666
+ // TODO
689
667
  memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
690
668
  Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
691
669
  return new_msg;
@@ -694,29 +672,13 @@ static VALUE Message_dup(VALUE _self) {
694
672
  // Support function for Message_eq, and also used by other #eq functions.
695
673
  bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
696
674
  const upb_MessageDef* m) {
697
- if (m1 == m2) return true;
698
-
699
- size_t size1, size2;
700
- int encode_opts =
701
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
702
- upb_Arena* arena_tmp = upb_Arena_New();
703
- const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
704
-
705
- // Compare deterministically serialized payloads with no unknown fields.
706
- char* data1;
707
- char* data2;
708
- upb_EncodeStatus status1 =
709
- upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
710
- upb_EncodeStatus status2 =
711
- upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
712
-
713
- if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
714
- bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
715
- upb_Arena_Free(arena_tmp);
716
- return ret;
675
+ upb_Status status;
676
+ upb_Status_Clear(&status);
677
+ bool return_value = shared_Message_Equal(m1, m2, m, &status);
678
+ if (upb_Status_IsOk(&status)) {
679
+ return return_value;
717
680
  } else {
718
- upb_Arena_Free(arena_tmp);
719
- rb_raise(cParseError, "Error comparing messages");
681
+ rb_raise(cParseError, upb_Status_ErrorMessage(&status));
720
682
  }
721
683
  }
722
684
 
@@ -741,23 +703,13 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
741
703
 
742
704
  uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
743
705
  uint64_t seed) {
744
- upb_Arena* arena = upb_Arena_New();
745
- char* data;
746
- size_t size;
747
-
748
- // Hash a deterministically serialized payloads with no unknown fields.
749
- upb_EncodeStatus status = upb_Encode(
750
- msg, upb_MessageDef_MiniTable(m),
751
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
752
- &data, &size);
753
-
754
- if (status == kUpb_EncodeStatus_Ok) {
755
- uint64_t ret = _upb_Hash(data, size, seed);
756
- upb_Arena_Free(arena);
757
- return ret;
706
+ upb_Status status;
707
+ upb_Status_Clear(&status);
708
+ uint64_t return_value = shared_Message_Hash(msg, m, seed, &status);
709
+ if (upb_Status_IsOk(&status)) {
710
+ return return_value;
758
711
  } else {
759
- upb_Arena_Free(arena);
760
- rb_raise(cParseError, "Error calculating hash");
712
+ rb_raise(cParseError, upb_Status_ErrorMessage(&status));
761
713
  }
762
714
  }
763
715
 
@@ -907,6 +859,32 @@ static VALUE Message_freeze(VALUE _self) {
907
859
  return _self;
908
860
  }
909
861
 
862
+ /*
863
+ * Deep freezes the message object recursively.
864
+ * Internal use only.
865
+ */
866
+ VALUE Message_internal_deep_freeze(VALUE _self) {
867
+ Message* self = ruby_to_Message(_self);
868
+ Message_freeze(_self);
869
+
870
+ int n = upb_MessageDef_FieldCount(self->msgdef);
871
+ for (int i = 0; i < n; i++) {
872
+ const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
873
+ VALUE field = Message_getfield(_self, f);
874
+
875
+ if (field != Qnil) {
876
+ if (upb_FieldDef_IsMap(f)) {
877
+ Map_internal_deep_freeze(field);
878
+ } else if (upb_FieldDef_IsRepeated(f)) {
879
+ RepeatedField_internal_deep_freeze(field);
880
+ } else if (upb_FieldDef_IsSubMessage(f)) {
881
+ Message_internal_deep_freeze(field);
882
+ }
883
+ }
884
+ }
885
+ return _self;
886
+ }
887
+
910
888
  /*
911
889
  * call-seq:
912
890
  * Message.[](index) => value
@@ -959,7 +937,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
959
937
  * MessageClass.decode(data, options) => message
960
938
  *
961
939
  * Decodes the given data (as a string containing bytes in protocol buffers wire
962
- * format) under the interpretration given by this message class's definition
940
+ * format) under the interpretation given by this message class's definition
963
941
  * and returns a message object with the corresponding field values.
964
942
  * @param options [Hash] options for the decoder
965
943
  * recursion_limit: set to maximum decoding depth for message (default is 64)
@@ -990,18 +968,27 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
990
968
  rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
991
969
  }
992
970
 
971
+ return Message_decode_bytes(RSTRING_LEN(data), RSTRING_PTR(data), options,
972
+ klass, /*freeze*/ false);
973
+ }
974
+
975
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
976
+ VALUE klass, bool freeze) {
993
977
  VALUE msg_rb = initialize_rb_class_with_no_args(klass);
994
978
  Message* msg = ruby_to_Message(msg_rb);
995
979
 
996
- upb_DecodeStatus status =
997
- upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
998
- upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
999
- Arena_get(msg->arena));
1000
-
980
+ const upb_FileDef* file = upb_MessageDef_File(msg->msgdef);
981
+ const upb_ExtensionRegistry* extreg =
982
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
983
+ upb_DecodeStatus status = upb_Decode(bytes, size, (upb_Message*)msg->msg,
984
+ upb_MessageDef_MiniTable(msg->msgdef),
985
+ extreg, options, Arena_get(msg->arena));
1001
986
  if (status != kUpb_DecodeStatus_Ok) {
1002
987
  rb_raise(cParseError, "Error occurred during parsing");
1003
988
  }
1004
-
989
+ if (freeze) {
990
+ Message_internal_deep_freeze(msg_rb);
991
+ }
1005
992
  return msg_rb;
1006
993
  }
1007
994
 
@@ -1022,7 +1009,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1022
1009
  int options = 0;
1023
1010
  upb_Status status;
1024
1011
 
1025
- // TODO(haberman): use this message's pool instead.
1012
+ // TODO: use this message's pool instead.
1026
1013
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1027
1014
 
1028
1015
  if (argc < 1 || argc > 2) {
@@ -1045,7 +1032,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1045
1032
  rb_raise(rb_eArgError, "Expected string for JSON data.");
1046
1033
  }
1047
1034
 
1048
- // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
1035
+ // TODO: Check and respect string encoding. If not UTF-8, we need to
1049
1036
  // convert, because string handlers pass data directly to message string
1050
1037
  // fields.
1051
1038
 
@@ -1138,7 +1125,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1138
1125
  size_t size;
1139
1126
  upb_Status status;
1140
1127
 
1141
- // TODO(haberman): use this message's pool instead.
1128
+ // TODO: use this message's pool instead.
1142
1129
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1143
1130
 
1144
1131
  if (argc < 1 || argc > 2) {
@@ -1319,9 +1306,12 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1319
1306
  upb_Message* new_msg = upb_Message_New(layout, arena);
1320
1307
  char* data;
1321
1308
 
1309
+ const upb_FileDef* file = upb_MessageDef_File(m);
1310
+ const upb_ExtensionRegistry* extreg =
1311
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
1322
1312
  if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
1323
1313
  kUpb_EncodeStatus_Ok ||
1324
- upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1314
+ upb_Decode(data, size, new_msg, layout, extreg, 0, arena) !=
1325
1315
  kUpb_DecodeStatus_Ok) {
1326
1316
  upb_Arena_Free(tmp_arena);
1327
1317
  rb_raise(cParseError, "Error occurred copying proto");
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_MESSAGE_H_
32
9
  #define RUBY_PROTOBUF_MESSAGE_H_
@@ -96,6 +73,13 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc);
96
73
  // module.
97
74
  VALUE MessageOrEnum_GetDescriptor(VALUE klass);
98
75
 
76
+ // Decodes a Message from a byte sequence.
77
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
78
+ VALUE klass, bool freeze);
79
+
80
+ // Recursively freeze message
81
+ VALUE Message_internal_deep_freeze(VALUE _self);
82
+
99
83
  // Call at startup to register all types in this module.
100
84
  void Message_register(VALUE protobuf);
101
85
 
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include "protobuf.h"
32
9
 
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
32
9
  #define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include "repeated_field.h"
32
9
 
@@ -286,7 +263,7 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
286
263
  memset(&fill, 0, sizeof(fill));
287
264
  for (int i = size; i < index; i++) {
288
265
  // Fill default values.
289
- // TODO(haberman): should this happen at the upb level?
266
+ // TODO: should this happen at the upb level?
290
267
  upb_Array_Set(array, i, fill);
291
268
  }
292
269
  }
@@ -510,6 +487,25 @@ static VALUE RepeatedField_freeze(VALUE _self) {
510
487
  return _self;
511
488
  }
512
489
 
490
+ /*
491
+ * Deep freezes the repeated field and values recursively.
492
+ * Internal use only.
493
+ */
494
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self) {
495
+ RepeatedField* self = ruby_to_RepeatedField(_self);
496
+ RepeatedField_freeze(_self);
497
+ if (self->type_info.type == kUpb_CType_Message) {
498
+ int size = upb_Array_Size(self->array);
499
+ int i;
500
+ for (i = 0; i < size; i++) {
501
+ upb_MessageValue msgval = upb_Array_Get(self->array, i);
502
+ VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
503
+ Message_internal_deep_freeze(val);
504
+ }
505
+ }
506
+ return _self;
507
+ }
508
+
513
509
  /*
514
510
  * call-seq:
515
511
  * RepeatedField.hash => hash_value
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_REPEATED_FIELD_H_
32
9
  #define RUBY_PROTOBUF_REPEATED_FIELD_H_
@@ -58,4 +35,7 @@ extern VALUE cRepeatedField;
58
35
  // Call at startup to register all types in this module.
59
36
  void RepeatedField_register(VALUE module);
60
37
 
38
+ // Recursively freeze RepeatedField.
39
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self);
40
+
61
41
  #endif // RUBY_PROTOBUF_REPEATED_FIELD_H_