ruby/ext/google/protobuf_c/storage.c
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2014 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #include "protobuf.h"
32 
33 #include <math.h>
34 
35 #include <ruby/encoding.h>
36 
37 // -----------------------------------------------------------------------------
38 // Ruby <-> native slot management.
39 // -----------------------------------------------------------------------------
40 
41 #define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
42 #define DEREF_OFFSET(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs)
43 #define DEREF(memory, type) *(type*)(memory)
44 
46  switch (type) {
47  case UPB_TYPE_FLOAT: return 4;
48  case UPB_TYPE_DOUBLE: return 8;
49  case UPB_TYPE_BOOL: return 1;
50  case UPB_TYPE_STRING: return sizeof(VALUE);
51  case UPB_TYPE_BYTES: return sizeof(VALUE);
52  case UPB_TYPE_MESSAGE: return sizeof(VALUE);
53  case UPB_TYPE_ENUM: return 4;
54  case UPB_TYPE_INT32: return 4;
55  case UPB_TYPE_INT64: return 8;
56  case UPB_TYPE_UINT32: return 4;
57  case UPB_TYPE_UINT64: return 8;
58  default: return 0;
59  }
60 }
61 
62 static bool is_ruby_num(VALUE value) {
63  return (TYPE(value) == T_FLOAT ||
64  TYPE(value) == T_FIXNUM ||
65  TYPE(value) == T_BIGNUM);
66 }
67 
69  if (!is_ruby_num(val)) {
70  rb_raise(cTypeError, "Expected number type for integral field '%s' (given %s).",
71  name, rb_class2name(CLASS_OF(val)));
72  }
73 
74  // NUM2{INT,UINT,LL,ULL} macros do the appropriate range checks on upper
75  // bound; we just need to do precision checks (i.e., disallow rounding) and
76  // check for < 0 on unsigned types.
77  if (TYPE(val) == T_FLOAT) {
78  double dbl_val = NUM2DBL(val);
79  if (floor(dbl_val) != dbl_val) {
80  rb_raise(rb_eRangeError,
81  "Non-integral floating point value assigned to integer field '%s' (given %s).",
82  name, rb_class2name(CLASS_OF(val)));
83  }
84  }
86  if (NUM2DBL(val) < 0) {
87  rb_raise(rb_eRangeError,
88  "Assigning negative value to unsigned integer field '%s' (given %s).",
89  name, rb_class2name(CLASS_OF(val)));
90  }
91  }
92 }
93 
95  rb_encoding* desired_encoding = (type == UPB_TYPE_STRING) ?
97  VALUE desired_encoding_value = rb_enc_from_encoding(desired_encoding);
98 
99  if (rb_obj_encoding(value) != desired_encoding_value || !OBJ_FROZEN(value)) {
100  // Note: this will not duplicate underlying string data unless necessary.
101  value = rb_str_encode(value, desired_encoding_value, 0, Qnil);
102 
103  if (type == UPB_TYPE_STRING &&
104  rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
105  rb_raise(rb_eEncodingError, "String is invalid UTF-8");
106  }
107 
108  // Ensure the data remains valid. Since we called #encode a moment ago,
109  // this does not freeze the string the user assigned.
110  rb_obj_freeze(value);
111  }
112 
113  return value;
114 }
115 
116 void native_slot_set(const char* name,
117  upb_fieldtype_t type, VALUE type_class,
118  void* memory, VALUE value) {
119  native_slot_set_value_and_case(name, type, type_class, memory, value, NULL, 0);
120 }
121 
123  upb_fieldtype_t type, VALUE type_class,
124  void* memory, VALUE value,
125  uint32_t* case_memory,
126  uint32_t case_number) {
127  // Note that in order to atomically change the value in memory and the case
128  // value (w.r.t. Ruby VM calls), we must set the value at |memory| only after
129  // all Ruby VM calls are complete. The case is then set at the bottom of this
130  // function.
131  switch (type) {
132  case UPB_TYPE_FLOAT:
133  if (!is_ruby_num(value)) {
134  rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).",
135  name, rb_class2name(CLASS_OF(value)));
136  }
137  DEREF(memory, float) = NUM2DBL(value);
138  break;
139  case UPB_TYPE_DOUBLE:
140  if (!is_ruby_num(value)) {
141  rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).",
142  name, rb_class2name(CLASS_OF(value)));
143  }
144  DEREF(memory, double) = NUM2DBL(value);
145  break;
146  case UPB_TYPE_BOOL: {
147  int8_t val = -1;
148  if (value == Qtrue) {
149  val = 1;
150  } else if (value == Qfalse) {
151  val = 0;
152  } else {
153  rb_raise(cTypeError, "Invalid argument for boolean field '%s' (given %s).",
154  name, rb_class2name(CLASS_OF(value)));
155  }
156  DEREF(memory, int8_t) = val;
157  break;
158  }
159  case UPB_TYPE_STRING:
160  if (CLASS_OF(value) == rb_cSymbol) {
161  value = rb_funcall(value, rb_intern("to_s"), 0);
162  } else if (CLASS_OF(value) != rb_cString) {
163  rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).",
164  name, rb_class2name(CLASS_OF(value)));
165  }
166 
168  break;
169 
170  case UPB_TYPE_BYTES: {
171  if (CLASS_OF(value) != rb_cString) {
172  rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).",
173  name, rb_class2name(CLASS_OF(value)));
174  }
175 
177  break;
178  }
179  case UPB_TYPE_MESSAGE: {
180  if (CLASS_OF(value) == CLASS_OF(Qnil)) {
181  value = Qnil;
182  } else if (CLASS_OF(value) != type_class) {
183  // check for possible implicit conversions
184  VALUE converted_value = Qnil;
185  const char* field_type_name = rb_class2name(type_class);
186 
187  if (strcmp(field_type_name, "Google::Protobuf::Timestamp") == 0 &&
188  rb_obj_is_kind_of(value, rb_cTime)) {
189  // Time -> Google::Protobuf::Timestamp
190  VALUE hash = rb_hash_new();
191  rb_hash_aset(hash, rb_str_new2("seconds"),
192  rb_funcall(value, rb_intern("to_i"), 0));
193  rb_hash_aset(hash, rb_str_new2("nanos"),
194  rb_funcall(value, rb_intern("nsec"), 0));
195  {
196  VALUE args[1] = {hash};
197  converted_value = rb_class_new_instance(1, args, type_class);
198  }
199  } else if (strcmp(field_type_name, "Google::Protobuf::Duration") == 0 &&
200  rb_obj_is_kind_of(value, rb_cNumeric)) {
201  // Numeric -> Google::Protobuf::Duration
202  VALUE hash = rb_hash_new();
203  rb_hash_aset(hash, rb_str_new2("seconds"),
204  rb_funcall(value, rb_intern("to_i"), 0));
205  {
206  VALUE n_value =
207  rb_funcall(value, rb_intern("remainder"), 1, INT2NUM(1));
208  n_value =
209  rb_funcall(n_value, rb_intern("*"), 1, INT2NUM(1000000000));
210  n_value = rb_funcall(n_value, rb_intern("round"), 0);
211  rb_hash_aset(hash, rb_str_new2("nanos"), n_value);
212  }
213  {
214  VALUE args[1] = { hash };
215  converted_value = rb_class_new_instance(1, args, type_class);
216  }
217  }
218 
219  // raise if no suitable conversaion could be found
220  if (converted_value == Qnil) {
221  rb_raise(cTypeError,
222  "Invalid type %s to assign to submessage field '%s'.",
223  rb_class2name(CLASS_OF(value)), name);
224  } else {
225  value = converted_value;
226  }
227  }
228  DEREF(memory, VALUE) = value;
229  break;
230  }
231  case UPB_TYPE_ENUM: {
232  int32_t int_val = 0;
233  if (TYPE(value) == T_STRING) {
234  value = rb_funcall(value, rb_intern("to_sym"), 0);
235  } else if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) {
236  rb_raise(cTypeError,
237  "Expected number or symbol type for enum field '%s'.", name);
238  }
239  if (TYPE(value) == T_SYMBOL) {
240  // Ensure that the given symbol exists in the enum module.
241  VALUE lookup = rb_funcall(type_class, rb_intern("resolve"), 1, value);
242  if (lookup == Qnil) {
243  rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
244  } else {
245  int_val = NUM2INT(lookup);
246  }
247  } else {
249  int_val = NUM2INT(value);
250  }
251  DEREF(memory, int32_t) = int_val;
252  break;
253  }
254  case UPB_TYPE_INT32:
255  case UPB_TYPE_INT64:
256  case UPB_TYPE_UINT32:
257  case UPB_TYPE_UINT64:
259  switch (type) {
260  case UPB_TYPE_INT32:
261  DEREF(memory, int32_t) = NUM2INT(value);
262  break;
263  case UPB_TYPE_INT64:
264  DEREF(memory, int64_t) = NUM2LL(value);
265  break;
266  case UPB_TYPE_UINT32:
267  DEREF(memory, uint32_t) = NUM2UINT(value);
268  break;
269  case UPB_TYPE_UINT64:
270  DEREF(memory, uint64_t) = NUM2ULL(value);
271  break;
272  default:
273  break;
274  }
275  break;
276  default:
277  break;
278  }
279 
280  if (case_memory != NULL) {
281  *case_memory = case_number;
282  }
283 }
284 
286  VALUE type_class,
287  const void* memory) {
288  switch (type) {
289  case UPB_TYPE_FLOAT:
290  return DBL2NUM(DEREF(memory, float));
291  case UPB_TYPE_DOUBLE:
292  return DBL2NUM(DEREF(memory, double));
293  case UPB_TYPE_BOOL:
294  return DEREF(memory, int8_t) ? Qtrue : Qfalse;
295  case UPB_TYPE_STRING:
296  case UPB_TYPE_BYTES:
297  case UPB_TYPE_MESSAGE:
298  return DEREF(memory, VALUE);
299  case UPB_TYPE_ENUM: {
300  int32_t val = DEREF(memory, int32_t);
301  VALUE symbol = enum_lookup(type_class, INT2NUM(val));
302  if (symbol == Qnil) {
303  return INT2NUM(val);
304  } else {
305  return symbol;
306  }
307  }
308  case UPB_TYPE_INT32:
309  return INT2NUM(DEREF(memory, int32_t));
310  case UPB_TYPE_INT64:
311  return LL2NUM(DEREF(memory, int64_t));
312  case UPB_TYPE_UINT32:
313  return UINT2NUM(DEREF(memory, uint32_t));
314  case UPB_TYPE_UINT64:
315  return ULL2NUM(DEREF(memory, uint64_t));
316  default:
317  return Qnil;
318  }
319 }
320 
321 void native_slot_init(upb_fieldtype_t type, void* memory) {
322  switch (type) {
323  case UPB_TYPE_FLOAT:
324  DEREF(memory, float) = 0.0;
325  break;
326  case UPB_TYPE_DOUBLE:
327  DEREF(memory, double) = 0.0;
328  break;
329  case UPB_TYPE_BOOL:
330  DEREF(memory, int8_t) = 0;
331  break;
332  case UPB_TYPE_STRING:
333  case UPB_TYPE_BYTES:
334  DEREF(memory, VALUE) = rb_str_new2("");
335  rb_enc_associate(DEREF(memory, VALUE), (type == UPB_TYPE_BYTES) ?
337  break;
338  case UPB_TYPE_MESSAGE:
339  DEREF(memory, VALUE) = Qnil;
340  break;
341  case UPB_TYPE_ENUM:
342  case UPB_TYPE_INT32:
343  DEREF(memory, int32_t) = 0;
344  break;
345  case UPB_TYPE_INT64:
346  DEREF(memory, int64_t) = 0;
347  break;
348  case UPB_TYPE_UINT32:
349  DEREF(memory, uint32_t) = 0;
350  break;
351  case UPB_TYPE_UINT64:
352  DEREF(memory, uint64_t) = 0;
353  break;
354  default:
355  break;
356  }
357 }
358 
359 void native_slot_mark(upb_fieldtype_t type, void* memory) {
360  switch (type) {
361  case UPB_TYPE_STRING:
362  case UPB_TYPE_BYTES:
363  case UPB_TYPE_MESSAGE:
364  rb_gc_mark(DEREF(memory, VALUE));
365  break;
366  default:
367  break;
368  }
369 }
370 
373 }
374 
376  switch (type) {
377  case UPB_TYPE_STRING:
378  case UPB_TYPE_BYTES: {
379  VALUE from_val = DEREF(from, VALUE);
380  DEREF(to, VALUE) = (from_val != Qnil) ?
381  rb_funcall(from_val, rb_intern("dup"), 0) : Qnil;
382  break;
383  }
384  case UPB_TYPE_MESSAGE: {
385  VALUE from_val = DEREF(from, VALUE);
386  DEREF(to, VALUE) = (from_val != Qnil) ?
387  Message_deep_copy(from_val) : Qnil;
388  break;
389  }
390  default:
392  }
393 }
394 
395 bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2) {
396  switch (type) {
397  case UPB_TYPE_STRING:
398  case UPB_TYPE_BYTES:
399  case UPB_TYPE_MESSAGE: {
400  VALUE val1 = DEREF(mem1, VALUE);
401  VALUE val2 = DEREF(mem2, VALUE);
402  VALUE ret = rb_funcall(val1, rb_intern("=="), 1, val2);
403  return ret == Qtrue;
404  }
405  default:
406  return !memcmp(mem1, mem2, native_slot_size(type));
407  }
408 }
409 
410 // -----------------------------------------------------------------------------
411 // Map field utilities.
412 // -----------------------------------------------------------------------------
413 
415  const upb_msgdef* subdef;
418  return NULL;
419  }
420  subdef = upb_fielddef_msgsubdef(field);
421  return upb_msgdef_mapentry(subdef) ? subdef : NULL;
422 }
423 
425  const upb_msgdef* subdef = tryget_map_entry_msgdef(field);
426  assert(subdef);
427  return subdef;
428 }
429 
431  const upb_msgdef* subdef = tryget_map_entry_msgdef(field);
432  if (subdef == NULL) return false;
433 
434  // Map fields are a proto3 feature.
435  // If we're using proto2 syntax we need to fallback to the repeated field.
436  return upb_msgdef_syntax(subdef) == UPB_SYNTAX_PROTO3;
437 }
438 
440  const upb_msgdef* subdef = map_entry_msgdef(field);
441  return map_entry_key(subdef);
442 }
443 
445  const upb_msgdef* subdef = map_entry_msgdef(field);
446  return map_entry_value(subdef);
447 }
448 
450  const upb_fielddef* key_field = upb_msgdef_itof(msgdef, MAP_KEY_FIELD);
451  assert(key_field != NULL);
452  return key_field;
453 }
454 
456  const upb_fielddef* value_field = upb_msgdef_itof(msgdef, MAP_VALUE_FIELD);
457  assert(value_field != NULL);
458  return value_field;
459 }
460 
461 // -----------------------------------------------------------------------------
462 // Memory layout management.
463 // -----------------------------------------------------------------------------
464 
466  const upb_fielddef* field) {
469 }
470 
471 static size_t align_up_to(size_t offset, size_t granularity) {
472  // Granularity must be a power of two.
473  return (offset + granularity - 1) & ~(granularity - 1);
474 }
475 
479 }
480 
482  const upb_msgdef *msgdef = desc->msgdef;
484  int nfields = upb_msgdef_numfields(msgdef);
485  int noneofs = upb_msgdef_numoneofs(msgdef);
487  upb_msg_oneof_iter oit;
488  size_t off = 0;
489  size_t hasbit = 0;
490 
491  layout->empty_template = NULL;
492  layout->desc = desc;
493  desc->layout = layout;
494 
495  layout->fields = ALLOC_N(MessageField, nfields);
496  layout->oneofs = NULL;
497 
498  if (noneofs > 0) {
499  layout->oneofs = ALLOC_N(MessageOneof, noneofs);
500  }
501 
502  for (upb_msg_field_begin(&it, msgdef);
508  } else {
511  }
512  }
513 
514  if (hasbit != 0) {
515  off += (hasbit + 8 - 1) / 8;
516  }
517 
518  off = align_up_to(off, sizeof(VALUE));
519  layout->value_offset = off;
520  layout->repeated_count = 0;
521  layout->map_count = 0;
522  layout->value_count = 0;
523 
524  // Place all VALUE fields for repeated fields.
525  for (upb_msg_field_begin(&it, msgdef);
531  continue;
532  }
533 
535  off += sizeof(VALUE);
537  }
538 
539  // Place all VALUE fields for map fields.
540  for (upb_msg_field_begin(&it, msgdef);
546  continue;
547  }
548 
550  off += sizeof(VALUE);
551  layout->map_count++;
552  }
553 
555 
556  // Next place all other (non-oneof) VALUE fields.
557  for (upb_msg_field_begin(&it, msgdef);
563  continue;
564  }
565 
567  off += sizeof(VALUE);
568  layout->value_count++;
569  }
570 
571  // Now place all other (non-oneof) fields.
572  for (upb_msg_field_begin(&it, msgdef);
576  size_t field_size;
577 
579  continue;
580  }
581 
582  // Allocate |field_size| bytes for this field in the layout.
584 
585  // Align current offset up to |size| granularity.
586  off = align_up_to(off, field_size);
588  off += field_size;
589  }
590 
591  // Handle oneofs now -- we iterate over oneofs specifically and allocate only
592  // one slot per oneof.
593  //
594  // We assign all value slots first, then pack the 'case' fields at the end,
595  // since in the common case (modern 64-bit platform) these are 8 bytes and 4
596  // bytes respectively and we want to avoid alignment overhead.
597  //
598  // Note that we reserve 4 bytes (a uint32) per 'case' slot because the value
599  // space for oneof cases is conceptually as wide as field tag numbers. In
600  // practice, it's unlikely that a oneof would have more than e.g. 256 or 64K
601  // members (8 or 16 bits respectively), so conceivably we could assign
602  // consecutive case numbers and then pick a smaller oneof case slot size, but
603  // the complexity to implement this indirection is probably not worthwhile.
604  for (upb_msg_oneof_begin(&oit, msgdef);
605  !upb_msg_oneof_done(&oit);
606  upb_msg_oneof_next(&oit)) {
607  const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
608  upb_oneof_iter fit;
609 
610  // Always allocate NATIVE_SLOT_MAX_SIZE bytes, but share the slot between
611  // all fields.
612  size_t field_size = NATIVE_SLOT_MAX_SIZE;
613  // Align the offset.
614  off = align_up_to(off, field_size);
615  // Assign all fields in the oneof this same offset.
616  for (upb_oneof_begin(&fit, oneof);
617  !upb_oneof_done(&fit);
618  upb_oneof_next(&fit)) {
619  const upb_fielddef* field = upb_oneof_iter_field(&fit);
621  layout->oneofs[upb_oneofdef_index(oneof)].offset = off;
622  }
623  off += field_size;
624  }
625 
626  // Now the case fields.
627  for (upb_msg_oneof_begin(&oit, msgdef);
628  !upb_msg_oneof_done(&oit);
629  upb_msg_oneof_next(&oit)) {
630  const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
631  size_t field_size = sizeof(uint32_t);
632  // Align the offset.
633  off = (off + field_size - 1) & ~(field_size - 1);
635  off += field_size;
636  }
637 
638  layout->size = off;
639  layout->msgdef = msgdef;
640 
641  // Create the empty message template.
644 
649  }
650 }
651 
653  xfree(layout->empty_template);
654  xfree(layout->fields);
655  xfree(layout->oneofs);
656  xfree(layout);
657 }
658 
660  VALUE type_class = Qnil;
662  VALUE submsgdesc = get_msgdef_obj(layout->desc->descriptor_pool,
664  type_class = Descriptor_msgclass(submsgdesc);
665  } else if (upb_fielddef_type(field) == UPB_TYPE_ENUM) {
666  VALUE subenumdesc = get_enumdef_obj(layout->desc->descriptor_pool,
668  type_class = EnumDescriptor_enummodule(subenumdesc);
669  }
670  return type_class;
671 }
672 
674  const void* storage,
675  const upb_fielddef* field) {
676  return ((uint8_t *)storage) +
678 }
679 
681  const void* storage,
682  const upb_oneofdef* oneof) {
683  return (uint32_t*)(((uint8_t*)storage) +
685 }
686 
688  const upb_oneofdef* oneof) {
690  return *ptr & ~ONEOF_CASE_MASK;
691 }
692 
694  const void* storage,
695  const upb_fielddef* field) {
696  size_t hasbit = layout->fields[upb_fielddef_index(field)].hasbit;
697  assert(hasbit != MESSAGE_FIELD_NO_HASBIT);
698 
699  ((uint8_t*)storage)[hasbit / 8] |= 1 << (hasbit % 8);
700 }
701 
703  const void* storage,
704  const upb_fielddef* field) {
705  size_t hasbit = layout->fields[upb_fielddef_index(field)].hasbit;
706  assert(hasbit != MESSAGE_FIELD_NO_HASBIT);
707  ((uint8_t*)storage)[hasbit / 8] &= ~(1 << (hasbit % 8));
708 }
709 
711  const void* storage,
712  const upb_fielddef* field) {
713  size_t hasbit = layout->fields[upb_fielddef_index(field)].hasbit;
714  if (hasbit == MESSAGE_FIELD_NO_HASBIT) {
715  return false;
716  }
717 
718  return DEREF_OFFSET(
719  (uint8_t*)storage, hasbit / 8, char) & (1 << (hasbit % 8));
720 }
721 
723  const void* storage,
724  const upb_fielddef* field) {
726  return slot_is_hasbit_set(layout, storage, field) ? Qtrue : Qfalse;
727 }
728 
730  const void* storage,
731  const upb_fielddef* field) {
732  void* memory = slot_memory(layout, storage, field);
734 
737  }
738 
739  if (oneof) {
740  uint32_t* oneof_case = slot_oneof_case(layout, storage, oneof);
741  memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
742  *oneof_case = ONEOF_CASE_NONE;
743  } else if (is_map_field(field)) {
744  VALUE map = Qnil;
745 
746  const upb_fielddef* key_field = map_field_key(field);
747  const upb_fielddef* value_field = map_field_value(field);
748  VALUE type_class = field_type_class(layout, value_field);
749 
750  if (type_class != Qnil) {
751  VALUE args[3] = {
753  fieldtype_to_ruby(upb_fielddef_type(value_field)),
754  type_class,
755  };
756  map = rb_class_new_instance(3, args, cMap);
757  } else {
758  VALUE args[2] = {
760  fieldtype_to_ruby(upb_fielddef_type(value_field)),
761  };
762  map = rb_class_new_instance(2, args, cMap);
763  }
764 
765  DEREF(memory, VALUE) = map;
767  VALUE ary = Qnil;
768 
769  VALUE type_class = field_type_class(layout, field);
770 
771  if (type_class != Qnil) {
772  VALUE args[2] = {
774  type_class,
775  };
776  ary = rb_class_new_instance(2, args, cRepeatedField);
777  } else {
779  ary = rb_class_new_instance(1, args, cRepeatedField);
780  }
781 
782  DEREF(memory, VALUE) = ary;
783  } else {
785  field_type_class(layout, field), memory,
787  }
788 }
789 
791  switch (upb_fielddef_type(field)) {
792  case UPB_TYPE_FLOAT: return DBL2NUM(upb_fielddef_defaultfloat(field));
793  case UPB_TYPE_DOUBLE: return DBL2NUM(upb_fielddef_defaultdouble(field));
794  case UPB_TYPE_BOOL:
795  return upb_fielddef_defaultbool(field) ? Qtrue : Qfalse;
796  case UPB_TYPE_MESSAGE: return Qnil;
797  case UPB_TYPE_ENUM: {
800  const char *label = upb_enumdef_iton(enumdef, num);
801  if (label) {
802  return ID2SYM(rb_intern(label));
803  } else {
804  return INT2NUM(num);
805  }
806  }
807  case UPB_TYPE_INT32: return INT2NUM(upb_fielddef_defaultint32(field));
808  case UPB_TYPE_INT64: return LL2NUM(upb_fielddef_defaultint64(field));;
809  case UPB_TYPE_UINT32: return UINT2NUM(upb_fielddef_defaultuint32(field));
810  case UPB_TYPE_UINT64: return ULL2NUM(upb_fielddef_defaultuint64(field));
811  case UPB_TYPE_STRING:
812  case UPB_TYPE_BYTES: {
813  size_t size;
814  const char *str = upb_fielddef_defaultstr(field, &size);
815  return get_frozen_string(str, size,
817  }
818  default: return Qnil;
819  }
820 }
821 
823  const void* storage,
824  const upb_fielddef* field) {
825  void* memory = slot_memory(layout, storage, field);
827  bool field_set;
829  field_set = slot_is_hasbit_set(layout, storage, field);
830  } else {
831  field_set = true;
832  }
833 
834  if (oneof) {
835  uint32_t oneof_case = slot_read_oneof_case(layout, storage, oneof);
836  if (oneof_case != upb_fielddef_number(field)) {
837  return layout_get_default(field);
838  }
840  field_type_class(layout, field), memory);
842  return *((VALUE *)memory);
843  } else if (!field_set) {
844  return layout_get_default(field);
845  } else {
847  field_type_class(layout, field), memory);
848  }
849 }
850 
851 static void check_repeated_field_type(const MessageLayout* layout, VALUE val,
852  const upb_fielddef* field) {
853  RepeatedField* self;
855 
856  if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
857  RTYPEDDATA_TYPE(val) != &RepeatedField_type) {
858  rb_raise(cTypeError, "Expected repeated field array");
859  }
860 
861  self = ruby_to_RepeatedField(val);
862  if (self->field_type != upb_fielddef_type(field)) {
863  rb_raise(cTypeError, "Repeated field array has wrong element type");
864  }
865 
866  if (self->field_type_class != field_type_class(layout, field)) {
867  rb_raise(cTypeError, "Repeated field array has wrong message/enum class");
868  }
869 }
870 
871 static void check_map_field_type(const MessageLayout* layout, VALUE val,
872  const upb_fielddef* field) {
873  const upb_fielddef* key_field = map_field_key(field);
874  const upb_fielddef* value_field = map_field_value(field);
875  Map* self;
876 
877  if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
878  RTYPEDDATA_TYPE(val) != &Map_type) {
879  rb_raise(cTypeError, "Expected Map instance");
880  }
881 
882  self = ruby_to_Map(val);
883  if (self->key_type != upb_fielddef_type(key_field)) {
884  rb_raise(cTypeError, "Map key type does not match field's key type");
885  }
886  if (self->value_type != upb_fielddef_type(value_field)) {
887  rb_raise(cTypeError, "Map value type does not match field's value type");
888  }
889  if (self->value_type_class != field_type_class(layout, value_field)) {
890  rb_raise(cTypeError, "Map value type has wrong message/enum class");
891  }
892 }
893 
895  void* storage,
896  const upb_fielddef* field,
897  VALUE val) {
898  void* memory = slot_memory(layout, storage, field);
900 
901  if (oneof) {
902  uint32_t* oneof_case = slot_oneof_case(layout, storage, oneof);
903  if (val == Qnil) {
904  // Assigning nil to a oneof field clears the oneof completely.
905  *oneof_case = ONEOF_CASE_NONE;
906  memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
907  } else {
908  // The transition between field types for a single oneof (union) slot is
909  // somewhat complex because we need to ensure that a GC triggered at any
910  // point by a call into the Ruby VM sees a valid state for this field and
911  // does not either go off into the weeds (following what it thinks is a
912  // VALUE but is actually a different field type) or miss an object (seeing
913  // what it thinks is a primitive field but is actually a VALUE for the new
914  // field type).
915  //
916  // In order for the transition to be safe, the oneof case slot must be in
917  // sync with the value slot whenever the Ruby VM has been called. Thus, we
918  // use native_slot_set_value_and_case(), which ensures that both the value
919  // and case number are altered atomically (w.r.t. the Ruby VM).
920  uint32_t case_value = upb_fielddef_number(field);
922  case_value |= ONEOF_CASE_MASK;
923  }
924 
927  field_type_class(layout, field), memory, val, oneof_case, case_value);
928  }
929  } else if (is_map_field(field)) {
931  DEREF(memory, VALUE) = val;
934  DEREF(memory, VALUE) = val;
935  } else {
937  field_type_class(layout, field), memory, val);
938  }
939 
940  if (layout->fields[upb_fielddef_index(field)].hasbit !=
943  }
944 }
945 
947  VALUE* value = (VALUE*)CHARPTR_AT(storage, layout->value_offset);
948  int i;
949 
950  for (i = 0; i < layout->repeated_count; i++, value++) {
952  }
953 
954  for (i = 0; i < layout->map_count; i++, value++) {
956  }
957 }
958 
960  VALUE* values = (VALUE*)CHARPTR_AT(storage, layout->value_offset);
961  int noneofs = upb_msgdef_numoneofs(layout->msgdef);
962  int i;
963 
964  for (i = 0; i < layout->value_count; i++) {
965  rb_gc_mark(values[i]);
966  }
967 
968  for (i = 0; i < noneofs; i++) {
969  MessageOneof* oneof = &layout->oneofs[i];
970  uint32_t* case_ptr = (uint32_t*)CHARPTR_AT(storage, oneof->case_offset);
971  if (*case_ptr & ONEOF_CASE_MASK) {
972  rb_gc_mark(DEREF_OFFSET(storage, oneof->offset, VALUE));
973  }
974  }
975 }
976 
977 void layout_dup(MessageLayout* layout, void* to, void* from) {
984 
985  void* to_memory = slot_memory(layout, to, field);
986  void* from_memory = slot_memory(layout, from, field);
987 
988  if (oneof) {
989  uint32_t* to_oneof_case = slot_oneof_case(layout, to, oneof);
990  uint32_t* from_oneof_case = slot_oneof_case(layout, from, oneof);
991  if (slot_read_oneof_case(layout, from, oneof) ==
993  *to_oneof_case = *from_oneof_case;
994  native_slot_dup(upb_fielddef_type(field), to_memory, from_memory);
995  }
996  } else if (is_map_field(field)) {
997  DEREF(to_memory, VALUE) = Map_dup(DEREF(from_memory, VALUE));
999  DEREF(to_memory, VALUE) = RepeatedField_dup(DEREF(from_memory, VALUE));
1000  } else {
1002  if (!slot_is_hasbit_set(layout, from, field)) continue;
1004  }
1005 
1006  native_slot_dup(upb_fielddef_type(field), to_memory, from_memory);
1007  }
1008  }
1009 }
1010 
1015  upb_msg_field_next(&it)) {
1018 
1019  void* to_memory = slot_memory(layout, to, field);
1020  void* from_memory = slot_memory(layout, from, field);
1021 
1022  if (oneof) {
1023  uint32_t* to_oneof_case = slot_oneof_case(layout, to, oneof);
1024  uint32_t* from_oneof_case = slot_oneof_case(layout, from, oneof);
1025  if (slot_read_oneof_case(layout, from, oneof) ==
1027  *to_oneof_case = *from_oneof_case;
1028  native_slot_deep_copy(upb_fielddef_type(field), to_memory, from_memory);
1029  }
1030  } else if (is_map_field(field)) {
1031  DEREF(to_memory, VALUE) =
1032  Map_deep_copy(DEREF(from_memory, VALUE));
1033  } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
1034  DEREF(to_memory, VALUE) =
1035  RepeatedField_deep_copy(DEREF(from_memory, VALUE));
1036  } else {
1038  if (!slot_is_hasbit_set(layout, from, field)) continue;
1040  }
1041 
1042  native_slot_deep_copy(upb_fielddef_type(field), to_memory, from_memory);
1043  }
1044  }
1045 }
1046 
1047 VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2) {
1051  upb_msg_field_next(&it)) {
1054 
1055  void* msg1_memory = slot_memory(layout, msg1, field);
1056  void* msg2_memory = slot_memory(layout, msg2, field);
1057 
1058  if (oneof) {
1059  uint32_t* msg1_oneof_case = slot_oneof_case(layout, msg1, oneof);
1060  uint32_t* msg2_oneof_case = slot_oneof_case(layout, msg2, oneof);
1061  if (*msg1_oneof_case != *msg2_oneof_case ||
1062  (slot_read_oneof_case(layout, msg1, oneof) ==
1064  !native_slot_eq(upb_fielddef_type(field), msg1_memory,
1065  msg2_memory))) {
1066  return Qfalse;
1067  }
1068  } else if (is_map_field(field)) {
1069  if (!Map_eq(DEREF(msg1_memory, VALUE),
1070  DEREF(msg2_memory, VALUE))) {
1071  return Qfalse;
1072  }
1073  } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
1074  if (!RepeatedField_eq(DEREF(msg1_memory, VALUE),
1075  DEREF(msg2_memory, VALUE))) {
1076  return Qfalse;
1077  }
1078  } else {
1079  if (slot_is_hasbit_set(layout, msg1, field) !=
1080  slot_is_hasbit_set(layout, msg2, field) ||
1081  !native_slot_eq(upb_fielddef_type(field), msg1_memory, msg2_memory)) {
1082  return Qfalse;
1083  }
1084  }
1085  }
1086  return Qtrue;
1087 }
1088 
1091  st_index_t h = rb_hash_start(0);
1092  VALUE hash_sym = rb_intern("hash");
1095  upb_msg_field_next(&it)) {
1097  VALUE field_val = layout_get(layout, storage, field);
1098  h = rb_hash_uint(h, NUM2LONG(rb_funcall(field_val, hash_sym, 0)));
1099  }
1100  h = rb_hash_end(h);
1101 
1102  return INT2FIX(h);
1103 }
1104 
1106  VALUE str = rb_str_new2("");
1107 
1109  bool first = true;
1112  upb_msg_field_next(&it)) {
1114  VALUE field_val = layout_get(layout, storage, field);
1115 
1116  if (!first) {
1117  str = rb_str_cat2(str, ", ");
1118  } else {
1119  first = false;
1120  }
1121  str = rb_str_cat2(str, upb_fielddef_name(field));
1122  str = rb_str_cat2(str, ": ");
1123 
1124  str = rb_str_append(str, rb_funcall(field_val, rb_intern("inspect"), 0));
1125  }
1126 
1127  return str;
1128 }
xds_interop_client.str
str
Definition: xds_interop_client.py:487
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
UPB_TYPE_UINT64
@ UPB_TYPE_UINT64
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:487
grpc::testing::val1
const char val1[]
Definition: client_context_test_peer_test.cc:34
MessageLayout::size
size_t size
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:939
regen-readme.it
it
Definition: regen-readme.py:15
Map_eq
VALUE Map_eq(VALUE _self, VALUE _other)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:588
upb_fielddef_label
upb_label_t upb_fielddef_label(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3347
upb_oneof_done
bool upb_oneof_done(upb_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3718
kRubyStringUtf8Encoding
rb_encoding * kRubyStringUtf8Encoding
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c:77
upb_fielddef_defaultint64
int64_t upb_fielddef_defaultint64(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3427
upb_oneofdef_index
uint32_t upb_oneofdef_index(const upb_oneofdef *o)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3693
upb_msg_field_next
void upb_msg_field_next(upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3626
upb_fielddef_defaultdouble
double upb_fielddef_defaultdouble(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3457
slot_oneof_case
static uint32_t * slot_oneof_case(MessageLayout *layout, const void *storage, const upb_oneofdef *oneof)
Definition: ruby/ext/google/protobuf_c/storage.c:680
Map
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:451
EnumDescriptor_enummodule
VALUE EnumDescriptor_enummodule(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c:1397
UPB_TYPE_FLOAT
@ UPB_TYPE_FLOAT
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:476
memset
return memset(p, 0, total)
upb_msgdef_numoneofs
int upb_msgdef_numoneofs(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3603
native_slot_check_int_range_precision
void native_slot_check_int_range_precision(const char *name, upb_fieldtype_t type, VALUE val)
Definition: ruby/ext/google/protobuf_c/storage.c:68
MessageField::offset
size_t offset
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:930
ONEOF_CASE_NONE
#define ONEOF_CASE_NONE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1197
upb_fielddef_issubmsg
bool upb_fielddef_issubmsg(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3486
upb_fielddef_defaultfloat
float upb_fielddef_defaultfloat(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3452
upb_fielddef_defaultuint32
uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3442
ALLOC_N
#define ALLOC_N(class_name, n)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1488
layout_eq
VALUE layout_eq(MessageLayout *layout, void *msg1, void *msg2)
Definition: ruby/ext/google/protobuf_c/storage.c:1047
upb_fieldtype_t
upb_fieldtype_t
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:472
native_slot_encode_and_freeze_string
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value)
Definition: ruby/ext/google/protobuf_c/storage.c:94
layout_get_default
VALUE layout_get_default(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:790
slot_clear_hasbit
static void slot_clear_hasbit(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:702
upb_fielddef_defaultbool
bool upb_fielddef_defaultbool(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3447
RepeatedField_new_this_type
VALUE RepeatedField_new_this_type(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:326
upb_fielddef_defaultint32
int32_t upb_fielddef_defaultint32(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3432
field_type_class
VALUE field_type_class(const MessageLayout *layout, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:659
RepeatedField_dup
VALUE RepeatedField_dup(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:347
layout_init
void layout_init(MessageLayout *layout, void *storage)
Definition: ruby/ext/google/protobuf_c/storage.c:946
upb_msg_iter_field
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3632
upb_oneof_iter_field
upb_fielddef * upb_oneof_iter_field(const upb_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3722
layout_mark
void layout_mark(MessageLayout *layout, void *storage)
Definition: ruby/ext/google/protobuf_c/storage.c:959
map_field_value
const upb_fielddef * map_field_value(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:444
MessageField
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:929
UPB_TYPE_UINT32
@ UPB_TYPE_UINT32
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:478
native_slot_eq
bool native_slot_eq(upb_fieldtype_t type, void *mem1, void *mem2)
Definition: ruby/ext/google/protobuf_c/storage.c:395
setup.name
name
Definition: setup.py:542
upb_msg_oneof_done
bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3662
create_layout
void create_layout(Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/storage.c:481
slot_memory
static void * slot_memory(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:673
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
slot_set_hasbit
static void slot_set_hasbit(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:693
native_slot_size
size_t native_slot_size(upb_fieldtype_t type)
Definition: ruby/ext/google/protobuf_c/storage.c:45
MessageOneof::case_offset
uint32_t case_offset
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:514
align_up_to
static size_t align_up_to(size_t offset, size_t granularity)
Definition: ruby/ext/google/protobuf_c/storage.c:471
NATIVE_SLOT_MAX_SIZE
#define NATIVE_SLOT_MAX_SIZE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1030
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
RepeatedField_deep_copy
VALUE RepeatedField_deep_copy(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:368
layout_inspect
VALUE layout_inspect(MessageLayout *layout, void *storage)
Definition: ruby/ext/google/protobuf_c/storage.c:1105
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
Descriptor::descriptor_pool
VALUE descriptor_pool
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:125
MessageLayout::value_offset
uint32_t value_offset
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:525
upb_fielddef_msgsubdef
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3476
enum_lookup
VALUE enum_lookup(VALUE self, VALUE number)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/message.c:753
hash
uint64_t hash
Definition: ring_hash.cc:284
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
check_repeated_field_type
static void check_repeated_field_type(const MessageLayout *layout, VALUE val, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:851
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
UPB_TYPE_BYTES
@ UPB_TYPE_BYTES
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:482
upb_msg_field_done
bool upb_msg_field_done(const upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3628
upb_oneofdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2992
UPB_TYPE_ENUM
@ UPB_TYPE_ENUM
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:479
upb_msg_oneof_begin
void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3645
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
check_map_field_type
static void check_map_field_type(const MessageLayout *layout, VALUE val, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:871
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
upb_oneof_next
void upb_oneof_next(upb_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3714
MessageLayout::map_count
int map_count
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:528
layout_deep_copy
void layout_deep_copy(MessageLayout *layout, void *to, void *from)
Definition: ruby/ext/google/protobuf_c/storage.c:1011
gen_synthetic_protos.label
label
Definition: gen_synthetic_protos.py:102
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
Map_new_this_type
VALUE Map_new_this_type(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:498
upb_oneof_begin
void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3710
Map_dup
VALUE Map_dup(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:520
MessageOneof
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:512
map_entry_value
const upb_fielddef * map_entry_value(const upb_msgdef *msgdef)
Definition: ruby/ext/google/protobuf_c/storage.c:455
upb_inttable_iter
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:1113
fieldtype_to_ruby
VALUE fieldtype_to_ruby(upb_fieldtype_t type)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c:868
CHARPTR_AT
#define CHARPTR_AT(msg, ofs)
Definition: ruby/ext/google/protobuf_c/storage.c:41
Message_deep_copy
VALUE Message_deep_copy(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/message.c:513
grpc::testing::val2
const char val2[]
Definition: client_context_test_peer_test.cc:35
MessageLayout::fields
MessageField * fields
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:938
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
upb_fielddef_number
uint32_t upb_fielddef_number(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3351
native_slot_mark
void native_slot_mark(upb_fieldtype_t type, void *memory)
Definition: ruby/ext/google/protobuf_c/storage.c:359
upb_fielddef_isstring
bool upb_fielddef_isstring(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3490
upb_enumdef_iton
const char * upb_enumdef_iton(const upb_enumdef *def, int32_t num)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3283
MESSAGE_FIELD_NO_HASBIT
#define MESSAGE_FIELD_NO_HASBIT
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:505
upb_fielddef_ismap
bool upb_fielddef_ismap(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3503
native_slot_set_value_and_case
void native_slot_set_value_and_case(const char *name, upb_fieldtype_t type, VALUE type_class, void *memory, VALUE value, uint32_t *case_memory, uint32_t case_number)
Definition: ruby/ext/google/protobuf_c/storage.c:122
cRepeatedField
VALUE cRepeatedField
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:42
upb_fielddef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2934
layout_hash
VALUE layout_hash(MessageLayout *layout, void *storage)
Definition: ruby/ext/google/protobuf_c/storage.c:1089
Map_deep_copy
VALUE Map_deep_copy(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:548
layout
MessageLayout * layout
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:809
upb_msg_iter_oneof
const upb_oneofdef * upb_msg_iter_oneof(const upb_msg_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3666
upb_msgdef_numfields
int upb_msgdef_numfields(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3598
cTypeError
VALUE cTypeError
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c:35
UPB_TYPE_INT32
@ UPB_TYPE_INT32
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:477
upb_msgdef_itof
const upb_fielddef * upb_msgdef_itof(const upb_msgdef *m, uint32_t i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3556
protobuf.h
native_slot_deep_copy
void native_slot_deep_copy(upb_fieldtype_t type, void *to, void *from)
Definition: ruby/ext/google/protobuf_c/storage.c:375
MessageLayout::desc
const Descriptor * desc
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:519
map_entry_key
const upb_fielddef * map_entry_key(const upb_msgdef *msgdef)
Definition: ruby/ext/google/protobuf_c/storage.c:449
MAP_VALUE_FIELD
#define MAP_VALUE_FIELD
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1103
MessageField::hasbit
uint32_t hasbit
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:509
value
const char * value
Definition: hpack_parser_table.cc:165
upb_fielddef_index
uint32_t upb_fielddef_index(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3343
is_map_field
bool is_map_field(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:430
layout_set
void layout_set(MessageLayout *layout, void *storage, const upb_fielddef *field, VALUE val)
Definition: ruby/ext/google/protobuf_c/storage.c:894
native_slot_set
void native_slot_set(const char *name, upb_fieldtype_t type, VALUE type_class, void *memory, VALUE value)
Definition: ruby/ext/google/protobuf_c/storage.c:116
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
tryget_map_entry_msgdef
const upb_msgdef * tryget_map_entry_msgdef(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:414
is_ruby_num
static bool is_ruby_num(VALUE value)
Definition: ruby/ext/google/protobuf_c/storage.c:62
UPB_TYPE_STRING
@ UPB_TYPE_STRING
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:481
layout_dup
void layout_dup(MessageLayout *layout, void *to, void *from)
Definition: ruby/ext/google/protobuf_c/storage.c:977
upb_enumdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2984
MessageLayout::msgdef
const upb_msgdef * msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:937
get_enumdef_obj
VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef *def)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c:2264
field_contains_hasbit
bool field_contains_hasbit(MessageLayout *layout, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:465
slot_is_hasbit_set
static bool slot_is_hasbit_set(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:710
upb_fielddef_haspresence
bool upb_fielddef_haspresence(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3512
UPB_LABEL_REPEATED
@ UPB_LABEL_REPEATED
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:494
ALLOC
#define ALLOC(class_name)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1486
upb_msg_field_begin
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3622
upb_fielddef_enumsubdef
const upb_enumdef * upb_fielddef_enumsubdef(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3481
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
RepeatedField_type
const rb_data_type_t RepeatedField_type
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:37
MessageLayout::oneofs
MessageOneof * oneofs
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:523
MAP_KEY_FIELD
#define MAP_KEY_FIELD
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1102
ruby_to_RepeatedField
RepeatedField * ruby_to_RepeatedField(VALUE value)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:44
first
StrT first
Definition: cxa_demangle.cpp:4884
msgdef
const upb_msgdef * msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:808
DEREF
#define DEREF(memory, type)
Definition: ruby/ext/google/protobuf_c/storage.c:43
upb_msgdef_syntax
upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3544
ruby_to_Map
Map * ruby_to_Map(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:142
kRubyString8bitEncoding
rb_encoding * kRubyString8bitEncoding
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c:79
values
std::array< int64_t, Size > values
Definition: abseil-cpp/absl/container/btree_benchmark.cc:608
map_field_key
const upb_fielddef * map_field_key(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:439
xds_manager.num
num
Definition: xds_manager.py:56
enumdef
const upb_enumdef * enumdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:839
UPB_SYNTAX_PROTO3
@ UPB_SYNTAX_PROTO3
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:2973
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
Descriptor_msgclass
VALUE Descriptor_msgclass(VALUE _self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c:664
UPB_TYPE_MESSAGE
@ UPB_TYPE_MESSAGE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:483
lookup
static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v, uint32_t hash, eqlfunc_t *eql)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1417
cMap
VALUE cMap
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:140
layout_clear
void layout_clear(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:729
free_layout
void free_layout(MessageLayout *layout)
Definition: ruby/ext/google/protobuf_c/storage.c:652
TYPE
#define TYPE(u, l)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:8202
upb_msg_oneof_next
void upb_msg_oneof_next(upb_msg_oneof_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3654
DEREF_OFFSET
#define DEREF_OFFSET(msg, ofs, type)
Definition: ruby/ext/google/protobuf_c/storage.c:42
upb_fielddef_containingoneof
const upb_oneofdef * upb_fielddef_containingoneof(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3418
native_slot_init
void native_slot_init(upb_fieldtype_t type, void *memory)
Definition: ruby/ext/google/protobuf_c/storage.c:321
upb_msgdef_mapentry
bool upb_msgdef_mapentry(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3608
MessageLayout
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:936
is_value_field
bool is_value_field(const upb_fielddef *f)
Definition: ruby/ext/google/protobuf_c/storage.c:476
map_entry_msgdef
const upb_msgdef * map_entry_msgdef(const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:424
MessageOneof::offset
uint32_t offset
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:513
layout_get
VALUE layout_get(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:822
int8_t
signed char int8_t
Definition: stdint-msvc2008.h:75
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
get_frozen_string
VALUE get_frozen_string(const char *str, size_t size, bool binary)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c:50
RepeatedField_eq
VALUE RepeatedField_eq(VALUE _self, VALUE _other)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:424
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
MessageLayout::repeated_count
int repeated_count
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:527
upb_strtable_iter
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:1086
self
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:543
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
upb_fielddef_isseq
bool upb_fielddef_isseq(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3495
native_slot_dup
void native_slot_dup(upb_fieldtype_t type, void *to, void *from)
Definition: ruby/ext/google/protobuf_c/storage.c:371
slot_read_oneof_case
uint32_t slot_read_oneof_case(MessageLayout *layout, const void *storage, const upb_oneofdef *oneof)
Definition: ruby/ext/google/protobuf_c/storage.c:687
layout_has
VALUE layout_has(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:722
MessageLayout::value_count
int value_count
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:526
UPB_TYPE_DOUBLE
@ UPB_TYPE_DOUBLE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:485
Map_type
const rb_data_type_t Map_type
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/map.c:135
upb_fielddef_defaultuint64
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3437
absl::status_internal::storage
static ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES absl::base_internal::AtomicHook< StatusPayloadPrinter > storage
Definition: abseil-cpp/absl/status/status_payload_printer.cc:26
upb_fielddef_defaultstr
const char * upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3462
UPB_TYPE_BOOL
@ UPB_TYPE_BOOL
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:474
UPB_TYPE_INT64
@ UPB_TYPE_INT64
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:486
get_msgdef_obj
VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef *def)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c:2260
native_slot_get
VALUE native_slot_get(upb_fieldtype_t type, VALUE type_class, const void *memory)
Definition: ruby/ext/google/protobuf_c/storage.c:285
ONEOF_CASE_MASK
#define ONEOF_CASE_MASK
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:531
upb_msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2962
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
upb_fielddef_name
const char * upb_fielddef_name(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3367
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
upb_fielddef_type
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3304
MessageLayout::empty_template
void * empty_template
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:521
RepeatedField
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:403


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:19