google-protobuf 3.17.0 → 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 (44) 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 +235 -1529
  5. data/ext/google/protobuf_c/defs.h +19 -19
  6. data/ext/google/protobuf_c/extconf.rb +12 -6
  7. data/ext/google/protobuf_c/map.c +108 -110
  8. data/ext/google/protobuf_c/map.h +7 -7
  9. data/ext/google/protobuf_c/message.c +456 -343
  10. data/ext/google/protobuf_c/message.h +22 -19
  11. data/ext/google/protobuf_c/protobuf.c +78 -56
  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 +11806 -6746
  16. data/ext/google/protobuf_c/ruby-upb.h +10860 -3532
  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 +27 -23
  25. data/lib/google/protobuf/descriptor_dsl.rb +465 -0
  26. data/lib/google/protobuf/descriptor_pb.rb +75 -0
  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 +27 -68
  37. data/lib/google/protobuf/well_known_types.rb +12 -2
  38. data/lib/google/protobuf/wrappers_pb.rb +24 -28
  39. data/lib/google/protobuf.rb +5 -73
  40. metadata +17 -36
  41. data/ext/google/protobuf_c/third_party/wyhash/wyhash.h +0 -145
  42. data/tests/basic.rb +0 -604
  43. data/tests/generated_code_test.rb +0 -23
  44. 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,20 +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
- find_header('third_party/wyhash/wyhash.h', '../../../..')
21
- 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,24 +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
- const upb_fielddef* key_field = map_field_key(field);
172
- 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);
173
173
  TypeInfo value_type_info = TypeInfo_get(value_field);
174
174
  Map* self;
175
175
 
@@ -179,7 +179,7 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef *field) {
179
179
  }
180
180
 
181
181
  self = ruby_to_Map(val);
182
- if (self->key_type != upb_fielddef_type(key_field)) {
182
+ if (self->key_type != upb_FieldDef_CType(key_field)) {
183
183
  rb_raise(cTypeError, "Map key type does not match field's key type");
184
184
  }
185
185
  if (self->value_type_info.type != value_type_info.type) {
@@ -189,19 +189,19 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef *field) {
189
189
  rb_raise(cTypeError, "Map value type has wrong message/enum class");
190
190
  }
191
191
 
192
+ Arena_fuse(self->arena, arena);
192
193
  return self->map;
193
194
  }
194
195
 
195
- 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,
196
197
  TypeInfo val_type) {
197
198
  bool first = true;
198
199
  TypeInfo key_type_info = {key_type};
199
200
  StringBuilder_Printf(b, "{");
200
201
  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);
202
+ size_t iter = kUpb_Map_Begin;
203
+ upb_MessageValue key, val;
204
+ while (upb_Map_Next(map, &key, &val, &iter)) {
205
205
  if (first) {
206
206
  first = false;
207
207
  } else {
@@ -217,10 +217,12 @@ void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type,
217
217
 
218
218
  static int merge_into_self_callback(VALUE key, VALUE val, VALUE _self) {
219
219
  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);
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);
224
226
  return ST_CONTINUE;
225
227
  }
226
228
 
@@ -232,11 +234,10 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
232
234
  RTYPEDDATA_TYPE(hashmap) == &Map_type) {
233
235
  Map* self = ruby_to_Map(_self);
234
236
  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;
237
+ upb_Arena* arena = Arena_get(self->arena);
238
+ upb_Message* self_msg = Map_GetMutable(_self);
238
239
 
239
- upb_arena_fuse(arena, Arena_get(other->arena));
240
+ Arena_fuse(other->arena, arena);
240
241
 
241
242
  if (self->key_type != other->key_type ||
242
243
  self->value_type_info.type != other->value_type_info.type ||
@@ -244,10 +245,10 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
244
245
  rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
245
246
  }
246
247
 
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);
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);
251
252
  }
