google-protobuf 3.16.0 → 3.21.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +128 -116
  3. data/ext/google/protobuf_c/convert.h +12 -9
  4. data/ext/google/protobuf_c/defs.c +217 -1521
  5. data/ext/google/protobuf_c/defs.h +19 -19
  6. data/ext/google/protobuf_c/extconf.rb +11 -3
  7. data/ext/google/protobuf_c/map.c +115 -102
  8. data/ext/google/protobuf_c/map.h +7 -7
  9. data/ext/google/protobuf_c/message.c +399 -308
  10. data/ext/google/protobuf_c/message.h +22 -19
  11. data/ext/google/protobuf_c/protobuf.c +89 -63
  12. data/ext/google/protobuf_c/protobuf.h +16 -9
  13. data/ext/google/protobuf_c/repeated_field.c +85 -85
  14. data/ext/google/protobuf_c/repeated_field.h +6 -5
  15. data/ext/google/protobuf_c/ruby-upb.c +10664 -7049
  16. data/ext/google/protobuf_c/ruby-upb.h +4378 -2489
  17. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -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 +9 -0
  22. data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
  23. data/lib/google/protobuf/api_pb.rb +1 -0
  24. data/lib/google/protobuf/descriptor_dsl.rb +465 -0
  25. data/lib/google/protobuf/descriptor_pb.rb +269 -0
  26. data/lib/google/protobuf/message_exts.rb +2 -2
  27. data/lib/google/protobuf/repeated_field.rb +15 -2
  28. data/lib/google/protobuf/type_pb.rb +1 -0
  29. data/lib/google/protobuf/well_known_types.rb +12 -2
  30. data/lib/google/protobuf.rb +5 -73
  31. data/tests/basic.rb +144 -9
  32. data/tests/stress.rb +1 -1
  33. metadata +15 -29
  34. data/ext/google/protobuf_c/third_party/wyhash/wyhash.h +0 -145
@@ -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,6 +2,10 @@
2
2
 
3
3
  require 'mkmf'
4
4
 
5
+ ext_name = "google/protobuf_c"
6
+
7
+ dir_config(ext_name)
8
+
5
9
  if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
6
10
  $CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
7
11
  else
@@ -14,7 +18,11 @@ if RUBY_PLATFORM =~ /linux/
14
18
  $LDFLAGS += " -Wl,-wrap,memcpy"
15
19
  end
16
20
 
17
- $objs = ["protobuf.o", "convert.o", "defs.o", "message.o",
18
- "repeated_field.o", "map.o", "ruby-upb.o", "wrap_memcpy.o"]
21
+ $VPATH << "$(srcdir)/third_party/utf8_range"
22
+ $INCFLAGS << "$(srcdir)/third_party/utf8_range"
23
+
24
+ $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
25
+ "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
26
+ "naive.c", "range2-neon.c", "range2-sse.c"]
19
27
 
20
- create_makefile("google/protobuf_c")
28
+ 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,22 @@ 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;
136
+ size_t iter = kUpb_Map_Begin;
137
137
  TypeInfo key_info = TypeInfo_from_type(key_type);
138
138
 
139
139
  if (!map) return hash;
140
140
 
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);
141
+ while (upb_MapIterator_Next(map, &iter)) {
142
+ upb_MessageValue key = upb_MapIterator_Key(map, iter);
143
+ upb_MessageValue val = upb_MapIterator_Value(map, iter);
144
144
  VALUE key_val = Convert_UpbToRuby(key, key_info, Qnil);
145
145
  VALUE val_val = Scalar_CreateHash(val, val_info);
146
146
  rb_hash_aset(hash, key_val, val_val);
@@ -152,24 +152,26 @@ VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type,
152
152
  VALUE Map_deep_copy(VALUE obj) {
153
153
  Map* self = ruby_to_Map(obj);
154
154
  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);
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 = kUpb_Map_Begin;
159
+ while (upb_MapIterator_Next(self->map, &iter)) {
160
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
161
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
162
+ upb_MessageValue val_copy =
163
+ Msgval_DeepCopy(val, self->value_type_info, arena);
164
+ upb_Map_Set(new_map, key, val_copy, arena);
164
165
  }
165
166
 
166
167
  return Map_GetRubyWrapper(new_map, self->key_type, self->value_type_info,
167
168
  new_arena_rb);
168
169
  }
