google-protobuf 3.9.2-x64-mingw32 → 3.10.0.rc.1-x64-mingw32

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.

@@ -3,11 +3,9 @@
3
3
  require 'mkmf'
4
4
 
5
5
  if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
6
- # XOPEN_SOURCE needed for strptime:
7
- # https://stackoverflow.com/questions/35234152/strptime-giving-implicit-declaration-and-undefined-reference
8
- $CFLAGS += " -std=c99 -O3 -DNDEBUG -D_XOPEN_SOURCE=700"
6
+ $CFLAGS += " -std=gnu90 -O3 -DNDEBUG -Wall -Wdeclaration-after-statement -Wsign-compare"
9
7
  else
10
- $CFLAGS += " -std=c99 -O3 -DNDEBUG"
8
+ $CFLAGS += " -std=gnu90 -O3 -DNDEBUG"
11
9
  end
12
10
 
13
11
 
@@ -71,6 +71,9 @@ static VALUE table_key(Map* self, VALUE key,
71
71
  case UPB_TYPE_BYTES:
72
72
  case UPB_TYPE_STRING:
73
73
  // Strings: use string content directly.
74
+ if (TYPE(key) == T_SYMBOL) {
75
+ key = rb_id2str(SYM2ID(key));
76
+ }
74
77
  Check_Type(key, T_STRING);
75
78
  key = native_slot_encode_and_freeze_string(self->key_type, key);
76
79
  *out_key = RSTRING_PTR(key);
@@ -386,10 +389,7 @@ VALUE Map_index(VALUE _self, VALUE key) {
386
389
  * was just inserted.
387
390
  */
388
391
  VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
389
- rb_check_frozen(_self);
390
-
391
392
  Map* self = ruby_to_Map(_self);
392
-
393
393
  char keybuf[TABLE_KEY_BUF_LENGTH];
394
394
  const char* keyval = NULL;
395
395
  size_t length = 0;
@@ -397,6 +397,13 @@ VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
397
397
  void* mem;
398
398
  key = table_key(self, key, keybuf, &keyval, &length);
399
399
 
400
+ rb_check_frozen(_self);
401
+
402
+ if (TYPE(value) == T_HASH) {
403
+ VALUE args[1] = { value };
404
+ value = rb_class_new_instance(1, args, self->value_type_class);
405
+ }
406
+
400
407
  mem = value_memory(&v);
401
408
  native_slot_set("", self->value_type, self->value_type_class, mem, value);
402
409
 
@@ -440,16 +447,15 @@ VALUE Map_has_key(VALUE _self, VALUE key) {
440
447
  * nil if none was present. Throws an exception if the key is of the wrong type.
441
448
  */
442
449
  VALUE Map_delete(VALUE _self, VALUE key) {
443
- rb_check_frozen(_self);
444
-
445
450
  Map* self = ruby_to_Map(_self);
446
-
447
451
  char keybuf[TABLE_KEY_BUF_LENGTH];
448
452
  const char* keyval = NULL;
449
453
  size_t length = 0;
450
454
  upb_value v;
451
455
  key = table_key(self, key, keybuf, &keyval, &length);
452
456
 
457
+ rb_check_frozen(_self);
458
+
453
459
  if (upb_strtable_remove2(&self->table, keyval, length, &v)) {
454
460
  void* mem = value_memory(&v);
455
461
  return native_slot_get(self->value_type, self->value_type_class, mem);
@@ -465,10 +471,10 @@ VALUE Map_delete(VALUE _self, VALUE key) {
465
471
  * Removes all entries from the map.
466
472
  */
467
473
  VALUE Map_clear(VALUE _self) {
468
- rb_check_frozen(_self);
469
-
470
474
  Map* self = ruby_to_Map(_self);
471
475
 
476
+ rb_check_frozen(_self);
477
+
472
478
  // Uninit and reinit the table -- this is faster than iterating and doing a
473
479
  // delete-lookup on each key.
474
480
  upb_strtable_uninit(&self->table);
@@ -489,7 +495,7 @@ VALUE Map_length(VALUE _self) {
489
495
  return ULL2NUM(upb_strtable_count(&self->table));
490
496
  }
491
497
 
492
- static VALUE Map_new_this_type(VALUE _self) {
498
+ VALUE Map_new_this_type(VALUE _self) {
493
499
  Map* self = ruby_to_Map(_self);
494
500
  VALUE new_map = Qnil;
495
501
  VALUE key_type = fieldtype_to_ruby(self->key_type);
@@ -60,47 +60,31 @@ rb_data_type_t Message_type = {
60
60
  VALUE Message_alloc(VALUE klass) {
61
61
  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
62
62
  Descriptor* desc = ruby_to_Descriptor(descriptor);
63
- MessageHeader* msg = (MessageHeader*)ALLOC_N(
64
- uint8_t, sizeof(MessageHeader) + desc->layout->size);
63
+ MessageHeader* msg;
65
64
  VALUE ret;
65
+ size_t size;
66
66
 
67
- memset(Message_data(msg), 0, desc->layout->size);
67
+ if (desc->layout == NULL) {
68
+ create_layout(desc);
69
+ }
68
70
 
69
- // We wrap first so that everything in the message object is GC-rooted in case
70
- // a collection happens during object creation in layout_init().
71
- ret = TypedData_Wrap_Struct(klass, &Message_type, msg);
71
+ msg = ALLOC_N(uint8_t, sizeof(MessageHeader) + desc->layout->size);
72
72
  msg->descriptor = desc;
73
- rb_ivar_set(ret, descriptor_instancevar_interned, descriptor);
74
-
75
73
  msg->unknown_fields = NULL;
74
+ memcpy(Message_data(msg), desc->layout->empty_template, desc->layout->size);
76
75
 
77
- layout_init(desc->layout, Message_data(msg));
76
+ ret = TypedData_Wrap_Struct(klass, &Message_type, msg);
77
+ rb_ivar_set(ret, descriptor_instancevar_interned, descriptor);
78
78
 
79
79
  return ret;
80
80
  }
81
81
 
82
82
  static const upb_fielddef* which_oneof_field(MessageHeader* self, const upb_oneofdef* o) {
83
- upb_oneof_iter it;
84
- size_t case_ofs;
85
83
  uint32_t oneof_case;
86
- const upb_fielddef* first_field;
87
84
  const upb_fielddef* f;
88
85
 
89
- // If no fields in the oneof, always nil.
90
- if (upb_oneofdef_numfields(o) == 0) {
91
- return NULL;
92
- }
93
- // Grab the first field in the oneof so we can get its layout info to find the
94
- // oneof_case field.
95
- upb_oneof_begin(&it, o);
96
- assert(!upb_oneof_done(&it));
97
- first_field = upb_oneof_iter_field(&it);
98
- assert(upb_fielddef_containingoneof(first_field) != NULL);
99
-
100
- case_ofs =
101
- self->descriptor->layout->
102
- fields[upb_fielddef_index(first_field)].case_offset;
103
- oneof_case = *((uint32_t*)((char*)Message_data(self) + case_ofs));
86
+ oneof_case =
87
+ slot_read_oneof_case(self->descriptor->layout, Message_data(self), o);
104
88
 
105
89
  if (oneof_case == ONEOF_CASE_NONE) {
106
90
  return NULL;
@@ -125,8 +109,9 @@ enum {
125
109
  };
126
110
 
127
111
  // Check if the field is a well known wrapper type
128
- static bool is_wrapper_type_field(const upb_fielddef* field) {
129
- char* field_type_name = rb_class2name(field_type_class(field));
112
+ static bool is_wrapper_type_field(const MessageLayout* layout,
113
+ const upb_fielddef* field) {
114
+ const char* field_type_name = rb_class2name(field_type_class(layout, field));
130
115
 
131
116
  return strcmp(field_type_name, "Google::Protobuf::DoubleValue") == 0 ||
132
117
  strcmp(field_type_name, "Google::Protobuf::FloatValue") == 0 ||
@@ -140,26 +125,34 @@ static bool is_wrapper_type_field(const upb_fielddef* field) {
140
125
  }
141
126
 
142
127
  // Get a new Ruby wrapper type and set the initial value
143
- static VALUE ruby_wrapper_type(const upb_fielddef* field, const VALUE* value) {
144
- if (is_wrapper_type_field(field) && value != Qnil) {
128
+ static VALUE ruby_wrapper_type(const MessageLayout* layout,
129
+ const upb_fielddef* field, const VALUE value) {
130
+ if (is_wrapper_type_field(layout, field) && value != Qnil) {
145
131
  VALUE hash = rb_hash_new();
146
132
  rb_hash_aset(hash, rb_str_new2("value"), value);
147
- VALUE args[1] = { hash };
148
- return rb_class_new_instance(1, args, field_type_class(field));
133
+ {
134
+ VALUE args[1] = {hash};
135
+ return rb_class_new_instance(1, args, field_type_class(layout, field));
136
+ }
149
137
  }
150
138
  return Qnil;
151
139
  }
152
140
 
153
141
  static int extract_method_call(VALUE method_name, MessageHeader* self,
154
- const upb_fielddef **f, const upb_oneofdef **o) {
155
- Check_Type(method_name, T_SYMBOL);
156
-
157
- VALUE method_str = rb_id2str(SYM2ID(method_name));
158
- char* name = RSTRING_PTR(method_str);
159
- size_t name_len = RSTRING_LEN(method_str);
142
+ const upb_fielddef **f, const upb_oneofdef **o) {
143
+ VALUE method_str;
144
+ char* name;
145
+ size_t name_len;
160
146
  int accessor_type;
161
147
  const upb_oneofdef* test_o;
162
148
  const upb_fielddef* test_f;
149
+ bool has_field;
150
+
151
+ Check_Type(method_name, T_SYMBOL);
152
+
153
+ method_str = rb_id2str(SYM2ID(method_name));
154
+ name = RSTRING_PTR(method_str);
155
+ name_len = RSTRING_LEN(method_str);
163
156
 
164
157
  if (name[name_len - 1] == '=') {
165
158
  accessor_type = METHOD_SETTER;
@@ -168,13 +161,13 @@ static int extract_method_call(VALUE method_name, MessageHeader* self,
168
161
  // we don't strip the prefix.
169
162
  } else if (strncmp("clear_", name, 6) == 0 &&
170
163
  !upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
171
- &test_f, &test_o)) {
164
+ &test_f, &test_o)) {
172
165
  accessor_type = METHOD_CLEAR;
173
166
  name = name + 6;
174
167
  name_len = name_len - 6;
175
168
  } else if (strncmp("has_", name, 4) == 0 && name[name_len - 1] == '?' &&
176
169
  !upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
177
- &test_f, &test_o)) {
170
+ &test_f, &test_o)) {
178
171
  accessor_type = METHOD_PRESENCE;
179
172
  name = name + 4;
180
173
  name_len = name_len - 5;
@@ -182,25 +175,26 @@ static int extract_method_call(VALUE method_name, MessageHeader* self,
182
175
  accessor_type = METHOD_GETTER;
183
176
  }
184
177
 
185
- bool has_field = upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
186
- &test_f, &test_o);
178
+ has_field = upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
179
+ &test_f, &test_o);
187
180
 
188
181
  // Look for wrapper type accessor of the form <field_name>_as_value
189
182
  if (!has_field &&
190
183
  (accessor_type == METHOD_GETTER || accessor_type == METHOD_SETTER) &&
191
184
  name_len > 9 && strncmp(name + name_len - 9, "_as_value", 9) == 0) {
192
- // Find the field name
185
+ const upb_oneofdef* test_o_wrapper;
186
+ const upb_fielddef* test_f_wrapper;
193
187
  char wrapper_field_name[name_len - 8];
188
+
189
+ // Find the field name
194
190
  strncpy(wrapper_field_name, name, name_len - 9);
195
- wrapper_field_name[name_len - 7] = '\0';
191
+ wrapper_field_name[name_len - 9] = '\0';
196
192
 
197
193
  // Check if field exists and is a wrapper type
198
- const upb_oneofdef* test_o_wrapper;
199
- const upb_fielddef* test_f_wrapper;
200
- if (upb_msgdef_lookupname(self->descriptor->msgdef, wrapper_field_name, name_len - 9,
201
- &test_f_wrapper, &test_o_wrapper) &&
194
+ if (upb_msgdef_lookupname(self->descriptor->msgdef, wrapper_field_name,
195
+ name_len - 9, &test_f_wrapper, &test_o_wrapper) &&
202
196
  upb_fielddef_type(test_f_wrapper) == UPB_TYPE_MESSAGE &&
203
- is_wrapper_type_field(test_f_wrapper)) {
197
+ is_wrapper_type_field(self->descriptor->layout, test_f_wrapper)) {
204
198
  // It does exist!
205
199
  has_field = true;
206
200
  if (accessor_type == METHOD_SETTER) {
@@ -216,17 +210,17 @@ static int extract_method_call(VALUE method_name, MessageHeader* self,
216
210
  // Look for enum accessor of the form <enum_name>_const
217
211
  if (!has_field && accessor_type == METHOD_GETTER &&
218
212
  name_len > 6 && strncmp(name + name_len - 6, "_const", 6) == 0) {
213
+ const upb_oneofdef* test_o_enum;
214
+ const upb_fielddef* test_f_enum;
215
+ char enum_name[name_len - 5];
219
216
 
220
217
  // Find enum field name
221
- char enum_name[name_len - 5];
222
218
  strncpy(enum_name, name, name_len - 6);
223
- enum_name[name_len - 4] = '\0';
219
+ enum_name[name_len - 6] = '\0';
224
220
 
225
221
  // Check if enum field exists
226
- const upb_oneofdef* test_o_enum;
227
- const upb_fielddef* test_f_enum;
228
222
  if (upb_msgdef_lookupname(self->descriptor->msgdef, enum_name, name_len - 6,
229
- &test_f_enum, &test_o_enum) &&
223
+ &test_f_enum, &test_o_enum) &&
230
224
  upb_fielddef_type(test_f_enum) == UPB_TYPE_ENUM) {
231
225
  // It does exist!
232
226
  has_field = true;
@@ -285,13 +279,14 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
285
279
  MessageHeader* self;
286
280
  const upb_oneofdef* o;
287
281
  const upb_fielddef* f;
282
+ int accessor_type;
288
283
 
289
284
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
290
285
  if (argc < 1) {
291
286
  rb_raise(rb_eArgError, "Expected method name as first argument.");
292
287
  }
293
288
 
294
- int accessor_type = extract_method_call(argv[0], self, &f, &o);
289
+ accessor_type = extract_method_call(argv[0], self, &f, &o);
295
290
  if (accessor_type == METHOD_UNKNOWN || (o == NULL && f == NULL) ) {
296
291
  return rb_call_super(argc, argv);
297
292
  } else if (accessor_type == METHOD_SETTER || accessor_type == METHOD_WRAPPER_SETTER) {
@@ -305,11 +300,12 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
305
300
 
306
301
  // Return which of the oneof fields are set
307
302
  if (o != NULL) {
303
+ const upb_fielddef* oneof_field = which_oneof_field(self, o);
304
+
308
305
  if (accessor_type == METHOD_SETTER) {
309
306
  rb_raise(rb_eRuntimeError, "Oneof accessors are read-only.");
310
307
  }
311
308
 
312
- const upb_fielddef* oneof_field = which_oneof_field(self, o);
313
309
  if (accessor_type == METHOD_PRESENCE) {
314
310
  return oneof_field == NULL ? Qfalse : Qtrue;
315
311
  } else if (accessor_type == METHOD_CLEAR) {
@@ -338,20 +334,21 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
338
334
  }
339
335
  return value;
340
336
  } else if (accessor_type == METHOD_WRAPPER_SETTER) {
341
- VALUE wrapper = ruby_wrapper_type(f, argv[1]);
337
+ VALUE wrapper = ruby_wrapper_type(self->descriptor->layout, f, argv[1]);
342
338
  layout_set(self->descriptor->layout, Message_data(self), f, wrapper);
343
339
  return Qnil;
344
340
  } else if (accessor_type == METHOD_ENUM_GETTER) {
345
- VALUE enum_type = field_type_class(f);
341
+ VALUE enum_type = field_type_class(self->descriptor->layout, f);
346
342
  VALUE method = rb_intern("const_get");
347
343
  VALUE raw_value = layout_get(self->descriptor->layout, Message_data(self), f);
348
344
 
349
345
  // Map repeated fields to a new type with ints
350
346
  if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) {
351
347
  int array_size = FIX2INT(rb_funcall(raw_value, rb_intern("length"), 0));
348
+ int i;
352
349
  VALUE array_args[1] = { ID2SYM(rb_intern("int64")) };
353
350
  VALUE array = rb_class_new_instance(1, array_args, CLASS_OF(raw_value));
354
- for (int i = 0; i < array_size; i++) {
351
+ for (i = 0; i < array_size; i++) {
355
352
  VALUE entry = rb_funcall(enum_type, method, 1, rb_funcall(raw_value,
356
353
  rb_intern("at"), 1, INT2NUM(i)));
357
354
  rb_funcall(array, rb_intern("push"), 1, entry);
@@ -370,13 +367,14 @@ VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) {
370
367
  MessageHeader* self;
371
368
  const upb_oneofdef* o;
372
369
  const upb_fielddef* f;
370
+ int accessor_type;
373
371
 
374
372
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
375
373
  if (argc < 1) {
376
374
  rb_raise(rb_eArgError, "Expected method name as first argument.");
377
375
  }
378
376
 
379
- int accessor_type = extract_method_call(argv[0], self, &f, &o);
377
+ accessor_type = extract_method_call(argv[0], self, &f, &o);
380
378
  if (accessor_type == METHOD_UNKNOWN) {
381
379
  return rb_call_super(argc, argv);
382
380
  } else if (o != NULL) {
@@ -386,15 +384,10 @@ VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) {
386
384
  }
387
385
  }
388
386
 
389
- VALUE create_submsg_from_hash(const upb_fielddef *f, VALUE hash) {
390
- const upb_def *d = upb_fielddef_subdef(f);
391
- assert(d != NULL);
392
-
393
- VALUE descriptor = get_def_obj(d);
394
- VALUE msgclass = rb_funcall(descriptor, rb_intern("msgclass"), 0, NULL);
395
-
387
+ VALUE create_submsg_from_hash(const MessageLayout* layout,
388
+ const upb_fielddef* f, VALUE hash) {
396
389
  VALUE args[1] = { hash };
397
- return rb_class_new_instance(1, args, msgclass);
390
+ return rb_class_new_instance(1, args, field_type_class(layout, f));
398
391
  }
399
392
 
400
393
  int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
@@ -434,6 +427,7 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
434
427
  Map_merge_into_self(map, val);
435
428
  } else if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) {
436
429
  VALUE ary;
430
+ int i;
437
431
 
438
432
  if (TYPE(val) != T_ARRAY) {
439
433
  rb_raise(rb_eArgError,
@@ -441,17 +435,17 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
441
435
  name, rb_class2name(CLASS_OF(val)));
442
436
  }
443
437
  ary = layout_get(self->descriptor->layout, Message_data(self), f);
444
- for (int i = 0; i < RARRAY_LEN(val); i++) {
438
+ for (i = 0; i < RARRAY_LEN(val); i++) {
445
439
  VALUE entry = rb_ary_entry(val, i);
446
440
  if (TYPE(entry) == T_HASH && upb_fielddef_issubmsg(f)) {
447
- entry = create_submsg_from_hash(f, entry);
441
+ entry = create_submsg_from_hash(self->descriptor->layout, f, entry);
448
442
  }
449
443
 
450
444
  RepeatedField_push(ary, entry);
451
445
  }
452
446
  } else {
453
447
  if (TYPE(val) == T_HASH && upb_fielddef_issubmsg(f)) {
454
- val = create_submsg_from_hash(f, val);
448
+ val = create_submsg_from_hash(self->descriptor->layout, f, val);
455
449
  }
456
450
 
457
451
  layout_set(self->descriptor->layout, Message_data(self), f, val);
@@ -472,7 +466,11 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
472
466
  * Message class are provided on each concrete message class.
473
467
  */
474
468
  VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
469
+ MessageHeader* self;
475
470
  VALUE hash_args;
471
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
472
+
473
+ layout_init(self->descriptor->layout, Message_data(self));
476
474
 
477
475
  if (argc == 0) {
478
476
  return Qnil;
@@ -608,17 +606,18 @@ VALUE Message_to_h(VALUE _self) {
608
606
  !upb_msg_field_done(&it);
609
607
  upb_msg_field_next(&it)) {
610
608
  const upb_fielddef* field = upb_msg_iter_field(&it);
609
+ VALUE msg_value;
610
+ VALUE msg_key;
611
611
 
612
612
  // For proto2, do not include fields which are not set.
613
613
  if (upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2 &&
614
- field_contains_hasbit(self->descriptor->layout, field) &&
615
- !layout_has(self->descriptor->layout, Message_data(self), field)) {
614
+ field_contains_hasbit(self->descriptor->layout, field) &&
615
+ !layout_has(self->descriptor->layout, Message_data(self), field)) {
616
616
  continue;
617
617
  }
618
618
 
619
- VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self),
620
- field);
621
- VALUE msg_key = ID2SYM(rb_intern(upb_fielddef_name(field)));
619
+ msg_value = layout_get(self->descriptor->layout, Message_data(self), field);
620
+ msg_key = ID2SYM(rb_intern(upb_fielddef_name(field)));
622
621
  if (is_map_field(field)) {
623
622
  msg_value = Map_to_h(msg_value);
624
623
  } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
@@ -629,7 +628,8 @@ VALUE Message_to_h(VALUE _self) {
629
628
  }
630
629
 
631
630
  if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
632
- for (int i = 0; i < RARRAY_LEN(msg_value); i++) {
631
+ int i;
632
+ for (i = 0; i < RARRAY_LEN(msg_value); i++) {
633
633
  VALUE elem = rb_ary_entry(msg_value, i);
634
634
  rb_ary_store(msg_value, i, Message_to_h(elem));
635
635
  }
@@ -696,17 +696,11 @@ VALUE Message_descriptor(VALUE klass) {
696
696
  return rb_ivar_get(klass, descriptor_instancevar_interned);
697
697
  }
698
698
 
699
- VALUE build_class_from_descriptor(Descriptor* desc) {
699
+ VALUE build_class_from_descriptor(VALUE descriptor) {
700
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
700
701
  const char *name;
701
702
  VALUE klass;
702
703
 
703
- if (desc->layout == NULL) {
704
- desc->layout = create_layout(desc->msgdef);
705
- }
706
- if (desc->fill_method == NULL) {
707
- desc->fill_method = new_fillmsg_decodermethod(desc, &desc->fill_method);
708
- }
709
-
710
704
  name = upb_msgdef_fullname(desc->msgdef);
711
705
  if (name == NULL) {
712
706
  rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name.");
@@ -717,8 +711,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
717
711
  // their own toplevel constant class name.
718
712
  rb_intern("Message"),
719
713
  rb_cObject);
720
- rb_ivar_set(klass, descriptor_instancevar_interned,
721
- get_def_obj(desc->msgdef));
714
+ rb_ivar_set(klass, descriptor_instancevar_interned, descriptor);
722
715
  rb_define_alloc_func(klass, Message_alloc);
723
716
  rb_require("google/protobuf/message_exts");
724
717
  rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts"));
@@ -802,7 +795,8 @@ VALUE enum_descriptor(VALUE self) {
802
795
  return rb_ivar_get(self, descriptor_instancevar_interned);
803
796
  }
804
797
 
805
- VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) {
798
+ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
799
+ EnumDescriptor* enumdesc = ruby_to_EnumDescriptor(_enumdesc);
806
800
  VALUE mod = rb_define_module_id(
807
801
  rb_intern(upb_enumdef_fullname(enumdesc->enumdef)));
808
802
 
@@ -823,8 +817,7 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) {
823
817
  rb_define_singleton_method(mod, "lookup", enum_lookup, 1);
824
818
  rb_define_singleton_method(mod, "resolve", enum_resolve, 1);
825
819
  rb_define_singleton_method(mod, "descriptor", enum_descriptor, 0);
826
- rb_ivar_set(mod, descriptor_instancevar_interned,
827
- get_def_obj(enumdesc->enumdef));
820
+ rb_ivar_set(mod, descriptor_instancevar_interned, _enumdesc);
828
821
 
829
822
  return mod;
830
823
  }