google-protobuf 3.19.4 → 3.23.3

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +128 -115
  3. data/ext/google/protobuf_c/convert.h +12 -9
  4. data/ext/google/protobuf_c/defs.c +215 -209
  5. data/ext/google/protobuf_c/defs.h +19 -19
  6. data/ext/google/protobuf_c/extconf.rb +12 -5
  7. data/ext/google/protobuf_c/map.c +102 -109
  8. data/ext/google/protobuf_c/map.h +7 -8
  9. data/ext/google/protobuf_c/message.c +446 -341
  10. data/ext/google/protobuf_c/message.h +22 -19
  11. data/ext/google/protobuf_c/protobuf.c +71 -59
  12. data/ext/google/protobuf_c/protobuf.h +13 -10
  13. data/ext/google/protobuf_c/repeated_field.c +82 -84
  14. data/ext/google/protobuf_c/repeated_field.h +6 -6
  15. data/ext/google/protobuf_c/ruby-upb.c +11651 -6848
  16. data/ext/google/protobuf_c/ruby-upb.h +10715 -3639
  17. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
  18. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  19. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  20. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  21. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
  22. data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
  23. data/lib/google/protobuf/any_pb.rb +24 -5
  24. data/lib/google/protobuf/api_pb.rb +26 -23
  25. data/lib/google/protobuf/descriptor_dsl.rb +8 -1
  26. data/lib/google/protobuf/descriptor_pb.rb +32 -225
  27. data/lib/google/protobuf/duration_pb.rb +24 -5
  28. data/lib/google/protobuf/empty_pb.rb +24 -3
  29. data/lib/google/protobuf/field_mask_pb.rb +24 -4
  30. data/lib/google/protobuf/message_exts.rb +7 -2
  31. data/lib/google/protobuf/plugin_pb.rb +47 -0
  32. data/lib/google/protobuf/repeated_field.rb +15 -2
  33. data/lib/google/protobuf/source_context_pb.rb +24 -4
  34. data/lib/google/protobuf/struct_pb.rb +24 -20
  35. data/lib/google/protobuf/timestamp_pb.rb +24 -5
  36. data/lib/google/protobuf/type_pb.rb +26 -68
  37. data/lib/google/protobuf/well_known_types.rb +11 -6
  38. data/lib/google/protobuf/wrappers_pb.rb +24 -28
  39. data/lib/google/protobuf.rb +4 -4
  40. metadata +13 -13
  41. data/tests/basic.rb +0 -648
  42. data/tests/generated_code_test.rb +0 -23
  43. data/tests/stress.rb +0 -38
@@ -40,9 +40,9 @@
40
40
  // TypeInfo
41
41
  // -----------------------------------------------------------------------------
42
42
 
43
- // This bundles a upb_fieldtype_t and msgdef/enumdef when appropriate. This is
43
+ // This bundles a upb_CType and msgdef/enumdef when appropriate. This is
44
44
  // convenient for functions that need type information but cannot necessarily
45
- // assume a upb_fielddef will be available.
45
+ // assume a upb_FieldDef will be available.
46
46
  //
47
47
  // For example, Google::Protobuf::Map and Google::Protobuf::RepeatedField can
48
48
  // be constructed with type information alone:
@@ -51,21 +51,21 @@
51
51
  // Google::Protobuf::RepeatedField.new(:message, FooMessage)
52
52
 
53
53
  typedef struct {
54
- upb_fieldtype_t type;
54
+ upb_CType type;
55
55
  union {
56
- const upb_msgdef* msgdef; // When type == UPB_TYPE_MESSAGE
57
- const upb_enumdef* enumdef; // When type == UPB_TYPE_ENUM
56
+ const upb_MessageDef* msgdef; // When type == kUpb_CType_Message
57
+ const upb_EnumDef* enumdef; // When type == kUpb_CType_Enum
58
58
  } def;
59
59
  } TypeInfo;
60
60
 
