google-protobuf 3.21.0 → 4.28.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.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +67 -86
  4. data/ext/google/protobuf_c/convert.h +3 -28
  5. data/ext/google/protobuf_c/defs.c +537 -75
  6. data/ext/google/protobuf_c/defs.h +3 -28
  7. data/ext/google/protobuf_c/extconf.rb +4 -4
  8. data/ext/google/protobuf_c/glue.c +72 -0
  9. data/ext/google/protobuf_c/map.c +114 -85
  10. data/ext/google/protobuf_c/map.h +12 -30
  11. data/ext/google/protobuf_c/message.c +250 -234
  12. data/ext/google/protobuf_c/message.h +11 -33
  13. data/ext/google/protobuf_c/protobuf.c +63 -185
  14. data/ext/google/protobuf_c/protobuf.h +27 -39
  15. data/ext/google/protobuf_c/repeated_field.c +72 -38
  16. data/ext/google/protobuf_c/repeated_field.h +11 -29
  17. data/ext/google/protobuf_c/ruby-upb.c +14513 -9003
  18. data/ext/google/protobuf_c/ruby-upb.h +13990 -4496
  19. data/ext/google/protobuf_c/shared_convert.c +69 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +37 -0
  22. data/ext/google/protobuf_c/shared_message.h +21 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
  25. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +20 -7
  26. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  27. data/lib/google/protobuf/any_pb.rb +6 -8
  28. data/lib/google/protobuf/api_pb.rb +6 -26
  29. data/lib/google/protobuf/descriptor_pb.rb +23 -226
  30. data/lib/google/protobuf/duration_pb.rb +6 -8
  31. data/lib/google/protobuf/empty_pb.rb +6 -6
  32. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  33. data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
  34. data/lib/google/protobuf/ffi/enum_descriptor.rb +173 -0
  35. data/lib/google/protobuf/ffi/ffi.rb +210 -0
  36. data/lib/google/protobuf/ffi/field_descriptor.rb +330 -0
  37. data/lib/google/protobuf/ffi/file_descriptor.rb +49 -0
  38. data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
  39. data/lib/google/protobuf/ffi/internal/convert.rb +296 -0
  40. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  41. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  42. data/lib/google/protobuf/ffi/map.rb +433 -0
  43. data/lib/google/protobuf/ffi/message.rb +781 -0
  44. data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
  45. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  46. data/lib/google/protobuf/ffi/oneof_descriptor.rb +97 -0
  47. data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
  48. data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
  49. data/lib/google/protobuf/field_mask_pb.rb +6 -7
  50. data/lib/google/protobuf/internal/object_cache.rb +99 -0
  51. data/lib/google/protobuf/message_exts.rb +8 -26
  52. data/lib/google/protobuf/plugin_pb.rb +25 -0
  53. data/lib/google/protobuf/repeated_field.rb +7 -31
  54. data/lib/google/protobuf/source_context_pb.rb +6 -7
  55. data/lib/google/protobuf/struct_pb.rb +6 -23
  56. data/lib/google/protobuf/timestamp_pb.rb +6 -8
  57. data/lib/google/protobuf/type_pb.rb +6 -71
  58. data/lib/google/protobuf/well_known_types.rb +5 -34
  59. data/lib/google/protobuf/wrappers_pb.rb +6 -31
  60. data/lib/google/protobuf.rb +27 -45
  61. data/lib/google/protobuf_ffi.rb +51 -0
  62. data/lib/google/protobuf_native.rb +19 -0
  63. data/lib/google/tasks/ffi.rake +100 -0
  64. metadata +92 -16
  65. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
  66. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
  67. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
  68. data/lib/google/protobuf/descriptor_dsl.rb +0 -465
  69. data/tests/basic.rb +0 -739
  70. data/tests/generated_code_test.rb +0 -23
  71. data/tests/stress.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c45dfcce28e802c96cf4b4179161ae0c36f724a54d5a2535830e1f3def8addd4
4
- data.tar.gz: e93796377de0d6aacea3094077cfc2e715d7f8566356933319456ef59cf9f718
3
+ metadata.gz: 531c1d4e78630f992244bac8fac8176297a60073b58bd92d344083f478f8dcb5
4
+ data.tar.gz: de1b062231118253de9063e495ce188907760bf536a368a426d0ab1cf59ea5bb
5
5
  SHA512:
6
- metadata.gz: 97934da6ce205d16d9de579349a4bcf80431582ce1cc39a32d6a8ca5273b850f96afec25bda3dd903c9361d54cad01a2bf53d4af908fd21d39926239de35bcc7
7
- data.tar.gz: d78bb7e9b1ba2dd1d14fd8dbf9b76fe4313500fcb380a57de1e79d50767c00313bbbabdf335f37cf734e88b8a3adafa8528cc3507fee9a6532954ac2aacb45cb
6
+ metadata.gz: ec022839412e0210fa1cd44b34d96defb2c83a0ca7c1b84bc62f00526f2af64d70abbfda7c405b0a8eaa718ab366a80bbbd7ee3a072144a539282adc7fb24059
7
+ data.tar.gz: 87463961cb841e762147dcdbd648557cd0a5228e122a717f6429220d485a2dea1fe32f3f1efbcb71504e2b2ad1a191810adcf4327c93bcb047bb6fb244a7748b
@@ -0,0 +1,3 @@
1
+ import '../../../lib/google/tasks/ffi.rake'
2
+
3
+ task default: ['ffi-protobuf:default']
@@ -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
  // -----------------------------------------------------------------------------
32
9
  // Ruby <-> upb data conversion functions.
@@ -41,6 +18,7 @@
41
18
 
42
19
  #include "message.h"
43
20
  #include "protobuf.h"
21
+ #include "shared_convert.h"
44
22
 
45
23
  static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
46
24
  upb_StringView ret;
@@ -111,8 +89,7 @@ static int32_t Convert_ToEnum(VALUE value, const char* name,
111
89
  case T_SYMBOL: {
112
90
  const upb_EnumValueDef* ev =
113
91
  upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value)));
114
- if (!ev)
115
- goto unknownval;
92
+ if (!ev) goto unknownval;
116
93
  val = upb_EnumValueDef_Number(ev);
117
94
  break;
118
95
  }
@@ -127,6 +104,41 @@ unknownval:
127
104
  rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
128
105
  }
129
106
 
107
+ VALUE Convert_CheckStringUtf8(VALUE str) {
108
+ VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
109
+
110
+ if (rb_obj_encoding(str) == utf8) {
111
+ // Note: Just because a string is marked as having UTF-8 encoding does
112
+ // not mean that it is *valid* UTF-8. We have to check separately
113
+ // whether it is valid.
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");
125
+ }
126
+ } else {
127
+ // Note: this will not duplicate underlying string data unless
128
+ // necessary.
129
+ //
130
+ // This will throw an exception if the conversion cannot be performed:
131
+ // - Encoding::UndefinedConversionError if certain characters cannot be
132
+ // converted to UTF-8.
133
+ // - Encoding::InvalidByteSequenceError if certain characters were invalid
134
+ // in the source encoding.
135
+ str = rb_str_encode(str, utf8, 0, Qnil);
136
+ PBRUBY_ASSERT(rb_enc_str_coderange(str) != ENC_CODERANGE_BROKEN);
137
+ }
138
+
139
+ return str;
140
+ }
141
+
130
142
  upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
131
143
  TypeInfo type_info, upb_Arena* arena) {
132
144
  upb_MessageValue ret;
@@ -160,29 +172,18 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
160
172
  }
161
173
  break;
162
174
  }
163
- case kUpb_CType_String: {
164
- VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
175
+ case kUpb_CType_String:
165
176
  if (rb_obj_class(value) == rb_cSymbol) {
166
177
  value = rb_funcall(value, rb_intern("to_s"), 0);
167
- } else if (rb_obj_class(value) != rb_cString) {
178
+ } else if (!rb_obj_is_kind_of(value, rb_cString)) {
168
179
  rb_raise(cTypeError,
169
180
  "Invalid argument for string field '%s' (given %s).", name,
170
181
  rb_class2name(CLASS_OF(value)));
171
182
  }
172
183
 
173
- if (rb_obj_encoding(value) != utf8) {
174
- // Note: this will not duplicate underlying string data unless
175
- // necessary.
176
- value = rb_str_encode(value, utf8, 0, Qnil);
177
-
178
- if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
179
- rb_raise(rb_eEncodingError, "String is invalid UTF-8");
180
- }
181
- }
182
-
184
+ value = Convert_CheckStringUtf8(value);
183
185
  ret.str_val = Convert_StringData(value, arena);
