google-protobuf 3.19.1 → 4.30.2

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +153 -166
  4. data/ext/google/protobuf_c/convert.h +15 -37
  5. data/ext/google/protobuf_c/defs.c +867 -251
  6. data/ext/google/protobuf_c/defs.h +22 -47
  7. data/ext/google/protobuf_c/extconf.rb +25 -5
  8. data/ext/google/protobuf_c/glue.c +135 -0
  9. data/ext/google/protobuf_c/map.c +182 -145
  10. data/ext/google/protobuf_c/map.h +16 -35
  11. data/ext/google/protobuf_c/message.c +534 -437
  12. data/ext/google/protobuf_c/message.h +30 -49
  13. data/ext/google/protobuf_c/protobuf.c +125 -238
  14. data/ext/google/protobuf_c/protobuf.h +40 -49
  15. data/ext/google/protobuf_c/repeated_field.c +152 -120
  16. data/ext/google/protobuf_c/repeated_field.h +16 -34
  17. data/ext/google/protobuf_c/ruby-upb.c +15827 -7228
  18. data/ext/google/protobuf_c/ruby-upb.h +15075 -3866
  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 +22 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
  25. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +22 -0
  26. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
  27. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
  28. data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
  29. data/lib/google/protobuf/any_pb.rb +6 -8
  30. data/lib/google/protobuf/api_pb.rb +6 -26
  31. data/lib/google/protobuf/descriptor_pb.rb +24 -225
  32. data/lib/google/protobuf/duration_pb.rb +6 -8
  33. data/lib/google/protobuf/empty_pb.rb +6 -6
  34. data/lib/google/protobuf/ffi/descriptor.rb +175 -0
  35. data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
  36. data/lib/google/protobuf/ffi/enum_descriptor.rb +183 -0
  37. data/lib/google/protobuf/ffi/ffi.rb +214 -0
  38. data/lib/google/protobuf/ffi/field_descriptor.rb +340 -0
  39. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  40. data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
  41. data/lib/google/protobuf/ffi/internal/convert.rb +292 -0
  42. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  43. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  44. data/lib/google/protobuf/ffi/map.rb +433 -0
  45. data/lib/google/protobuf/ffi/message.rb +783 -0
  46. data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
  47. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  48. data/lib/google/protobuf/ffi/oneof_descriptor.rb +107 -0
  49. data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
  50. data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
  51. data/lib/google/protobuf/field_mask_pb.rb +6 -7
  52. data/lib/google/protobuf/internal/object_cache.rb +99 -0
  53. data/lib/google/protobuf/message_exts.rb +10 -28
  54. data/lib/google/protobuf/plugin_pb.rb +25 -0
  55. data/lib/google/protobuf/repeated_field.rb +22 -33
  56. data/lib/google/protobuf/source_context_pb.rb +6 -7
  57. data/lib/google/protobuf/struct_pb.rb +6 -23
  58. data/lib/google/protobuf/timestamp_pb.rb +6 -8
  59. data/lib/google/protobuf/type_pb.rb +6 -71
  60. data/lib/google/protobuf/well_known_types.rb +16 -40
  61. data/lib/google/protobuf/wrappers_pb.rb +6 -31
  62. data/lib/google/protobuf.rb +32 -50
  63. data/lib/google/protobuf_ffi.rb +52 -0
  64. data/lib/google/protobuf_native.rb +19 -0
  65. data/lib/google/tasks/ffi.rake +100 -0
  66. metadata +97 -20
  67. data/lib/google/protobuf/descriptor_dsl.rb +0 -458
  68. data/tests/basic.rb +0 -640
  69. data/tests/generated_code_test.rb +0 -23
  70. data/tests/stress.rb +0 -38
@@ -1,70 +1,54 @@
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__
33
10
 
34
- #include <ruby/ruby.h>
35
- #include <ruby/vm.h>
11
+ // Ruby 3+ defines NDEBUG itself, see: https://bugs.ruby-lang.org/issues/18777
12
+ #ifdef NDEBUG
13
+ #include <ruby.h>
14
+ #else
15
+ #include <ruby.h>
16
+ #undef NDEBUG
17
+ #endif
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
+ #include <assert.h> // Must be included after the NDEBUG logic above.
36
26
  #include <ruby/encoding.h>
27
+ #include <ruby/vm.h>
37
28
 
