google-protobuf 3.23.3 → 4.27.1
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.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +28 -72
- data/ext/google/protobuf_c/convert.h +3 -28
- data/ext/google/protobuf_c/defs.c +512 -60
- data/ext/google/protobuf_c/defs.h +3 -28
- data/ext/google/protobuf_c/extconf.rb +2 -1
- data/ext/google/protobuf_c/glue.c +72 -0
- data/ext/google/protobuf_c/map.c +28 -36
- data/ext/google/protobuf_c/map.h +6 -28
- data/ext/google/protobuf_c/message.c +88 -143
- data/ext/google/protobuf_c/message.h +10 -32
- data/ext/google/protobuf_c/protobuf.c +49 -175
- data/ext/google/protobuf_c/protobuf.h +24 -32
- data/ext/google/protobuf_c/repeated_field.c +23 -33
- data/ext/google/protobuf_c/repeated_field.h +6 -28
- data/ext/google/protobuf_c/ruby-upb.c +13046 -10690
- data/ext/google/protobuf_c/ruby-upb.h +8405 -5836
- data/ext/google/protobuf_c/shared_convert.c +69 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +37 -0
- data/ext/google/protobuf_c/shared_message.h +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
- data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
- data/lib/google/protobuf/any_pb.rb +1 -22
- data/lib/google/protobuf/api_pb.rb +1 -24
- data/lib/google/protobuf/descriptor_pb.rb +14 -23
- data/lib/google/protobuf/duration_pb.rb +1 -22
- data/lib/google/protobuf/empty_pb.rb +1 -22
- data/lib/google/protobuf/ffi/descriptor.rb +166 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +173 -0
- data/lib/google/protobuf/ffi/ffi.rb +210 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +330 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +49 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +289 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +409 -0
- data/lib/google/protobuf/ffi/message.rb +659 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +97 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +385 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
- data/lib/google/protobuf/field_mask_pb.rb +1 -22
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +3 -26
- data/lib/google/protobuf/plugin_pb.rb +2 -24
- data/lib/google/protobuf/repeated_field.rb +7 -31
- data/lib/google/protobuf/source_context_pb.rb +1 -22
- data/lib/google/protobuf/struct_pb.rb +1 -22
- data/lib/google/protobuf/timestamp_pb.rb +1 -22
- data/lib/google/protobuf/type_pb.rb +1 -24
- data/lib/google/protobuf/well_known_types.rb +5 -34
- data/lib/google/protobuf/wrappers_pb.rb +1 -22
- data/lib/google/protobuf.rb +27 -45
- data/lib/google/protobuf_ffi.rb +51 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +89 -8
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
@@ -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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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_DEFS_H_
|
32
9
|
#define RUBY_PROTOBUF_DEFS_H_
|
33
10
|
|
34
|
-
#include <ruby/ruby.h>
|
35
|
-
|
36
11
|
#include "protobuf.h"
|
37
12
|
#include "ruby-upb.h"
|
38
13
|
|
@@ -22,6 +22,7 @@ $INCFLAGS += " -I$(srcdir)/third_party/utf8_range"
|
|
22
22
|
|
23
23
|
$srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
|
24
24
|
"repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
|
25
|
-
"
|
25
|
+
"utf8_range.c", "shared_convert.c",
|
26
|
+
"shared_message.c"]
|
26
27
|
|
27
28
|
create_makefile(ext_name)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2023 Google Inc. All rights reserved.
|
3
|
+
//
|
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
|
7
|
+
|
8
|
+
// -----------------------------------------------------------------------------
|
9
|
+
// Exposing inlined UPB functions. Strictly free of dependencies on
|
10
|
+
// Ruby interpreter internals.
|
11
|
+
|
12
|
+
#include "ruby-upb.h"
|
13
|
+
|
14
|
+
upb_Arena* Arena_create() { return upb_Arena_Init(NULL, 0, &upb_alloc_global); }
|
15
|
+
|
16
|
+
google_protobuf_FileDescriptorProto* FileDescriptorProto_parse(
|
17
|
+
const char* serialized_file_proto, size_t length, upb_Arena* arena) {
|
18
|
+
return google_protobuf_FileDescriptorProto_parse(serialized_file_proto,
|
19
|
+
length, arena);
|
20
|
+
}
|
21
|
+
|
22
|
+
char* EnumDescriptor_serialized_options(const upb_EnumDef* enumdef,
|
23
|
+
size_t* size, upb_Arena* arena) {
|
24
|
+
const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(enumdef);
|
25
|
+
char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, size);
|
26
|
+
return serialized;
|
27
|
+
}
|
28
|
+
|
29
|
+
char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
|
30
|
+
size_t* size, upb_Arena* arena) {
|
31
|
+
const google_protobuf_FileOptions* opts = upb_FileDef_Options(filedef);
|
32
|
+
char* serialized = google_protobuf_FileOptions_serialize(opts, arena, size);
|
33
|
+
return serialized;
|
34
|
+
}
|
35
|
+
|
36
|
+
char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
|
37
|
+
upb_Arena* arena) {
|
38
|
+
const google_protobuf_MessageOptions* opts = upb_MessageDef_Options(msgdef);
|
39
|
+
char* serialized =
|
40
|
+
google_protobuf_MessageOptions_serialize(opts, arena, size);
|
41
|
+
return serialized;
|
42
|
+
}
|
43
|
+
|
44
|
+
char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
|
45
|
+
size_t* size, upb_Arena* arena) {
|
46
|
+
const google_protobuf_OneofOptions* opts = upb_OneofDef_Options(oneofdef);
|
47
|
+
char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, size);
|
48
|
+
return serialized;
|
49
|
+
}
|
50
|
+
|
51
|
+
char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
|
52
|
+
size_t* size, upb_Arena* arena) {
|
53
|
+
const google_protobuf_FieldOptions* opts = upb_FieldDef_Options(fielddef);
|
54
|
+
char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, size);
|
55
|
+
return serialized;
|
56
|
+
}
|
57
|
+
|
58
|
+
char* ServiceDescriptor_serialized_options(const upb_ServiceDef* servicedef,
|
59
|
+
size_t* size, upb_Arena* arena) {
|
60
|
+
const google_protobuf_ServiceOptions* opts =
|
61
|
+
upb_ServiceDef_Options(servicedef);
|
62
|
+
char* serialized =
|
63
|
+
google_protobuf_ServiceOptions_serialize(opts, arena, size);
|
64
|
+
return serialized;
|
65
|
+
}
|
66
|
+
|
67
|
+
char* MethodDescriptor_serialized_options(const upb_MethodDef* methoddef,
|
68
|
+
size_t* size, upb_Arena* arena) {
|
69
|
+
const google_protobuf_MethodOptions* opts = upb_MethodDef_Options(methoddef);
|
70
|
+
char* serialized = google_protobuf_MethodOptions_serialize(opts, arena, size);
|
71
|
+
return serialized;
|
72
|
+
}
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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 "convert.h"
|
32
9
|
#include "defs.h"
|
@@ -61,9 +38,11 @@ static void Map_mark(void* _self) {
|
|
61
38
|
rb_gc_mark(self->arena);
|
62
39
|
}
|
63
40
|
|
41
|
+
static size_t Map_memsize(const void* _self) { return sizeof(Map); }
|
42
|
+
|
64
43
|
const rb_data_type_t Map_type = {
|
65
44
|
"Google::Protobuf::Map",
|
66
|
-
{Map_mark, RUBY_DEFAULT_FREE,
|
45
|
+
{Map_mark, RUBY_DEFAULT_FREE, Map_memsize},
|
67
46
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
68
47
|
};
|
69
48
|
|
@@ -93,7 +72,6 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
|
|
93
72
|
if (val == Qnil) {
|
94
73
|
val = Map_alloc(cMap);
|
95
74
|
Map* self;
|
96
|
-
ObjectCache_Add(map, val);
|
97
75
|
TypedData_Get_Struct(val, Map, &Map_type, self);
|
98
76
|
self->map = map;
|
99
77
|
self->arena = arena;
|
@@ -103,6 +81,7 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
|
|
103
81
|
const upb_MessageDef* val_m = self->value_type_info.def.msgdef;
|
104
82
|
self->value_type_class = Descriptor_DefToClass(val_m);
|
105
83
|
}
|
84
|
+
return ObjectCache_TryAdd(map, val);
|
106
85
|
}
|
107
86
|
|
108
87
|
return val;
|
@@ -235,7 +214,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
235
214
|
Map* self = ruby_to_Map(_self);
|
236
215
|
Map* other = ruby_to_Map(hashmap);
|
237
216
|
upb_Arena* arena = Arena_get(self->arena);
|
238
|
-
|
217
|
+
upb_Map* self_map = Map_GetMutable(_self);
|
239
218
|
|
240
219
|
Arena_fuse(other->arena, arena);
|
241
220
|
|
@@ -248,7 +227,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
248
227
|
size_t iter = kUpb_Map_Begin;
|
249
228
|
upb_MessageValue key, val;
|
250
229
|
while (upb_Map_Next(other->map, &key, &val, &iter)) {
|
251
|
-
upb_Map_Set(
|
230
|
+
upb_Map_Set(self_map, key, val, arena);
|
252
231
|
}
|
253
232
|
} else {
|
254
233
|
rb_raise(rb_eArgError, "Unknown type merging into Map");
|
@@ -319,7 +298,9 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
|
|
319
298
|
|
320
299
|
self->map = upb_Map_New(Arena_get(self->arena), self->key_type,
|
321
300
|
self->value_type_info.type);
|
322
|
-
|
301
|
+
VALUE stored = ObjectCache_TryAdd(self->map, _self);
|
302
|
+
(void)stored;
|
303
|
+
PBRUBY_ASSERT(stored == _self);
|
323
304
|
|
324
305
|
if (init_arg != Qnil) {
|
325
306
|
Map_merge_into_self(_self, init_arg);
|
@@ -465,7 +446,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
|
|
465
446
|
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
|
466
447
|
upb_MessageValue val_upb;
|
467
448
|
|
468
|
-
if (upb_Map_Delete(
|
449
|
+
if (upb_Map_Delete(Map_GetMutable(_self), key_upb, &val_upb)) {
|
469
450
|
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
|
470
451
|
} else {
|
471
452
|
return Qnil;
|
@@ -584,11 +565,22 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
|
|
584
565
|
* Freezes the message object. We have to intercept this so we can pin the
|
585
566
|
* Ruby object into memory so we don't forget it's frozen.
|
586
567
|
*/
|
587
|
-
|
568
|
+
VALUE Map_freeze(VALUE _self) {
|
588
569
|
Map* self = ruby_to_Map(_self);
|
589
|
-
|
590
|
-
|
591
|
-
|
570
|
+
|
571
|
+
if (RB_OBJ_FROZEN(_self)) return _self;
|
572
|
+
Arena_Pin(self->arena, _self);
|
573
|
+
RB_OBJ_FREEZE(_self);
|
574
|
+
|
575
|
+
if (self->value_type_info.type == kUpb_CType_Message) {
|
576
|
+
size_t iter = kUpb_Map_Begin;
|
577
|
+
upb_MessageValue key, val;
|
578
|
+
|
579
|
+
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
580
|
+
VALUE val_val =
|
581
|
+
Convert_UpbToRuby(val, self->value_type_info, self->arena);
|
582
|
+
Message_freeze(val_val);
|
583
|
+
}
|
592
584
|
}
|
593
585
|
return _self;
|
594
586
|
}
|
data/ext/google/protobuf_c/map.h
CHANGED
@@ -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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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_
|
33
10
|
|
34
|
-
#include <ruby/ruby.h>
|
35
|
-
|
36
11
|
#include "protobuf.h"
|
37
12
|
#include "ruby-upb.h"
|
38
13
|
|
@@ -63,4 +38,7 @@ extern VALUE cMap;
|
|
63
38
|
// Call at startup to register all types in this module.
|
64
39
|
void Map_register(VALUE module);
|
65
40
|
|
41
|
+
// Recursively freeze map
|
42
|
+
VALUE Map_freeze(VALUE _self);
|
43
|
+
|
66
44
|
#endif // RUBY_PROTOBUF_MAP_H_
|