184
186
  break;
185
- }
186
187
  case kUpb_CType_Bytes: {
187
188
  VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
188
189
  if (rb_obj_class(value) != rb_cString) {
@@ -194,7 +195,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
194
195
  if (rb_obj_encoding(value) != bytes) {
195
196
  // Note: this will not duplicate underlying string data unless
196
197
  // necessary.
197
- // TODO(haberman): is this really necessary to get raw bytes?
198
+ // TODO: is this really necessary to get raw bytes?
198
199
  value = rb_str_encode(value, bytes, 0, Qnil);
199
200
  }
200
201
 
@@ -227,11 +228,13 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
227
228
  ret.uint64_val = NUM2ULL(value);
228
229
  break;
229
230
  default:
230
- break;
231
+ rb_raise(cTypeError, "Convert_RubyToUpb(): Unexpected type %d",
232
+ (int)type_info.type);
231
233
  }
232
234
  break;
233
235
  default:
234
- break;
236
+ rb_raise(cTypeError,
237
+ "Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
235
238
  }
236
239
 
237
240
  return ret;
@@ -255,7 +258,7 @@ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
255
258
  case kUpb_CType_UInt64:
256
259
  return ULL2NUM(upb_val.int64_val);
257
260
  case kUpb_CType_Enum: {
258
- const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber(
261
+ const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
259
262
  type_info.def.enumdef, upb_val.int32_val);
260
263
  if (ev) {
261
264
  return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
@@ -312,50 +315,28 @@ upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
312
315
 
313
316
  bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
314
317
  TypeInfo type_info) {
315
- switch (type_info.type) {
316
- case kUpb_CType_Bool:
317
- return memcmp(&val1, &val2, 1) == 0;
318
- case kUpb_CType_Float:
319
- case kUpb_CType_Int32:
320
- case kUpb_CType_UInt32:
321
- case kUpb_CType_Enum:
322
- return memcmp(&val1, &val2, 4) == 0;
323
- case kUpb_CType_Double:
324
- case kUpb_CType_Int64:
325
- case kUpb_CType_UInt64:
326
- return memcmp(&val1, &val2, 8) == 0;
327
- case kUpb_CType_String:
328
- case kUpb_CType_Bytes:
329
- return val1.str_val.size == val2.str_val.size &&
330
- memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
331
- 0;
332
- case kUpb_CType_Message:
333
- return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef);
334
- default:
335
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
318
+ upb_Status status;
319
+ upb_Status_Clear(&status);
320
+ bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
321
+ type_info.def.msgdef, &status);
322
+ if (upb_Status_IsOk(&status)) {
323
+ return return_value;
324
+ } else {
325
+ rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
326
+ upb_Status_ErrorMessage(&status));
336
327
  }
337
328
  }
338
329
 
339
330
  uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
340
331
  uint64_t seed) {
341
- switch (type_info.type) {
342
- case kUpb_CType_Bool:
343
- return _upb_Hash(&val, 1, seed);
344
- case kUpb_CType_Float:
345
- case kUpb_CType_Int32:
346
- case kUpb_CType_UInt32:
347
- case kUpb_CType_Enum:
348
- return _upb_Hash(&val, 4, seed);
349
- case kUpb_CType_Double:
350
- case kUpb_CType_Int64:
351
- case kUpb_CType_UInt64:
352
- return _upb_Hash(&val, 8, seed);
353
- case kUpb_CType_String:
354
- case kUpb_CType_Bytes:
355
- return _upb_Hash(val.str_val.data, val.str_val.size, seed);
356
- case kUpb_CType_Message:
357
- return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
358
- default:
359
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
332
+ upb_Status status;
333
+ upb_Status_Clear(&status);
334
+ uint64_t return_value = shared_Msgval_GetHash(
335
+ val, type_info.type, type_info.def.msgdef, seed, &status);
336
+ if (upb_Status_IsOk(&status)) {
337
+ return return_value;
338
+ } else {
339
+ rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
340
+ upb_Status_ErrorMessage(&status));
360
341
  }
361
342
  }
@@ -1,38 +1,13 @@
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_CONVERT_H_
32
9
  #define RUBY_PROTOBUF_CONVERT_H_
33
10
 
34
- #include <ruby/ruby.h>
35
-
36
11
  #include "protobuf.h"
37
12
  #include "ruby-upb.h"
38
13