38
- #include "ruby-upb.h"
39
29
  #include "defs.h"
30
+ #include "ruby-upb.h"
40
31
 
41
32
  // These operate on a map field (i.e., a repeated field of submessages whose
42
33
  // submessage type is a map-entry msgdef).
43
- const upb_fielddef* map_field_key(const upb_fielddef* field);
44
- const upb_fielddef* map_field_value(const upb_fielddef* field);
34
+ const upb_FieldDef* map_field_key(const upb_FieldDef* field);
35
+ const upb_FieldDef* map_field_value(const upb_FieldDef* field);
45
36
 
46
37
  // -----------------------------------------------------------------------------
47
38
  // Arena
48
39
  // -----------------------------------------------------------------------------
49
40
 
50
- // A Ruby object that wraps an underlying upb_arena. Any objects that are
41
+ // A Ruby object that wraps an underlying upb_Arena. Any objects that are
51
42
  // allocated from this arena should reference the Arena in rb_gc_mark(), to
52
43
  // ensure that the object's underlying memory outlives any Ruby object that can
53
44
  // reach it.
54
45
 
55
46
  VALUE Arena_new();
56
- upb_arena *Arena_get(VALUE arena);
47
+ upb_Arena* Arena_get(VALUE arena);
57
48
 
58
49
  // Fuses this arena to another, throwing a Ruby exception if this is not
59
50
  // possible.
60
- void Arena_fuse(VALUE arena, upb_arena *other);
61
-
62
- // Pins this Ruby object to the lifetime of this arena, so that as long as the
63
- // arena is alive this object will not be collected.
64
- //
65
- // We use this to guarantee that the "frozen" bit on the object will be
66
- // remembered, even if the user drops their reference to this precise object.
67
- void Arena_Pin(VALUE arena, VALUE obj);
51
+ void Arena_fuse(VALUE arena, upb_Arena* other);
68
52
 
69
53
  // -----------------------------------------------------------------------------
70
54
  // ObjectCache
@@ -76,10 +60,9 @@ void Arena_Pin(VALUE arena, VALUE obj);
76
60
  // being collected (though in Ruby <2.7 is it effectively strong, due to
77
61
  // implementation limitations).
78
62
 
79
- // Adds an entry to the cache. The "arena" parameter must give the arena that
80
- // "key" was allocated from. In Ruby <2.7.0, it will be used to remove the key
81
- // from the cache when the arena is destroyed.
82
- void ObjectCache_Add(const void* key, VALUE val);
63
+ // Tries to add a new entry to the cache, returning the newly installed value or
64
+ // the pre-existing entry.
65
+ VALUE ObjectCache_TryAdd(const void* key, VALUE val);
83
66
 
84
67
  // Returns the cached object for this key, if any. Otherwise returns Qnil.
85
68
  VALUE ObjectCache_Get(const void* key);
@@ -93,10 +76,11 @@ typedef struct StringBuilder StringBuilder;
93
76
 
94
77
  StringBuilder* StringBuilder_New();
95
78
  void StringBuilder_Free(StringBuilder* b);
96
- void StringBuilder_Printf(StringBuilder* b, const char *fmt, ...);
79
+ void StringBuilder_Printf(StringBuilder* b, const char* fmt, ...);
97
80
  VALUE StringBuilder_ToRubyString(StringBuilder* b);
98
81
 
99
- void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, TypeInfo info);
82
+ void StringBuilder_PrintMsgval(StringBuilder* b, upb_MessageValue val,
83
+ TypeInfo info);
100
84
 
101
85
  // -----------------------------------------------------------------------------
102
86
  // Utilities.
@@ -105,11 +89,18 @@ void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, TypeInfo info);
105
89
  extern VALUE cTypeError;
106
90
 
107
91
  #ifdef NDEBUG
108
- #define PBRUBY_ASSERT(expr) do {} while (false && (expr))
92
+ #define PBRUBY_ASSERT(expr) \
93
+ do { \
94
+ } while (false && (expr))
109
95
  #else
110
- #define PBRUBY_ASSERT(expr) assert(expr)
96
+ #define PBRUBY_ASSERT(expr) \
97
+ if (!(expr)) \
98
+ rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr)
111
99
  #endif
112
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
+
113
104
  #define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
114
105
 
115
106
  #define UPB_UNUSED(var) (void)var