252
253
  } else {
253
254
  rb_raise(rb_eArgError, "Unknown type merging into Map");
@@ -303,20 +304,20 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
303
304
 
304
305
  // Check that the key type is an allowed type.
305
306
  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:
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:
313
314
  // These are OK.
314
315
  break;
315
316
  default:
316
317
  rb_raise(rb_eArgError, "Invalid key type for map.");
317
318
  }
318
319
 
319
- 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,
320
321
  self->value_type_info.type);
321
322
  ObjectCache_Add(self->map, _self);
322
323
 
@@ -337,11 +338,10 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
337
338
  */
338
339
  static VALUE Map_each(VALUE _self) {
339
340
  Map* self = ruby_to_Map(_self);
340
- size_t iter = UPB_MAP_BEGIN;
341
+ size_t iter = kUpb_Map_Begin;
342
+ upb_MessageValue key, val;
341
343
 
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);
344
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
345
345
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
346
346
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
347
347
  rb_yield_values(2, key_val, val_val);
@@ -358,11 +358,11 @@ static VALUE Map_each(VALUE _self) {
358
358
  */
359
359
  static VALUE Map_keys(VALUE _self) {
360
360
  Map* self = ruby_to_Map(_self);
361
- size_t iter = UPB_MAP_BEGIN;
361
+ size_t iter = kUpb_Map_Begin;
362
362
  VALUE ret = rb_ary_new();
363
+ upb_MessageValue key, val;
363
364
 
364
- while (upb_mapiter_next(self->map, &iter)) {
365
- upb_msgval key = upb_mapiter_key(self->map, iter);
365
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
366
366
  VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
367
367
  rb_ary_push(ret, key_val);
368
368
  }
@@ -378,11 +378,11 @@ static VALUE Map_keys(VALUE _self) {
378
378
  */
379
379
  static VALUE Map_values(VALUE _self) {
380
380
  Map* self = ruby_to_Map(_self);
381
- size_t iter = UPB_MAP_BEGIN;
381
+ size_t iter = kUpb_Map_Begin;
382
382
  VALUE ret = rb_ary_new();
383
+ upb_MessageValue key, val;
383
384
 
384
- while (upb_mapiter_next(self->map, &iter)) {
385
- upb_msgval val = upb_mapiter_value(self->map, iter);
385
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
386
386
  VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
387
387
  rb_ary_push(ret, val_val);
388
388
  }
@@ -399,10 +399,11 @@ static VALUE Map_values(VALUE _self) {
399
399
  */
400
400
  static VALUE Map_index(VALUE _self, VALUE key) {
401
401
  Map* self = ruby_to_Map(_self);
402
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
403
- upb_msgval val;
402
+ upb_MessageValue key_upb =
403
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
404
+ upb_MessageValue val;
404
405
 
405
- if (upb_map_get(self->map, key_upb, &val)) {
406
+ if (upb_Map_Get(self->map, key_upb, &val)) {
406
407
  return Convert_UpbToRuby(val, self->value_type_info, self->arena);
407
408
  } else {
408
409
  return Qnil;
@@ -419,11 +420,13 @@ static VALUE Map_index(VALUE _self, VALUE key) {
419
420
  */
420
421
  static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
421
422
  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);
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);
425
428
 
426
- upb_map_set(Map_GetMutable(_self), key_upb, val_upb, arena);
429
+ upb_Map_Set(Map_GetMutable(_self), key_upb, val_upb, arena);
427
430
 
428
431
  return val;
429
432
  }
@@ -437,9 +440,10 @@ static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) {
437
440
  */
438
441
  static VALUE Map_has_key(VALUE _self, VALUE key) {
439
442
  Map* self = ruby_to_Map(_self);
440
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
443
+ upb_MessageValue key_upb =
444
+ Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
441
445
 
442
- if (upb_map_get(self->map, key_upb, NULL)) {
446
+ if (upb_Map_Get(self->map, key_upb, NULL)) {
443
447
  return Qtrue;
444
448
  } else {
445
449
  return Qfalse;
@@ -455,23 +459,17 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
455
459
  */
456
460
  static VALUE Map_delete(VALUE _self, VALUE key) {
457
461
  Map* self = ruby_to_Map(_self);
458
- upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
459
- upb_msgval val_upb;
460
- VALUE ret;
461
-
462
462
  rb_check_frozen(_self);
463
463
 
464
- // TODO(haberman): make upb_map_delete() also capable of returning the deleted
465
- // value.
466
- if (upb_map_get(self->map, key_upb, &val_upb)) {
467
- 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);
468
470
  } else {
469
- ret = Qnil;
471
+ return Qnil;
470
472
  }
471
-
472
- upb_map_delete(Map_GetMutable(_self), key_upb);
473
-
474
- return ret;
475
473
  }
476
474
 
477
475
  /*
@@ -481,7 +479,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
481
479
  * Removes all entries from the map.
482
480
  */
483
481
  static VALUE Map_clear(VALUE _self) {
484
- upb_map_clear(Map_GetMutable(_self));
482
+ upb_Map_Clear(Map_GetMutable(_self));
485
483
  return Qnil;
486
484
  }
487
485
 
@@ -493,7 +491,7 @@ static VALUE Map_clear(VALUE _self) {
493
491
  */
494
492
  static VALUE Map_length(VALUE _self) {
495
493
  Map* self = ruby_to_Map(_self);
496
- return ULL2NUM(upb_map_size(self->map));
494
+ return ULL2NUM(upb_Map_Size(self->map));
497
495
  }
498
496
 
499
497
  /*
@@ -507,16 +505,15 @@ static VALUE Map_dup(VALUE _self) {
507
505
  Map* self = ruby_to_Map(_self);
508
506
  VALUE new_map_rb = Map_new_this_type(self);
509
507
  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);
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);
513
511
 
514
- upb_arena_fuse(arena, Arena_get(self->arena));
512
+ Arena_fuse(self->arena, arena);
515
513
 
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);
514
+ upb_MessageValue key, val;
515
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
516
+ upb_Map_Set(new_map, key, val, arena);
520
517
  }
521
518
 
522
519
  return new_map_rb;
@@ -557,18 +554,17 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
557
554
  self->value_type_class != other->value_type_class) {
558
555
  return Qfalse;
559
556
  }
560
- if (upb_map_size(self->map) != upb_map_size(other->map)) {
557
+ if (upb_Map_Size(self->map) != upb_Map_Size(other->map)) {
561
558
  return Qfalse;
562
559
  }
563
560
 
564
561
  // For each member of self, check that an equal member exists at the same key
565
562
  // 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)) {
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)) {
572
568
  // Not present in other map.
573
569
  return Qfalse;
574
570
  }
@@ -607,11 +603,10 @@ VALUE Map_hash(VALUE _self) {
607
603
  Map* self = ruby_to_Map(_self);
608
604
  uint64_t hash = 0;
609
605
 
610
- size_t iter = UPB_MAP_BEGIN;
606
+ size_t iter = kUpb_Map_Begin;
611
607
  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);
608
+ upb_MessageValue key, val;
609
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
615
610
  hash = Msgval_GetHash(key, key_info, hash);
616
611
  hash = Msgval_GetHash(val, self->value_type_info, hash);
617
612
  }
@@ -678,7 +673,10 @@ void Map_register(VALUE module) {
678
673
  rb_define_method(klass, "delete", Map_delete, 1);
679
674
  rb_define_method(klass, "clear", Map_clear, 0);
680
675
  rb_define_method(klass, "length", Map_length, 0);
676
+ rb_define_method(klass, "size", Map_length, 0);
681
677
  rb_define_method(klass, "dup", Map_dup, 0);
678
+ // Also define #clone so that we don't inherit Object#clone.
679
+ rb_define_method(klass, "clone", Map_dup, 0);
682
680
  rb_define_method(klass, "==", Map_eq, 1);
683
681
  rb_define_method(klass, "freeze", Map_freeze, 0);
684
682
  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);