169
170
 
170
- const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef *field) {
171
- const upb_fielddef* key_field = map_field_key(field);
172
- const upb_fielddef* value_field = map_field_value(field);
171
+ const upb_Map* Map_GetUpbMap(VALUE val, const upb_FieldDef* field,
172
+ upb_Arena* arena) {
173
+ const upb_FieldDef* key_field = map_field_key(field);
174
+ const upb_FieldDef* value_field = map_field_value(field);
173
175
  TypeInfo value_type_info = TypeInfo_get(value_field);
174
176
  Map* self;
175
177
 
@@ -179,7 +181,7 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef *field) {
179
181
  }
180
182
 
181
183
  self = ruby_to_Map(val);
182
- if (self->key_type != upb_fielddef_type(key_field)) {
184
+ if (self->key_type != upb_FieldDef_CType(key_field)) {
183
185
  rb_raise(cTypeError, "Map key type does not match field's key type");
184
186
  }
185
187
  if (self->value_type_info.type != value_type_info.type) {
@@ -189,19 +191,20 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef *field) {
189
191
  rb_raise(cTypeError, "Map value type has wrong message/enum class");
190
192
  }
191
193
 
194
+ Arena_fuse(self->arena, arena);
192
195
  return self->map;
193
196
  }
194
197
 
195
- void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type,
198
+ void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type,
196
199
  TypeInfo val_type) {
197
200
  bool first = true;
198
201
  TypeInfo key_type_info = {key_type};
199
202
  StringBuilder_Printf(b, "{");
200
203
  if (map) {
201
- size_t iter = UPB_MAP_BEGIN;
202
- while (upb_mapiter_next(map, &iter)) {
203
- upb_msgval key = upb_mapiter_key(map, iter);
204
- upb_msgval val = upb_mapiter_value(map, iter);
204
+ size_t iter = kUpb_Map_Begin;
205
+ while (upb_MapIterator_Next(map, &iter)) {
206
+ upb_MessageValue key = upb_MapIterator_Key(map, iter);
207
+ upb_MessageValue val = upb_MapIterator_Value(map, iter);
205
208
  if (first) {
206
209
  first = false;
207
210
  } else {
@@ -217,10 +220,12 @@ void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type,
217
220
 
218
221
  static int merge_into_self_callback(VALUE key, VALUE val, VALUE _self) {
219
222
  Map* self = ruby_to_Map(_self);
220
- upb_arena *arena = Arena_get(self->arena);
221
- upb_msgval key_val = Convert_RubyToUpb(key, "", Map_keyinfo(self), arena);
222
- upb_msgval val_val = Convert_RubyToUpb(val, "", self->value_type_info, arena);
223
- upb_map_set(Map_GetMutable(_self), key_val, val_val, arena);
223
+ upb_Arena* arena = Arena_get(self->arena);
224
+ upb_MessageValue key_val =
225
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), arena);
226
+ upb_MessageValue val_val =
227
+ Convert_RubyToUpb(val, "", self->value_type_info, arena);
228
+ upb_Map_Set(Map_GetMutable(_self), key_val, val_val, arena);
224
229
  return ST_CONTINUE;
225
230
  }
226
231
 
@@ -232,11 +237,11 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
232
237
  RTYPEDDATA_TYPE(hashmap) == &Map_type) {
233
238
  Map* self = ruby_to_Map(_self);
234
239
  Map* other = ruby_to_Map(hashmap);
235
- upb_arena *arena = Arena_get(self->arena);
236
- upb_msg *self_msg = Map_GetMutable(_self);
237
- size_t iter = UPB_MAP_BEGIN;
240
+ upb_Arena* arena = Arena_get(self->arena);
241
+ upb_Message* self_msg = Map_GetMutable(_self);
242
+ size_t iter = kUpb_Map_Begin;
238
243
 
239
- upb_arena_fuse(arena, Arena_get(other->arena));
244
+ Arena_fuse(other->arena, arena);
240
245
 
241
246
  if (self->key_type != other->key_type ||
242
247
  self->value_type_info.type != other->value_type_info.type ||
@@ -244,10 +249,10 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
244
249
  rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
245
250
  }
246
251
 
247
- while (upb_mapiter_next(other->map, &iter)) {
248
- upb_msgval key = upb_mapiter_key(other->map, iter);
249
- upb_msgval val = upb_mapiter_value(other->map, iter);
250
- upb_map_set(self_msg, key, val, arena);
252
+ while (upb_MapIterator_Next(other->map, &iter)) {
253
+ upb_MessageValue key = upb_MapIterator_Key(other->map, iter);
254
+ upb_MessageValue val = upb_MapIterator_Value(other->map, iter);
255
+ upb_Map_Set(self_msg, key, val, arena);
251
256
  }
252
257
  } else {
253
258
  rb_raise(rb_eArgError, "Unknown type merging into Map");
@@ -303,20 +308,20 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
303
308
 
304
309
  // Check that the key type is an allowed type.
305
310
  switch (self->key_type) {
306
- case UPB_TYPE_INT32:
307
- case UPB_TYPE_INT64:
308
- case UPB_TYPE_UINT32:
309
- case UPB_TYPE_UINT64:
310
- case UPB_TYPE_BOOL:
311
- case UPB_TYPE_STRING:
312
- case UPB_TYPE_BYTES:
311
+ case kUpb_CType_Int32:
312
+ case kUpb_CType_Int64:
313
+ case kUpb_CType_UInt32:
314
+ case kUpb_CType_UInt64:
315
+ case kUpb_CType_Bool:
316
+ case kUpb_CType_String:
317
+ case kUpb_CType_Bytes:
313
318
  // These are OK.
314
319
  break;
315
320
  default:
316
321
  rb_raise(rb_eArgError, "Invalid key type for map.");
317
322
  }
318
323
 
319
- self->map = upb_map_new(Arena_get(self->arena), self->key_type,
324
+ self->map = upb_Map_New(Arena_get(self->arena), self->key_type,
320
325
  self->value_type_info.type);
321
326
  ObjectCache_Add(self->map, _self);
322
327
 
@@ -337,11 +342,11 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
337
342
  */
338
343
  static VALUE Map_each(VALUE _self) {
339
344
  Map* self = ruby_to_Map(_self);
340
- size_t iter = UPB_MAP_BEGIN;
345
+ size_t iter = kUpb_Map_Begin;
341
346
 
342
- while (upb_mapiter_next(self->map, &iter)) {
343
- upb_msgval key = upb_mapiter_key(self->map, iter);
344
- upb_msgval val = upb_mapiter_value(self->map, iter);
347
+ while (upb_MapIterator_Next(self->map, &iter)) {
348
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
349
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
345
350
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
346
351
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
347
352
  rb_yield_values(2, key_val, val_val);
@@ -358,11 +363,11 @@ static VALUE Map_each(VALUE _self) {
358
363
  */
359
364
  static VALUE Map_keys(VALUE _self) {
360
365
  Map* self = ruby_to_Map(_self);
361
- size_t iter = UPB_MAP_BEGIN;
366
+ size_t iter = kUpb_Map_Begin;
362
367
  VALUE ret = rb_ary_new();
363
368
 
364
- while (upb_mapiter_next(self->map, &iter)) {
365
- upb_msgval key = upb_mapiter_key(self->map, iter);
369
+ while (upb_MapIterator_Next(self->map, &iter)) {
370
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
366
371
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
367
372
  rb_ary_push(ret, key_val);
368
373
  }
@@ -378,11 +383,11 @@ static VALUE Map_keys(VALUE _self) {
378
383
  */
379
384
  static VALUE Map_values(VALUE _self) {
380
385
  Map* self = ruby_to_Map(_self);
381
- size_t iter = UPB_MAP_BEGIN;
386
+ size_t iter = kUpb_Map_Begin;
382
387
  VALUE ret = rb_ary_new();
383
388
 
384
- while (upb_mapiter_next(self->map, &iter)) {
385
- upb_msgval val = upb_mapiter_value(self->map, iter);
389
+ while (upb_MapIterator_Next(self->map, &iter)) {
390
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
386
391
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
387
392
  rb_ary_push(ret, val_val);
388
393
  }
@@ -399,10 +404,11 @@ static VALUE Map_values(VALUE _self) {
399
404
  */
400
405
  static VALUE Map_index(VALUE _self, VALUE key) {
401
406
  Map* self = ruby_to_Map(_self);
402
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
403
- upb_msgval val;
407
+ upb_MessageValue key_upb =
408
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
409
+ upb_MessageValue val;
404
410
 
405
- if (upb_map_get(self->map, key_upb, &val)) {
411
+ if (upb_Map_Get(self->map, key_upb, &val)) {
406
412
  return Convert_UpbToRuby(val, self->value_type_info, self->arena);
407
413
  } else {
408
414
  return Qnil;
@@ -419,11 +425,13 @@ static VALUE Map_index(VALUE _self, VALUE key) {
419
425
  */
420
426
  static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
421
427
  Map* self = ruby_to_Map(_self);
422
- upb_arena *arena = Arena_get(self->arena);
423
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
424
- upb_msgval val_upb = Convert_RubyToUpb(val, "", self->value_type_info, arena);
428
+ upb_Arena* arena = Arena_get(self->arena);
429
+ upb_MessageValue key_upb =
430
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
431
+ upb_MessageValue val_upb =
432
+ Convert_RubyToUpb(val, "", self->value_type_info, arena);
425
433
 
426
- upb_map_set(Map_GetMutable(_self), key_upb, val_upb, arena);
434
+ upb_Map_Set(Map_GetMutable(_self), key_upb, val_upb, arena);
427
435
 
428
436
  return val;
429
437
  }
@@ -437,9 +445,10 @@ static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
437
445
  */
438
446
  static VALUE Map_has_key(VALUE _self, VALUE key) {
439
447
  Map* self = ruby_to_Map(_self);
440
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
448
+ upb_MessageValue key_upb =
449
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
441
450
 
442
- if (upb_map_get(self->map, key_upb, NULL)) {
451
+ if (upb_Map_Get(self->map, key_upb, NULL)) {
443
452
  return Qtrue;
444
453
  } else {
445
454
  return Qfalse;
@@ -455,21 +464,22 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
455
464
  */
456
465
  static VALUE Map_delete(VALUE _self, VALUE key) {
457
466
  Map* self = ruby_to_Map(_self);
458
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
459
- upb_msgval val_upb;
467
+ upb_MessageValue key_upb =
468
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
469
+ upb_MessageValue val_upb;
460
470
  VALUE ret;
461
471
 
462
472
  rb_check_frozen(_self);
463
473
 
464
- // TODO(haberman): make upb_map_delete() also capable of returning the deleted
474
+ // TODO(haberman): make upb_Map_Delete() also capable of returning the deleted
465
475
  // value.
466
- if (upb_map_get(self->map, key_upb, &val_upb)) {
476
+ if (upb_Map_Get(self->map, key_upb, &val_upb)) {
467
477
  ret = Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
468
478
  } else {
469
479
  ret = Qnil;
470
480
  }
471
481
 
472
- upb_map_delete(Map_GetMutable(_self), key_upb);
482
+ upb_Map_Delete(Map_GetMutable(_self), key_upb);
473
483
 
474
484
  return ret;
475
485
  }
@@ -481,7 +491,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
481
491
  * Removes all entries from the map.
482
492
  */
483
493
  static VALUE Map_clear(VALUE _self) {
484
- upb_map_clear(Map_GetMutable(_self));
494
+ upb_Map_Clear(Map_GetMutable(_self));
485
495
  return Qnil;
486
496
  }
487
497
 
@@ -493,7 +503,7 @@ static VALUE Map_clear(VALUE _self) {
493
503
  */
494
504
  static VALUE Map_length(VALUE _self) {
495
505
  Map* self = ruby_to_Map(_self);
496
- return ULL2NUM(upb_map_size(self->map));
506
+ return ULL2NUM(upb_Map_Size(self->map));
497
507
  }
498
508
 
499
509
  /*
@@ -507,16 +517,16 @@ static VALUE Map_dup(VALUE _self) {
507
517
  Map* self = ruby_to_Map(_self);
508
518
  VALUE new_map_rb = Map_new_this_type(self);
509
519
  Map* new_self = ruby_to_Map(new_map_rb);
510
- size_t iter = UPB_MAP_BEGIN;
511
- upb_arena *arena = Arena_get(new_self->arena);
512
- upb_map *new_map = Map_GetMutable(new_map_rb);
520
+ size_t iter = kUpb_Map_Begin;
521
+ upb_Arena* arena = Arena_get(new_self->arena);
522
+ upb_Map* new_map = Map_GetMutable(new_map_rb);
513
523
 
514
- upb_arena_fuse(arena, Arena_get(self->arena));
524
+ Arena_fuse(self->arena, arena);
515
525
 
516
- while (upb_mapiter_next(self->map, &iter)) {
517
- upb_msgval key = upb_mapiter_key(self->map, iter);
518
- upb_msgval val = upb_mapiter_value(self->map, iter);
519
- upb_map_set(new_map, key, val, arena);
526
+ while (upb_MapIterator_Next(self->map, &iter)) {
527
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
528
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
529
+ upb_Map_Set(new_map, key, val, arena);
520
530
  }
521
531
 
522
532
  return new_map_rb;
@@ -557,18 +567,18 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
557
567
  self->value_type_class != other->value_type_class) {
558
568
  return Qfalse;
559
569
  }
560
- if (upb_map_size(self->map) != upb_map_size(other->map)) {
570
+ if (upb_Map_Size(self->map) != upb_Map_Size(other->map)) {
561
571
  return Qfalse;
562
572
  }
563
573
 
564
574
  // For each member of self, check that an equal member exists at the same key
565
575
  // in other.
566
- size_t iter = UPB_MAP_BEGIN;
567
- while (upb_mapiter_next(self->map, &iter)) {
568
- upb_msgval key = upb_mapiter_key(self->map, iter);
569
- upb_msgval val = upb_mapiter_value(self->map, iter);
570
- upb_msgval other_val;
571
- if (!upb_map_get(other->map, key, &other_val)) {
576
+ size_t iter = kUpb_Map_Begin;
577
+ while (upb_MapIterator_Next(self->map, &iter)) {
578
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
579
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
580
+ upb_MessageValue other_val;
581
+ if (!upb_Map_Get(other->map, key, &other_val)) {
572
582
  // Not present in other map.
573
583
  return Qfalse;
574
584
  }
@@ -607,11 +617,11 @@ VALUE Map_hash(VALUE _self) {
607
617
  Map* self = ruby_to_Map(_self);
608
618
  uint64_t hash = 0;
609
619
 
610
- size_t iter = UPB_MAP_BEGIN;
620
+ size_t iter = kUpb_Map_Begin;
611
621
  TypeInfo key_info = {self->key_type};
612
- while (upb_mapiter_next(self->map, &iter)) {
613
- upb_msgval key = upb_mapiter_key(self->map, iter);
614
- upb_msgval val = upb_mapiter_value(self->map, iter);
622
+ while (upb_MapIterator_Next(self->map, &iter)) {
623
+ upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
624
+ upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
615
625
  hash = Msgval_GetHash(key, key_info, hash);
616
626
  hash = Msgval_GetHash(val, self->value_type_info, hash);
617
627
  }
@@ -678,7 +688,10 @@ void Map_register(VALUE module) {
678
688
  rb_define_method(klass, "delete", Map_delete, 1);
679
689
  rb_define_method(klass, "clear", Map_clear, 0);
680
690
  rb_define_method(klass, "length", Map_length, 0);
691
+ rb_define_method(klass, "size", Map_length, 0);
681
692
  rb_define_method(klass, "dup", Map_dup, 0);
693
+ // Also define #clone so that we don't inherit Object#clone.
694
+ rb_define_method(klass, "clone", Map_dup, 0);
682
695
  rb_define_method(klass, "==", Map_eq, 1);
683
696
  rb_define_method(klass, "freeze", Map_freeze, 0);
684
697
  rb_define_method(klass, "hash", Map_hash, 0);
@@ -38,21 +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);
47
+ const upb_Map *Map_GetUpbMap(VALUE val, const upb_FieldDef *field,
48
+ upb_Arena *arena);
48
49
 
49
50
  // Implements #inspect for this map by appending its contents to |b|.
50
- 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,
51
52
  TypeInfo val_type);
52
53
 
53
54
  // Returns a new Hash object containing the contents of this Map.
54
- VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type,
55
- TypeInfo val_info);
55
+ VALUE Map_CreateHash(const upb_Map *map, upb_CType key_type, TypeInfo val_info);
56
56
 
57
57
  // Returns a deep copy of this Map object.
58
58
  VALUE Map_deep_copy(VALUE obj);