61
- static inline TypeInfo TypeInfo_get(const upb_fielddef *f) {
62
- TypeInfo ret = {upb_fielddef_type(f), {NULL}};
61
+ static inline TypeInfo TypeInfo_get(const upb_FieldDef* f) {
62
+ TypeInfo ret = {upb_FieldDef_CType(f), {NULL}};
63
63
  switch (ret.type) {
64
- case UPB_TYPE_MESSAGE:
65
- ret.def.msgdef = upb_fielddef_msgsubdef(f);
64
+ case kUpb_CType_Message:
65
+ ret.def.msgdef = upb_FieldDef_MessageSubDef(f);
66
66
  break;
67
- case UPB_TYPE_ENUM:
68
- ret.def.enumdef = upb_fielddef_enumsubdef(f);
67
+ case kUpb_CType_Enum:
68
+ ret.def.enumdef = upb_FieldDef_EnumSubDef(f);
69
69
  break;
70
70
  default:
71
71
  break;
@@ -76,9 +76,9 @@ static inline TypeInfo TypeInfo_get(const upb_fielddef *f) {
76
76
  TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg,
77
77
  VALUE* type_class, VALUE* init_arg);
78
78
 
79
- static inline TypeInfo TypeInfo_from_type(upb_fieldtype_t type) {
79
+ static inline TypeInfo TypeInfo_from_type(upb_CType type) {
80
80
  TypeInfo ret = {type};
81
- assert(type != UPB_TYPE_MESSAGE && type != UPB_TYPE_ENUM);
81
+ assert(type != kUpb_CType_Message && type != kUpb_CType_Enum);
82
82
  return ret;
83
83
  }
84
84
 
@@ -86,17 +86,17 @@ static inline TypeInfo TypeInfo_from_type(upb_fieldtype_t type) {
86
86
  // Other utilities
87
87
  // -----------------------------------------------------------------------------
88
88
 
89
- VALUE Descriptor_DefToClass(const upb_msgdef *m);
89
+ VALUE Descriptor_DefToClass(const upb_MessageDef* m);
90
90
 
91
91
  // Returns the underlying msgdef, enumdef, or symtab (respectively) for the
92
92
  // given Descriptor, EnumDescriptor, or DescriptorPool Ruby object.
93
- const upb_enumdef *EnumDescriptor_GetEnumDef(VALUE enum_desc_rb);
94
- const upb_symtab *DescriptorPool_GetSymtab(VALUE desc_pool_rb);
95
- const upb_msgdef *Descriptor_GetMsgDef(VALUE desc_rb);
93
+ const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb);
94
+ const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb);
95
+ const upb_MessageDef* Descriptor_GetMsgDef(VALUE desc_rb);
96
96
 
97
97
  // Returns a upb field type for the given Ruby symbol
98
- // (eg. :float => UPB_TYPE_FLOAT).
99
- upb_fieldtype_t ruby_to_fieldtype(VALUE type);
98
+ // (eg. :float => kUpb_CType_Float).
99
+ upb_CType ruby_to_fieldtype(VALUE type);
100
100
 
101
101
  // The singleton generated pool (a DescriptorPool object).
102
102
  extern VALUE generated_pool;
@@ -2,19 +2,26 @@
2
2
 
3
3
  require 'mkmf'
4
4
 
5
- if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
5
+ ext_name = "google/protobuf_c"
6
+
7
+ dir_config(ext_name)
8
+
9
+ if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /freebsd/
6
10
  $CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
7
11
  else
8
12
  $CFLAGS += " -std=gnu99 -O3 -DNDEBUG"
9
13
  end
10
14
 
11
-
12
15
  if RUBY_PLATFORM =~ /linux/
13
16
  # Instruct the linker to point memcpy calls at our __wrap_memcpy wrapper.
14
17
  $LDFLAGS += " -Wl,-wrap,memcpy"
15
18
  end
16
19
 
17
- $objs = ["protobuf.o", "convert.o", "defs.o", "message.o",
18
- "repeated_field.o", "map.o", "ruby-upb.o", "wrap_memcpy.o"]
20
+ $VPATH << "$(srcdir)/third_party/utf8_range"
21
+ $INCFLAGS += " -I$(srcdir)/third_party/utf8_range"
22
+
23
+ $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
24
+ "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
25
+ "naive.c", "range2-neon.c", "range2-sse.c"]
19
26
 
20
- create_makefile("google/protobuf_c")
27
+ create_makefile(ext_name)
@@ -34,7 +34,7 @@
34
34
  #include "protobuf.h"
35
35
 
36
36
  // -----------------------------------------------------------------------------
37
- // Basic map operations on top of upb_map.
37
+ // Basic map operations on top of upb_Map.
38
38
  //
39
39
  // Note that we roll our own `Map` container here because, as for
40
40
  // `RepeatedField`, we want a strongly-typed container. This is so that any user
@@ -48,8 +48,8 @@
48
48
  // -----------------------------------------------------------------------------
49
49
 
50
50
  typedef struct {
51
- const upb_map *map; // Can convert to mutable when non-frozen.
52
- upb_fieldtype_t key_type;
51
+ const upb_Map* map; // Can convert to mutable when non-frozen.
52
+ upb_CType key_type;
53
53
  TypeInfo value_type_info;
54
54
  VALUE value_type_class;
55
55
  VALUE arena;
@@ -62,9 +62,9 @@ static void Map_mark(void* _self) {
62
62
  }
63
63
 
64
64
  const rb_data_type_t Map_type = {
65
- "Google::Protobuf::Map",
66
- { Map_mark, RUBY_DEFAULT_FREE, NULL },
67
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
65
+ "Google::Protobuf::Map",
66
+ {Map_mark, RUBY_DEFAULT_FREE, NULL},
67
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
68
68
  };
69
69
 
70
70
  VALUE cMap;
@@ -84,8 +84,8 @@ static VALUE Map_alloc(VALUE klass) {
84
84
  return TypedData_Wrap_Struct(klass, &Map_type, self);
85
85
  }
86
86
 
87
- VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type,
88
- TypeInfo value_type, VALUE arena) {
87
+ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
88
+ VALUE arena) {
89
89
  PBRUBY_ASSERT(map);
90
90
 
91
91
  VALUE val = ObjectCache_Get(map);
@@ -99,8 +99,8 @@ VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type,
99
99
  self->arena = arena;
100
100
  self->key_type = key_type;
101
101
  self->value_type_info = value_type;
102
- if (self->value_type_info.type == UPB_TYPE_MESSAGE) {
103
- const upb_msgdef *val_m = self->value_type_info.def.msgdef;
102
+ if (self->value_type_info.type == kUpb_CType_Message) {
103
+ const upb_MessageDef* val_m = self->value_type_info.def.msgdef;
104
104
  self->value_type_class = Descriptor_DefToClass(val_m);
105
105
  }
106
106
  }
@@ -108,9 +108,9 @@ VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type,
108
108
  return val;
109
109
  }
110
110
 
111
- static VALUE Map_new_this_type(Map *from) {
111
+ static VALUE Map_new_this_type(Map* from) {
112
112
  VALUE arena_rb = Arena_new();
113
- upb_map* map = upb_map_new(Arena_get(arena_rb), from->key_type,
113
+ upb_Map* map = upb_Map_New(Arena_get(arena_rb), from->key_type,
114
114
  from->value_type_info.type);
115
115
  VALUE ret =
116
116
  Map_GetRubyWrapper(map, from->key_type, from->value_type_info, arena_rb);
@@ -125,22 +125,21 @@ static TypeInfo Map_keyinfo(Map* self) {
125
125
  return ret;
126
126
  }
127
127
 
128
- static upb_map *Map_GetMutable(VALUE _self) {
128
+ static upb_Map* Map_GetMutable(VALUE _self) {
129
129
  rb_check_frozen(_self);
130
- return (upb_map*)ruby_to_Map(_self)->map;
130
+ return (upb_Map*)ruby_to_Map(_self)->map;
131
131
  }
132
132
 
133
- VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type,
133
+ VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type,
134
134
  TypeInfo val_info) {
135
135
  VALUE hash = rb_hash_new();
136
- size_t iter = UPB_MAP_BEGIN;
137
136
  TypeInfo key_info = TypeInfo_from_type(key_type);
138
137
 
139
138
  if (!map) return hash;
140
139
 
141
- while (upb_mapiter_next(map, &iter)) {
142
- upb_msgval key = upb_mapiter_key(map, iter);
143
- upb_msgval val = upb_mapiter_value(map, iter);
140
+ size_t iter = kUpb_Map_Begin;
141
+ upb_MessageValue key, val;
142
+ while (upb_Map_Next(map, &key, &val, &iter)) {
144
143
  VALUE key_val = Convert_UpbToRuby(key, key_info, Qnil);
145
144
  VALUE val_val = Scalar_CreateHash(val, val_info);
146
145
  rb_hash_aset(hash, key_val, val_val);
@@ -152,25 +151,25 @@ VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type,
152
151
  VALUE Map_deep_copy(VALUE obj) {
153
152
  Map* self = ruby_to_Map(obj);
154
153
  VALUE new_arena_rb = Arena_new();
155
- upb_arena *arena = Arena_get(new_arena_rb);
156
- upb_map* new_map =
157
- upb_map_new(arena, self->key_type, self->value_type_info.type);
158
- size_t iter = UPB_MAP_BEGIN;
159
- while (upb_mapiter_next(self->map, &iter)) {
160
- upb_msgval key = upb_mapiter_key(self->map, iter);
161
- upb_msgval val = upb_mapiter_value(self->map, iter);
162
- upb_msgval val_copy = Msgval_DeepCopy(val, self->value_type_info, arena);
163
- upb_map_set(new_map, key, val_copy, arena);
154
+ upb_Arena* arena = Arena_get(new_arena_rb);
155
+ upb_Map* new_map =
156
+ upb_Map_New(arena, self->key_type, self->value_type_info.type);
157
+ size_t iter = kUpb_Map_Begin;
158
+ upb_MessageValue key, val;
159
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
160
+ upb_MessageValue val_copy =
161
+ Msgval_DeepCopy(val, self->value_type_info, arena);
162
+ upb_Map_Set(new_map, key, val_copy, arena);
164
163
  }
165
164
 
166
165
  return Map_GetRubyWrapper(new_map, self->key_type, self->value_type_info,
167
166
  new_arena_rb);
168
167
  }
169
168
 
170
- const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field,
171
- upb_arena* arena) {
172
- const upb_fielddef* key_field = map_field_key(field);
173
- const upb_fielddef* value_field = map_field_value(field);
169
+ const upb_Map* Map_GetUpbMap(VALUE val, const upb_FieldDef* field,
170
+ upb_Arena* arena) {
171
+ const upb_FieldDef* key_field = map_field_key(field);
172
+ const upb_FieldDef* value_field = map_field_value(field);
174
173
  TypeInfo value_type_info = TypeInfo_get(value_field);
175
174
  Map* self;
176
175
 
@@ -180,7 +179,7 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field,
180
179
  }
181
180
 
182
181
  self = ruby_to_Map(val);
183
- if (self->key_type != upb_fielddef_type(key_field)) {
182
+ if (self->key_type != upb_FieldDef_CType(key_field)) {
184
183
  rb_raise(cTypeError, "Map key type does not match field's key type");
185
184
  }
186
185
  if (self->value_type_info.type != value_type_info.type) {
@@ -194,16 +193,15 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field,
194
193
  return self->map;
195
194
  }
196
195
 
197
- void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type,
196
+ void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type,
198
197
  TypeInfo val_type) {
199
198
  bool first = true;
200
199
  TypeInfo key_type_info = {key_type};
201
200
  StringBuilder_Printf(b, "{");
202
201
  if (map) {
203
- size_t iter = UPB_MAP_BEGIN;
204
- while (upb_mapiter_next(map, &iter)) {
205
- upb_msgval key = upb_mapiter_key(map, iter);
206
- upb_msgval val = upb_mapiter_value(map, iter);
202
+ size_t iter = kUpb_Map_Begin;
203
+ upb_MessageValue key, val;
204
+ while (upb_Map_Next(map, &key, &val, &iter)) {
207
205
  if (first) {
208
206
  first = false;
209
207
  } else {
@@ -219,10 +217,12 @@ void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type,
219
217
 
220
218
  static int merge_into_self_callback(VALUE key, VALUE val, VALUE _self) {
221
219
  Map* self = ruby_to_Map(_self);
222
- upb_arena *arena = Arena_get(self->arena);
223
- upb_msgval key_val = Convert_RubyToUpb(key, "", Map_keyinfo(self), arena);
224
- upb_msgval val_val = Convert_RubyToUpb(val, "", self->value_type_info, arena);
225
- upb_map_set(Map_GetMutable(_self), key_val, val_val, arena);
220
+ upb_Arena* arena = Arena_get(self->arena);
221
+ upb_MessageValue key_val =
222
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), arena);
223
+ upb_MessageValue val_val =
224
+ Convert_RubyToUpb(val, "", self->value_type_info, arena);
225
+ upb_Map_Set(Map_GetMutable(_self), key_val, val_val, arena);
226
226
  return ST_CONTINUE;
227
227
  }
228
228
 
@@ -234,9 +234,8 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
234
234
  RTYPEDDATA_TYPE(hashmap) == &Map_type) {
235
235
  Map* self = ruby_to_Map(_self);
236
236
  Map* other = ruby_to_Map(hashmap);
237
- upb_arena *arena = Arena_get(self->arena);
238
- upb_msg *self_msg = Map_GetMutable(_self);
239
- size_t iter = UPB_MAP_BEGIN;
237
+ upb_Arena* arena = Arena_get(self->arena);
238
+ upb_Message* self_msg = Map_GetMutable(_self);
240
239
 
241
240
  Arena_fuse(other->arena, arena);
242
241
 
@@ -246,10 +245,10 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
246
245
  rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
247
246
  }
248
247
 
249
- while (upb_mapiter_next(other->map, &iter)) {
250
- upb_msgval key = upb_mapiter_key(other->map, iter);
251
- upb_msgval val = upb_mapiter_value(other->map, iter);
252
- upb_map_set(self_msg, key, val, arena);
248
+ size_t iter = kUpb_Map_Begin;
249
+ upb_MessageValue key, val;
250
+ while (upb_Map_Next(other->map, &key, &val, &iter)) {
251
+ upb_Map_Set(self_msg, key, val, arena);
253
252
  }
254
253
  } else {
255
254
  rb_raise(rb_eArgError, "Unknown type merging into Map");
@@ -305,20 +304,20 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
305
304
 
306
305
  // Check that the key type is an allowed type.
307
306
  switch (self->key_type) {
308
- case UPB_TYPE_INT32:
309
- case UPB_TYPE_INT64:
310
- case UPB_TYPE_UINT32:
311
- case UPB_TYPE_UINT64:
312
- case UPB_TYPE_BOOL:
313
- case UPB_TYPE_STRING:
314
- case UPB_TYPE_BYTES:
307
+ case kUpb_CType_Int32:
308
+ case kUpb_CType_Int64:
309
+ case kUpb_CType_UInt32:
310
+ case kUpb_CType_UInt64:
311
+ case kUpb_CType_Bool:
312
+ case kUpb_CType_String:
313
+ case kUpb_CType_Bytes:
315
314
  // These are OK.
316
315
  break;
317
316
  default:
318
317
  rb_raise(rb_eArgError, "Invalid key type for map.");
319
318
  }
320
319
 
321
- self->map = upb_map_new(Arena_get(self->arena), self->key_type,
320
+ self->map = upb_Map_New(Arena_get(self->arena), self->key_type,
322
321
  self->value_type_info.type);
323
322
  ObjectCache_Add(self->map, _self);
324
323
 
@@ -339,11 +338,10 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
339
338
  */
340
339
  static VALUE Map_each(VALUE _self) {
341
340
  Map* self = ruby_to_Map(_self);
342
- size_t iter = UPB_MAP_BEGIN;
341
+ size_t iter = kUpb_Map_Begin;
342
+ upb_MessageValue key, val;
343
343
 
344
- while (upb_mapiter_next(self->map, &iter)) {
345
- upb_msgval key = upb_mapiter_key(self->map, iter);
346
- upb_msgval val = upb_mapiter_value(self->map, iter);
344
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
347
345
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
348
346
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
349
347
  rb_yield_values(2, key_val, val_val);
@@ -360,11 +358,11 @@ static VALUE Map_each(VALUE _self) {
360
358
  */
361
359
  static VALUE Map_keys(VALUE _self) {
362
360
  Map* self = ruby_to_Map(_self);
363
- size_t iter = UPB_MAP_BEGIN;
361
+ size_t iter = kUpb_Map_Begin;
364
362
  VALUE ret = rb_ary_new();
363
+ upb_MessageValue key, val;
365
364
 
366
- while (upb_mapiter_next(self->map, &iter)) {
367
- upb_msgval key = upb_mapiter_key(self->map, iter);
365
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
368
366
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
369
367
  rb_ary_push(ret, key_val);
370
368
  }
@@ -380,11 +378,11 @@ static VALUE Map_keys(VALUE _self) {
380
378
  */
381
379
  static VALUE Map_values(VALUE _self) {
382
380
  Map* self = ruby_to_Map(_self);
383
- size_t iter = UPB_MAP_BEGIN;
381
+ size_t iter = kUpb_Map_Begin;
384
382
  VALUE ret = rb_ary_new();
383
+ upb_MessageValue key, val;
385
384
 
386
- while (upb_mapiter_next(self->map, &iter)) {
387
- upb_msgval val = upb_mapiter_value(self->map, iter);
385
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
388
386
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
389
387
  rb_ary_push(ret, val_val);
390
388
  }
@@ -401,10 +399,11 @@ static VALUE Map_values(VALUE _self) {
401
399
  */
402
400
  static VALUE Map_index(VALUE _self, VALUE key) {
403
401
  Map* self = ruby_to_Map(_self);
404
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
405
- upb_msgval val;
402
+ upb_MessageValue key_upb =
403
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
404
+ upb_MessageValue val;
406
405
 
407
- if (upb_map_get(self->map, key_upb, &val)) {
406
+ if (upb_Map_Get(self->map, key_upb, &val)) {
408
407
  return Convert_UpbToRuby(val, self->value_type_info, self->arena);
409
408
  } else {
410
409
  return Qnil;
@@ -421,11 +420,13 @@ static VALUE Map_index(VALUE _self, VALUE key) {
421
420
  */
422
421
  static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
423
422
  Map* self = ruby_to_Map(_self);
424
- upb_arena *arena = Arena_get(self->arena);
425
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
426
- upb_msgval val_upb = Convert_RubyToUpb(val, "", self->value_type_info, arena);
423
+ upb_Arena* arena = Arena_get(self->arena);
424
+ upb_MessageValue key_upb =
425
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
426
+ upb_MessageValue val_upb =
427
+ Convert_RubyToUpb(val, "", self->value_type_info, arena);
427
428
 
428
- upb_map_set(Map_GetMutable(_self), key_upb, val_upb, arena);
429
+ upb_Map_Set(Map_GetMutable(_self), key_upb, val_upb, arena);
429
430
 
430
431
  return val;
431
432
  }
@@ -439,9 +440,10 @@ static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
439
440
  */
440
441
  static VALUE Map_has_key(VALUE _self, VALUE key) {
441
442
  Map* self = ruby_to_Map(_self);
442
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
443
+ upb_MessageValue key_upb =
444
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
443
445
 
444
- if (upb_map_get(self->map, key_upb, NULL)) {
446
+ if (upb_Map_Get(self->map, key_upb, NULL)) {
445
447
  return Qtrue;
446
448
  } else {
447
449
  return Qfalse;
@@ -457,23 +459,17 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
457
459
  */
458
460
  static VALUE Map_delete(VALUE _self, VALUE key) {
459
461
  Map* self = ruby_to_Map(_self);
460
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
461
- upb_msgval val_upb;
462
- VALUE ret;
463
-
464
462
  rb_check_frozen(_self);
465
463
 
466
- // TODO(haberman): make upb_map_delete() also capable of returning the deleted
467
- // value.
468
- if (upb_map_get(self->map, key_upb, &val_upb)) {
469
- ret = Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
464
+ upb_MessageValue key_upb =
465
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
466
+ upb_MessageValue val_upb;
467
+
468
+ if (upb_Map_Delete(self->map, key_upb, &val_upb)) {
469
+ return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
470
470
  } else {
471
- ret = Qnil;
471
+ return Qnil;
472
472
  }
473
-
474
- upb_map_delete(Map_GetMutable(_self), key_upb);
475
-
476
- return ret;
477
473
  }
478
474
 
479
475
  /*
@@ -483,7 +479,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
483
479
  * Removes all entries from the map.
484
480
  */
485
481
  static VALUE Map_clear(VALUE _self) {
486
- upb_map_clear(Map_GetMutable(_self));
482
+ upb_Map_Clear(Map_GetMutable(_self));
487
483
  return Qnil;
488
484
  }
489
485
 
@@ -495,7 +491,7 @@ static VALUE Map_clear(VALUE _self) {
495
491
  */
496
492
  static VALUE Map_length(VALUE _self) {
497
493
  Map* self = ruby_to_Map(_self);
498
- return ULL2NUM(upb_map_size(self->map));
494
+ return ULL2NUM(upb_Map_Size(self->map));
499
495
  }
500
496
 
501
497
  /*
@@ -509,16 +505,15 @@ static VALUE Map_dup(VALUE _self) {
509
505
  Map* self = ruby_to_Map(_self);
510
506
  VALUE new_map_rb = Map_new_this_type(self);
511
507
  Map* new_self = ruby_to_Map(new_map_rb);
512
- size_t iter = UPB_MAP_BEGIN;
513
- upb_arena *arena = Arena_get(new_self->arena);
514
- upb_map *new_map = Map_GetMutable(new_map_rb);
508
+ size_t iter = kUpb_Map_Begin;
509
+ upb_Arena* arena = Arena_get(new_self->arena);
510
+ upb_Map* new_map = Map_GetMutable(new_map_rb);
515
511
 
516
512
  Arena_fuse(self->arena, arena);
517
513
 
518
- while (upb_mapiter_next(self->map, &iter)) {
519
- upb_msgval key = upb_mapiter_key(self->map, iter);
520
- upb_msgval val = upb_mapiter_value(self->map, iter);
521
- upb_map_set(new_map, key, val, arena);
514
+ upb_MessageValue key, val;
515
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
516
+ upb_Map_Set(new_map, key, val, arena);
522
517
  }
523
518
 
524
519
  return new_map_rb;
@@ -559,18 +554,17 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
559
554
  self->value_type_class != other->value_type_class) {
560
555
  return Qfalse;
561
556
  }
562
- if (upb_map_size(self->map) != upb_map_size(other->map)) {
557
+ if (upb_Map_Size(self->map) != upb_Map_Size(other->map)) {
563
558
  return Qfalse;
564
559
  }
565
560
 
566
561
  // For each member of self, check that an equal member exists at the same key
567
562
  // in other.
568
- size_t iter = UPB_MAP_BEGIN;
569
- while (upb_mapiter_next(self->map, &iter)) {
570
- upb_msgval key = upb_mapiter_key(self->map, iter);
571
- upb_msgval val = upb_mapiter_value(self->map, iter);
572
- upb_msgval other_val;
573
- if (!upb_map_get(other->map, key, &other_val)) {
563
+ size_t iter = kUpb_Map_Begin;
564
+ upb_MessageValue key, val;
565
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
566
+ upb_MessageValue other_val;
567
+ if (!upb_Map_Get(other->map, key, &other_val)) {
574
568
  // Not present in other map.
575
569
  return Qfalse;
576
570
  }
@@ -609,11 +603,10 @@ VALUE Map_hash(VALUE _self) {
609
603
  Map* self = ruby_to_Map(_self);
610
604
  uint64_t hash = 0;
611
605
 
612
- size_t iter = UPB_MAP_BEGIN;
606
+ size_t iter = kUpb_Map_Begin;
613
607
  TypeInfo key_info = {self->key_type};
614
- while (upb_mapiter_next(self->map, &iter)) {
615
- upb_msgval key = upb_mapiter_key(self->map, iter);
616
- upb_msgval val = upb_mapiter_value(self->map, iter);
608
+ upb_MessageValue key, val;
609
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
617
610
  hash = Msgval_GetHash(key, key_info, hash);
618
611
  hash = Msgval_GetHash(val, self->value_type_info, hash);
619
612
  }
@@ -38,22 +38,21 @@
38
38
 
39
39
  // Returns a Ruby wrapper object for the given map, which will be created if
40
40
  // one does not exist already.
41
- VALUE Map_GetRubyWrapper(upb_map *map, upb_fieldtype_t key_type,
42
- TypeInfo value_type, VALUE arena);
41
+ VALUE Map_GetRubyWrapper(upb_Map *map, upb_CType key_type, TypeInfo value_type,
42
+ VALUE arena);
43
43
 
44
- // Gets the underlying upb_map for this Ruby map object, which must have
44
+ // Gets the underlying upb_Map for this Ruby map object, which must have
45
45
  // key/value type that match |field|. If this is not a map or the type doesn't
46
46
  // match, raises an exception.
47
- const upb_map *Map_GetUpbMap(VALUE val, const upb_fielddef *field,
48
- upb_arena *arena);
47
+ const upb_Map *Map_GetUpbMap(VALUE val, const upb_FieldDef *field,
48
+ upb_Arena *arena);
49
49
 
50
50
  // Implements #inspect for this map by appending its contents to |b|.
51
- void Map_Inspect(StringBuilder *b, const upb_map *map, upb_fieldtype_t key_type,
51
+ void Map_Inspect(StringBuilder *b, const upb_Map *map, upb_CType key_type,
52
52
  TypeInfo val_type);
53
53
 
54
54
  // Returns a new Hash object containing the contents of this Map.
55
- VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type,
56
- TypeInfo val_info);
55
+ VALUE Map_CreateHash(const upb_Map *map, upb_CType key_type, TypeInfo val_info);
57
56
 
58
57
  // Returns a deep copy of this Map object.
59
58
  VALUE Map_deep_copy(VALUE obj);