google-protobuf 3.7.1-x86-linux → 3.8.0.rc.1-x86-linux

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bf0084d60f5ebd6fc64f1eb3b6f3e42f083495d31fa00127afeff29f4acaedb
4
- data.tar.gz: a057eefb7db5cfd23ad5002368cf4c76252f57c927ce00fd0134b4461a93d977
3
+ metadata.gz: 27315d86fe139488b17dada6f691586b8c113ec4846b3a4dd614486145c16b53
4
+ data.tar.gz: 8aff09c9c3b040ff4f3139cdc0cfefeaa2c5ea0ba1ec1e917ad6e9dff3ef59bd
5
5
  SHA512:
6
- metadata.gz: 2b2885ad8dd0e43394689df868ef5a3ff2962ac961d1f044a9cc3873c4364011d65eea5d2bdb6f3ae57ad7af35adcba81a1cb4050456f451abfbd2427c9df518
7
- data.tar.gz: 7755abbd47bb1c58ba9663dde8c08976c3d6d6db47ad964ff78b1fdd3c4b048ea478719001a0b3c5f99b7e4e58c2794c2242649df0930652ef7ecec2fcd74ea6
6
+ metadata.gz: 0a3caa68b6eccaf7607ac0c525edaae97a82a00fa42be3924bca9d5fcbedcc36e3d142655aeaa9d674331ce2c747ec481aa064830490840ef4bf62386f905327
7
+ data.tar.gz: caeef3132c503eadc1327b09e059f1601ff1189e9a8515b0d571e60ed42edc7fd1120d87bf454652f9e1426e6fc32bafeef1577ec7a367d494a9b4ebb222f352
@@ -886,7 +886,7 @@ VALUE FieldDescriptor_default_set(VALUE _self, VALUE default_value) {
886
886
  upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
887
887
 
888
888
  switch (upb_fielddef_type(mut_def)) {
889
- case UPB_TYPE_FLOAT:
889
+ case UPB_TYPE_FLOAT:
890
890
  upb_fielddef_setdefaultfloat(mut_def, NUM2DBL(default_value));
891
891
  break;
892
892
  case UPB_TYPE_DOUBLE:
@@ -902,16 +902,16 @@ VALUE FieldDescriptor_default_set(VALUE _self, VALUE default_value) {
902
902
  upb_fielddef_setdefaultbool(mut_def, RTEST(default_value));
903
903
  break;
904
904
  case UPB_TYPE_ENUM:
905
- case UPB_TYPE_INT32:
905
+ case UPB_TYPE_INT32:
906
906
  upb_fielddef_setdefaultint32(mut_def, NUM2INT(default_value));
907
907
  break;
908
- case UPB_TYPE_INT64:
908
+ case UPB_TYPE_INT64:
909
909
  upb_fielddef_setdefaultint64(mut_def, NUM2INT(default_value));
910
910
  break;
911
- case UPB_TYPE_UINT32:
911
+ case UPB_TYPE_UINT32:
912
912
  upb_fielddef_setdefaultuint32(mut_def, NUM2UINT(default_value));
913
913
  break;
914
- case UPB_TYPE_UINT64:
914
+ case UPB_TYPE_UINT64:
915
915
  upb_fielddef_setdefaultuint64(mut_def, NUM2UINT(default_value));
916
916
  break;
917
917
  case UPB_TYPE_STRING:
@@ -2085,7 +2085,7 @@ VALUE Builder_alloc(VALUE klass) {
2085
2085
 
2086
2086
  void Builder_register(VALUE module) {
2087
2087
  VALUE klass = rb_define_class_under(module, "Builder", rb_cObject);
2088
- rb_define_alloc_func(klass, Builder_alloc);
2088
+ rb_define_alloc_func(klass, Builder_alloc);
2089
2089
  rb_define_method(klass, "initialize", Builder_initialize, 0);
2090
2090
  rb_define_method(klass, "add_file", Builder_add_file, -1);
2091
2091
  rb_define_method(klass, "add_message", Builder_add_message, 1);
@@ -2230,7 +2230,7 @@ VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb) {
2230
2230
  VALUE def_rb = rb_ary_entry(self->pending_list, i);
2231
2231
  if (CLASS_OF(def_rb) == cDescriptor) {
2232
2232
  self->defs[i] = (upb_def*)ruby_to_Descriptor(def_rb)->msgdef;
2233
-
2233
+
2234
2234
  if (upb_filedef_syntax(upb_def_file(self->defs[i])) == UPB_SYNTAX_PROTO3) {
2235
2235
  proto3_validate_msgdef((const upb_msgdef*)self->defs[i]);
2236
2236
  }
@@ -386,6 +386,8 @@ VALUE Map_index(VALUE _self, VALUE key) {
386
386
  * was just inserted.
387
387
  */
388
388
  VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
389
+ rb_check_frozen(_self);
390
+
389
391
  Map* self = ruby_to_Map(_self);
390
392
 
391
393
  char keybuf[TABLE_KEY_BUF_LENGTH];
@@ -438,6 +440,8 @@ VALUE Map_has_key(VALUE _self, VALUE key) {
438
440
  * nil if none was present. Throws an exception if the key is of the wrong type.
439
441
  */
440
442
  VALUE Map_delete(VALUE _self, VALUE key) {
443
+ rb_check_frozen(_self);
444
+
441
445
  Map* self = ruby_to_Map(_self);
442
446
 
443
447
  char keybuf[TABLE_KEY_BUF_LENGTH];
@@ -461,6 +465,8 @@ VALUE Map_delete(VALUE _self, VALUE key) {
461
465
  * Removes all entries from the map.
462
466
  */
463
467
  VALUE Map_clear(VALUE _self) {
468
+ rb_check_frozen(_self);
469
+
464
470
  Map* self = ruby_to_Map(_self);
465
471
 
466
472
  // Uninit and reinit the table -- this is faster than iterating and doing a
@@ -118,9 +118,38 @@ enum {
118
118
  METHOD_GETTER = 1,
119
119
  METHOD_SETTER = 2,
120
120
  METHOD_CLEAR = 3,
121
- METHOD_PRESENCE = 4
121
+ METHOD_PRESENCE = 4,
122
+ METHOD_ENUM_GETTER = 5,
123
+ METHOD_WRAPPER_GETTER = 6,
124
+ METHOD_WRAPPER_SETTER = 7
122
125
  };
123
126
 
127
+ // 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));
130
+
131
+ return strcmp(field_type_name, "Google::Protobuf::DoubleValue") == 0 ||
132
+ strcmp(field_type_name, "Google::Protobuf::FloatValue") == 0 ||
133
+ strcmp(field_type_name, "Google::Protobuf::Int32Value") == 0 ||
134
+ strcmp(field_type_name, "Google::Protobuf::Int64Value") == 0 ||
135
+ strcmp(field_type_name, "Google::Protobuf::UInt32Value") == 0 ||
136
+ strcmp(field_type_name, "Google::Protobuf::UInt64Value") == 0 ||
137
+ strcmp(field_type_name, "Google::Protobuf::BoolValue") == 0 ||
138
+ strcmp(field_type_name, "Google::Protobuf::StringValue") == 0 ||
139
+ strcmp(field_type_name, "Google::Protobuf::BytesValue") == 0;
140
+ }
141
+
142
+ // 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) {
145
+ VALUE hash = rb_hash_new();
146
+ 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));
149
+ }
150
+ return Qnil;
151
+ }
152
+
124
153
  static int extract_method_call(VALUE method_name, MessageHeader* self,
125
154
  const upb_fielddef **f, const upb_oneofdef **o) {
126
155
  Check_Type(method_name, T_SYMBOL);
@@ -153,9 +182,62 @@ static int extract_method_call(VALUE method_name, MessageHeader* self,
153
182
  accessor_type = METHOD_GETTER;
154
183
  }
155
184
 
185
+ bool has_field = upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
186
+ &test_f, &test_o);
187
+
188
+ // Look for wrapper type accessor of the form <field_name>_as_value
189
+ if (!has_field &&
190
+ (accessor_type == METHOD_GETTER || accessor_type == METHOD_SETTER) &&
191
+ name_len > 9 && strncmp(name + name_len - 9, "_as_value", 9) == 0) {
192
+ // Find the field name
193
+ char wrapper_field_name[name_len - 8];
194
+ strncpy(wrapper_field_name, name, name_len - 9);
195
+ wrapper_field_name[name_len - 7] = '\0';
196
+
197
+ // 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) &&
202
+ upb_fielddef_type(test_f_wrapper) == UPB_TYPE_MESSAGE &&
203
+ is_wrapper_type_field(test_f_wrapper)) {
204
+ // It does exist!
205
+ has_field = true;
206
+ if (accessor_type == METHOD_SETTER) {
207
+ accessor_type = METHOD_WRAPPER_SETTER;
208
+ } else {
209
+ accessor_type = METHOD_WRAPPER_GETTER;
210
+ }
211
+ test_o = test_o_wrapper;
212
+ test_f = test_f_wrapper;
213
+ }
214
+ }
215
+
216
+ // Look for enum accessor of the form <enum_name>_const
217
+ if (!has_field && accessor_type == METHOD_GETTER &&
218
+ name_len > 6 && strncmp(name + name_len - 6, "_const", 6) == 0) {
219
+
220
+ // Find enum field name
221
+ char enum_name[name_len - 5];
222
+ strncpy(enum_name, name, name_len - 6);
223
+ enum_name[name_len - 4] = '\0';
224
+
225
+ // Check if enum field exists
226
+ const upb_oneofdef* test_o_enum;
227
+ const upb_fielddef* test_f_enum;
228
+ if (upb_msgdef_lookupname(self->descriptor->msgdef, enum_name, name_len - 6,
229
+ &test_f_enum, &test_o_enum) &&
230
+ upb_fielddef_type(test_f_enum) == UPB_TYPE_ENUM) {
231
+ // It does exist!
232
+ has_field = true;
233
+ accessor_type = METHOD_ENUM_GETTER;
234
+ test_o = test_o_enum;
235
+ test_f = test_f_enum;
236
+ }
237
+ }
238
+
156
239
  // Verify the name corresponds to a oneof or field in this message.
157
- if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len,
158
- &test_f, &test_o)) {
240
+ if (!has_field) {
159
241
  return METHOD_UNKNOWN;
160
242
  }
161
243
 
@@ -212,10 +294,11 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
212
294
  int accessor_type = extract_method_call(argv[0], self, &f, &o);
213
295
  if (accessor_type == METHOD_UNKNOWN || (o == NULL && f == NULL) ) {
214
296
  return rb_call_super(argc, argv);
215
- } else if (accessor_type == METHOD_SETTER) {
297
+ } else if (accessor_type == METHOD_SETTER || accessor_type == METHOD_WRAPPER_SETTER) {
216
298
  if (argc != 2) {
217
299
  rb_raise(rb_eArgError, "Expected 2 arguments, received %d", argc);
218
300
  }
301
+ rb_check_frozen(_self);
219
302
  } else if (argc != 1) {
220
303
  rb_raise(rb_eArgError, "Expected 1 argument, received %d", argc);
221
304
  }
@@ -231,13 +314,13 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
231
314
  return oneof_field == NULL ? Qfalse : Qtrue;
232
315
  } else if (accessor_type == METHOD_CLEAR) {
233
316
  if (oneof_field != NULL) {
234
- layout_clear(self->descriptor->layout, Message_data(self), oneof_field);
317
+ layout_clear(self->descriptor->layout, Message_data(self), oneof_field);
235
318
  }
236
319
  return Qnil;
237
320
  } else {
238
321
  // METHOD_ACCESSOR
239
322
  return oneof_field == NULL ? Qnil :
240
- ID2SYM(rb_intern(upb_fielddef_name(oneof_field)));
323
+ ID2SYM(rb_intern(upb_fielddef_name(oneof_field)));
241
324
  }
242
325
  // Otherwise we're operating on a single proto field
243
326
  } else if (accessor_type == METHOD_SETTER) {
@@ -248,6 +331,35 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
248
331
  return Qnil;
249
332
  } else if (accessor_type == METHOD_PRESENCE) {
250
333
  return layout_has(self->descriptor->layout, Message_data(self), f);
334
+ } else if (accessor_type == METHOD_WRAPPER_GETTER) {
335
+ VALUE value = layout_get(self->descriptor->layout, Message_data(self), f);
336
+ if (value != Qnil) {
337
+ value = rb_funcall(value, rb_intern("value"), 0);
338
+ }
339
+ return value;
340
+ } else if (accessor_type == METHOD_WRAPPER_SETTER) {
341
+ VALUE wrapper = ruby_wrapper_type(f, argv[1]);
342
+ layout_set(self->descriptor->layout, Message_data(self), f, wrapper);
343
+ return Qnil;
344
+ } else if (accessor_type == METHOD_ENUM_GETTER) {
345
+ VALUE enum_type = field_type_class(f);
346
+ VALUE method = rb_intern("const_get");
347
+ VALUE raw_value = layout_get(self->descriptor->layout, Message_data(self), f);
348
+
349
+ // Map repeated fields to a new type with ints
350
+ if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) {
351
+ int array_size = FIX2INT(rb_funcall(raw_value, rb_intern("length"), 0));
352
+ VALUE array_args[1] = { ID2SYM(rb_intern("int64")) };
353
+ VALUE array = rb_class_new_instance(1, array_args, CLASS_OF(raw_value));
354
+ for (int i = 0; i < array_size; i++) {
355
+ VALUE entry = rb_funcall(enum_type, method, 1, rb_funcall(raw_value,
356
+ rb_intern("at"), 1, INT2NUM(i)));
357
+ rb_funcall(array, rb_intern("push"), 1, entry);
358
+ }
359
+ return array;
360
+ }
361
+ // Convert the value for singular fields
362
+ return rb_funcall(enum_type, method, 1, raw_value);
251
363
  } else {
252
364
  return layout_get(self->descriptor->layout, Message_data(self), f);
253
365
  }
@@ -622,10 +734,12 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
622
734
  // Also define #clone so that we don't inherit Object#clone.
623
735
  rb_define_method(klass, "clone", Message_dup, 0);
624
736
  rb_define_method(klass, "==", Message_eq, 1);
737
+ rb_define_method(klass, "eql?", Message_eq, 1);
625
738
  rb_define_method(klass, "hash", Message_hash, 0);
626
739
  rb_define_method(klass, "to_h", Message_to_h, 0);
627
740
  rb_define_method(klass, "to_hash", Message_to_h, 0);
628
741
  rb_define_method(klass, "inspect", Message_inspect, 0);
742
+ rb_define_method(klass, "to_s", Message_inspect, 0);
629
743
  rb_define_method(klass, "[]", Message_index, 1);
630
744
  rb_define_method(klass, "[]=", Message_index_set, 2);
631
745
  rb_define_singleton_method(klass, "decode", Message_decode, 1);
@@ -223,6 +223,12 @@ VALUE RepeatedField_push(VALUE _self, VALUE val) {
223
223
  return _self;
224
224
  }
225
225
 
226
+ VALUE RepeatedField_push_vararg(VALUE _self, VALUE args) {
227
+ for (int i = 0; i < RARRAY_LEN(args); i++) {
228
+ RepeatedField_push(_self, rb_ary_entry(args, i));
229
+ }
230
+ return _self;
231
+ }
226
232
 
227
233
  // Used by parsing handlers.
228
234
  void RepeatedField_push_native(VALUE _self, void* data) {
@@ -635,7 +641,7 @@ void RepeatedField_register(VALUE module) {
635
641
  rb_define_method(klass, "[]", RepeatedField_index, -1);
636
642
  rb_define_method(klass, "at", RepeatedField_index, -1);
637
643
  rb_define_method(klass, "[]=", RepeatedField_index_set, 2);
638
- rb_define_method(klass, "push", RepeatedField_push, 1);
644
+ rb_define_method(klass, "push", RepeatedField_push_vararg, -2);
639
645
  rb_define_method(klass, "<<", RepeatedField_push, 1);
640
646
  rb_define_private_method(klass, "pop_one", RepeatedField_pop_one, 0);
641
647
  rb_define_method(klass, "replace", RepeatedField_replace, 1);
@@ -111,13 +111,13 @@ VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value) {
111
111
  return value;
112
112
  }
113
113
 
114
- void native_slot_set(const char* name,
114
+ void native_slot_set(const char* name,
115
115
  upb_fieldtype_t type, VALUE type_class,
116
116
  void* memory, VALUE value) {
117
117
  native_slot_set_value_and_case(name, type, type_class, memory, value, NULL, 0);
118
118
  }
119
119
 
120
- void native_slot_set_value_and_case(const char* name,
120
+ void native_slot_set_value_and_case(const char* name,
121
121
  upb_fieldtype_t type, VALUE type_class,
122
122
  void* memory, VALUE value,
123
123
  uint32_t* case_memory,
@@ -178,9 +178,39 @@ void native_slot_set_value_and_case(const char* name,
178
178
  if (CLASS_OF(value) == CLASS_OF(Qnil)) {
179
179
  value = Qnil;
180
180
  } else if (CLASS_OF(value) != type_class) {
181
- rb_raise(cTypeError,
182
- "Invalid type %s to assign to submessage field '%s'.",
183
- rb_class2name(CLASS_OF(value)), name);
181
+ // check for possible implicit conversions
182
+ VALUE converted_value = NULL;
183
+ char* field_type_name = rb_class2name(type_class);
184
+
185
+ if (strcmp(field_type_name, "Google::Protobuf::Timestamp") == 0 &&
186
+ rb_obj_is_kind_of(value, rb_cTime)) {
187
+ // Time -> Google::Protobuf::Timestamp
188
+ VALUE hash = rb_hash_new();
189
+ rb_hash_aset(hash, rb_str_new2("seconds"), rb_funcall(value, rb_intern("to_i"), 0));
190
+ rb_hash_aset(hash, rb_str_new2("nanos"), rb_funcall(value, rb_intern("nsec"), 0));
191
+ VALUE args[1] = { hash };
192
+ converted_value = rb_class_new_instance(1, args, type_class);
193
+ } else if (strcmp(field_type_name, "Google::Protobuf::Duration") == 0 &&
194
+ rb_obj_is_kind_of(value, rb_cNumeric)) {
195
+ // Numeric -> Google::Protobuf::Duration
196
+ VALUE hash = rb_hash_new();
197
+ rb_hash_aset(hash, rb_str_new2("seconds"), rb_funcall(value, rb_intern("to_i"), 0));
198
+ VALUE n_value = rb_funcall(value, rb_intern("remainder"), 1, INT2NUM(1));
199
+ n_value = rb_funcall(n_value, rb_intern("*"), 1, INT2NUM(1000000000));
200
+ n_value = rb_funcall(n_value, rb_intern("round"), 0);
201
+ rb_hash_aset(hash, rb_str_new2("nanos"), n_value);
202
+ VALUE args[1] = { hash };
203
+ converted_value = rb_class_new_instance(1, args, type_class);
204
+ }
205
+
206
+ // raise if no suitable conversaion could be found
207
+ if (converted_value == NULL) {
208
+ rb_raise(cTypeError,
209
+ "Invalid type %s to assign to submessage field '%s'.",
210
+ rb_class2name(CLASS_OF(value)), name);
211
+ } else {
212
+ value = converted_value;
213
+ }
184
214
  }
185
215
  DEREF(memory, VALUE) = value;
186
216
  break;
@@ -668,7 +698,7 @@ void layout_clear(MessageLayout* layout,
668
698
 
669
699
  DEREF(memory, VALUE) = ary;
670
700
  } else {
671
- native_slot_set(upb_fielddef_name(field),
701
+ native_slot_set(upb_fielddef_name(field),
672
702
  upb_fielddef_type(field), field_type_class(field),
673
703
  memory, layout_get_default(field));
674
704
  }
@@ -839,7 +869,7 @@ void layout_set(MessageLayout* layout,
839
869
  check_repeated_field_type(val, field);
840
870
  DEREF(memory, VALUE) = val;
841
871
  } else {
842
- native_slot_set(upb_fielddef_name(field),
872
+ native_slot_set(upb_fielddef_name(field),
843
873
  upb_fielddef_type(field), field_type_class(field),
844
874
  memory, val);
845
875
  }
@@ -12624,6 +12624,7 @@ done:
12624
12624
  ** - handling of keys/escape-sequences/etc that span input buffers.
12625
12625
  */
12626
12626
 
12627
+ #include <ctype.h>
12627
12628
  #include <errno.h>
12628
12629
  #include <float.h>
12629
12630
  #include <math.h>
@@ -12820,6 +12821,19 @@ typedef struct {
12820
12821
  bool is_unknown_field;
12821
12822
  } upb_jsonparser_frame;
12822
12823
 
12824
+ static void init_frame(upb_jsonparser_frame* frame) {
12825
+ frame->m = NULL;
12826
+ frame->f = NULL;
12827
+ frame->name_table = NULL;
12828
+ frame->is_repeated = false;
12829
+ frame->is_map = false;
12830
+ frame->is_mapentry = false;
12831
+ frame->mapfield = NULL;
12832
+ frame->is_any = false;
12833
+ frame->any_frame = NULL;
12834
+ frame->is_unknown_field = false;
12835
+ }
12836
+
12823
12837
  struct upb_json_parser {
12824
12838
  upb_env *env;
12825
12839
  const upb_json_parsermethod *method;
@@ -12867,6 +12881,13 @@ struct upb_json_parser {
12867
12881
  struct tm tm;
12868
12882
  };
12869
12883
 
12884
+ static upb_jsonparser_frame* start_jsonparser_frame(upb_json_parser *p) {
12885
+ upb_jsonparser_frame *inner;
12886
+ inner = p->top + 1;
12887
+ init_frame(inner);
12888
+ return inner;
12889
+ }
12890
+
12870
12891
  struct upb_json_parsermethod {
12871
12892
  upb_refcounted base;
12872
12893
 
@@ -13824,18 +13845,11 @@ static bool start_stringval(upb_json_parser *p) {
13824
13845
 
13825
13846
  /* Start a new parser frame: parser frames correspond one-to-one with
13826
13847
  * handler frames, and string events occur in a sub-frame. */
13827
- inner = p->top + 1;
13848
+ inner = start_jsonparser_frame(p);
13828
13849
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
13829
13850
  upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
13830
13851
  inner->m = p->top->m;
13831
13852
  inner->f = p->top->f;
13832
- inner->name_table = NULL;
13833
- inner->is_repeated = false;
13834
- inner->is_map = false;
13835
- inner->is_mapentry = false;
13836
- inner->is_any = false;
13837
- inner->any_frame = NULL;
13838
- inner->is_unknown_field = false;
13839
13853
  p->top = inner;
13840
13854
 
13841
13855
  if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) {
@@ -14285,6 +14299,47 @@ static void start_timestamp_zone(upb_json_parser *p, const char *ptr) {
14285
14299
  capture_begin(p, ptr);
14286
14300
  }
14287
14301
 
14302
+ #define EPOCH_YEAR 1970
14303
+ #define TM_YEAR_BASE 1900
14304
+
14305
+ static bool isleap(int year) {
14306
+ return (year % 4) == 0 && (year % 100 != 0 || (year % 400) == 0);
14307
+ }
14308
+
14309
+ const unsigned short int __mon_yday[2][13] = {
14310
+ /* Normal years. */
14311
+ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
14312
+ /* Leap years. */
14313
+ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
14314
+ };
14315
+
14316
+ int64_t epoch(int year, int yday, int hour, int min, int sec) {
14317
+ int64_t years = year - EPOCH_YEAR;
14318
+
14319
+ int64_t leap_days = years / 4 - years / 100 + years / 400;
14320
+
14321
+ int64_t days = years * 365 + yday + leap_days;
14322
+ int64_t hours = days * 24 + hour;
14323
+ int64_t mins = hours * 60 + min;
14324
+ int64_t secs = mins * 60 + sec;
14325
+ return secs;
14326
+ }
14327
+
14328
+ static int64_t upb_mktime(const struct tm *tp) {
14329
+ int sec = tp->tm_sec;
14330
+ int min = tp->tm_min;
14331
+ int hour = tp->tm_hour;
14332
+ int mday = tp->tm_mday;
14333
+ int mon = tp->tm_mon;
14334
+ int year = tp->tm_year + TM_YEAR_BASE;
14335
+
14336
+ /* Calculate day of year from year, month, and day of month. */
14337
+ int mon_yday = ((__mon_yday[isleap(year)][mon]) - 1);
14338
+ int yday = mon_yday + mday;
14339
+
14340
+ return epoch(year, yday, hour, min, sec);
14341
+ }
14342
+
14288
14343
  static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) {
14289
14344
  size_t len;
14290
14345
  const char *buf;
@@ -14311,7 +14366,7 @@ static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) {
14311
14366
  }
14312
14367
 
14313
14368
  /* Normalize tm */
14314
- seconds = mktime(&p->tm) - timezone;
14369
+ seconds = upb_mktime(&p->tm);
14315
14370
  seconds += 3600 * hours;
14316
14371
 
14317
14372
  /* Check timestamp boundary */
@@ -14358,18 +14413,11 @@ static bool start_fieldmask_path(upb_json_parser *p) {
14358
14413
 
14359
14414
  /* Start a new parser frame: parser frames correspond one-to-one with
14360
14415
  * handler frames, and string events occur in a sub-frame. */
14361
- inner = p->top + 1;
14416
+ inner = start_jsonparser_frame(p);
14362
14417
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
14363
14418
  upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
14364
14419
  inner->m = p->top->m;
14365
14420
  inner->f = p->top->f;
14366
- inner->name_table = NULL;
14367
- inner->is_repeated = false;
14368
- inner->is_map = false;
14369
- inner->is_mapentry = false;
14370
- inner->is_any = false;
14371
- inner->any_frame = NULL;
14372
- inner->is_unknown_field = false;
14373
14421
  p->top = inner;
14374
14422
 
14375
14423
  multipart_startaccum(p);
@@ -14505,18 +14553,12 @@ static bool handle_mapentry(upb_json_parser *p) {
14505
14553
  mapfield = p->top->mapfield;
14506
14554
  mapentrymsg = upb_fielddef_msgsubdef(mapfield);
14507
14555
 
14508
- inner = p->top + 1;
14556
+ inner = start_jsonparser_frame(p);
14509
14557
  p->top->f = mapfield;
14510
14558
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
14511
14559
  upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
14512
14560
  inner->m = mapentrymsg;
14513
- inner->name_table = NULL;
14514
14561
  inner->mapfield = mapfield;
14515
- inner->is_repeated = false;
14516
- inner->is_map = false;
14517
- inner->is_any = false;
14518
- inner->any_frame = NULL;
14519
- inner->is_unknown_field = false;
14520
14562
 
14521
14563
  /* Don't set this to true *yet* -- we reuse parsing handlers below to push
14522
14564
  * the key field value to the sink, and these handlers will pop the frame
@@ -14634,16 +14676,7 @@ static bool start_subobject(upb_json_parser *p) {
14634
14676
  upb_jsonparser_frame *inner;
14635
14677
  if (!check_stack(p)) return false;
14636
14678
 
14637
- inner = p->top + 1;
14638
- inner->m = NULL;
14639
- inner->f = NULL;
14640
- inner->is_repeated = false;
14641
- inner->is_map = false;
14642
- inner->is_mapentry = false;
14643
- inner->is_any = false;
14644
- inner->any_frame = NULL;
14645
- inner->is_unknown_field = false;
14646
- p->top = inner;
14679
+ p->top = start_jsonparser_frame(p);
14647
14680
  return true;
14648
14681
  }
14649
14682
 
@@ -14655,19 +14688,12 @@ static bool start_subobject(upb_json_parser *p) {
14655
14688
  * context. */
14656
14689
  if (!check_stack(p)) return false;
14657
14690
 
14658
- inner = p->top + 1;
14691
+ inner = start_jsonparser_frame(p);
14659
14692
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
14660
14693
  upb_sink_startseq(&p->top->sink, sel, &inner->sink);
14661
14694
  inner->m = upb_fielddef_msgsubdef(p->top->f);
14662
- inner->name_table = NULL;
14663
14695
  inner->mapfield = p->top->f;
14664
- inner->f = NULL;
14665
- inner->is_repeated = false;
14666
14696
  inner->is_map = true;
14667
- inner->is_mapentry = false;
14668
- inner->is_any = false;
14669
- inner->any_frame = NULL;
14670
- inner->is_unknown_field = false;
14671
14697
  p->top = inner;
14672
14698
 
14673
14699
  return true;
@@ -14679,17 +14705,11 @@ static bool start_subobject(upb_json_parser *p) {
14679
14705
  * context. */
14680
14706
  if (!check_stack(p)) return false;
14681
14707
 
14682
- inner = p->top + 1;
14683
-
14708
+ inner = start_jsonparser_frame(p);
14684
14709
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
14685
14710
  upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
14686
14711
  inner->m = upb_fielddef_msgsubdef(p->top->f);
14687
14712
  set_name_table(p, inner);
14688
- inner->f = NULL;
14689
- inner->is_repeated = false;
14690
- inner->is_map = false;
14691
- inner->is_mapentry = false;
14692
- inner->is_unknown_field = false;
14693
14713
  p->top = inner;
14694
14714
 
14695
14715
  if (is_wellknown_msg(p, UPB_WELLKNOWN_ANY)) {
@@ -14804,15 +14824,7 @@ static bool start_array(upb_json_parser *p) {
14804
14824
  }
14805
14825
 
14806
14826
  if (p->top->is_unknown_field) {
14807
- inner = p->top + 1;
14808
- inner->m = NULL;
14809
- inner->name_table = NULL;
14810
- inner->f = NULL;
14811
- inner->is_repeated = false;
14812
- inner->is_map = false;
14813
- inner->is_mapentry = false;
14814
- inner->is_any = false;
14815
- inner->any_frame = NULL;
14827
+ inner = start_jsonparser_frame(p);
14816
14828
  inner->is_unknown_field = true;
14817
14829
  p->top = inner;
14818
14830
 
@@ -14829,18 +14841,12 @@ static bool start_array(upb_json_parser *p) {
14829
14841
 
14830
14842
  if (!check_stack(p)) return false;
14831
14843
 
14832
- inner = p->top + 1;
14844
+ inner = start_jsonparser_frame(p);
14833
14845
  sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
14834
14846
  upb_sink_startseq(&p->top->sink, sel, &inner->sink);
14835
14847
  inner->m = p->top->m;
14836
- inner->name_table = NULL;
14837
14848
  inner->f = p->top->f;
14838
14849
  inner->is_repeated = true;
14839
- inner->is_map = false;
14840
- inner->is_mapentry = false;
14841
- inner->is_any = false;
14842
- inner->any_frame = NULL;
14843
- inner->is_unknown_field = false;
14844
14850
  p->top = inner;
14845
14851
 
14846
14852
  return true;
@@ -15219,11 +15225,11 @@ static bool is_fieldmask_object(upb_json_parser *p) {
15219
15225
  * final state once, when the closing '"' is seen. */
15220
15226
 
15221
15227
 
15222
- #line 2824 "upb/json/parser.rl"
15228
+ #line 2789 "upb/json/parser.rl"
15223
15229
 
15224
15230
 
15225
15231
 
15226
- #line 2627 "upb/json/parser.c"
15232
+ #line 2592 "upb/json/parser.c"
15227
15233
  static const char _json_actions[] = {
15228
15234
  0, 1, 0, 1, 1, 1, 3, 1,
15229
15235
  4, 1, 6, 1, 7, 1, 8, 1,
@@ -15478,7 +15484,7 @@ static const int json_en_value_machine = 78;
15478
15484
  static const int json_en_main = 1;
15479
15485
 
15480
15486
 
15481
- #line 2827 "upb/json/parser.rl"
15487
+ #line 2792 "upb/json/parser.rl"
15482
15488
 
15483
15489
  size_t parse(void *closure, const void *hd, const char *buf, size_t size,
15484
15490
  const upb_bufhandle *handle) {
@@ -15501,7 +15507,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
15501
15507
  capture_resume(parser, buf);
15502
15508
 
15503
15509
 
15504
- #line 2905 "upb/json/parser.c"
15510
+ #line 2870 "upb/json/parser.c"
15505
15511
  {
15506
15512
  int _klen;
15507
15513
  unsigned int _trans;
@@ -15576,147 +15582,147 @@ _match:
15576
15582
  switch ( *_acts++ )
15577
15583
  {
15578
15584
  case 1:
15579
- #line 2632 "upb/json/parser.rl"
15585
+ #line 2597 "upb/json/parser.rl"
15580
15586
  { p--; {cs = stack[--top]; goto _again;} }
15581
15587
  break;
15582
15588
  case 2:
15583
- #line 2634 "upb/json/parser.rl"
15589
+ #line 2599 "upb/json/parser.rl"
15584
15590
  { p--; {stack[top++] = cs; cs = 23;goto _again;} }
15585
15591
  break;
15586
15592
  case 3:
15587
- #line 2638 "upb/json/parser.rl"
15593
+ #line 2603 "upb/json/parser.rl"
15588
15594
  { start_text(parser, p); }
15589
15595
  break;
15590
15596
  case 4:
15591
- #line 2639 "upb/json/parser.rl"
15597
+ #line 2604 "upb/json/parser.rl"
15592
15598
  { CHECK_RETURN_TOP(end_text(parser, p)); }
15593
15599
  break;
15594
15600
  case 5:
15595
- #line 2645 "upb/json/parser.rl"
15601
+ #line 2610 "upb/json/parser.rl"
15596
15602
  { start_hex(parser); }
15597
15603
  break;
15598
15604
  case 6:
15599
- #line 2646 "upb/json/parser.rl"
15605
+ #line 2611 "upb/json/parser.rl"
15600
15606
  { hexdigit(parser, p); }
15601
15607
  break;
15602
15608
  case 7:
15603
- #line 2647 "upb/json/parser.rl"
15609
+ #line 2612 "upb/json/parser.rl"
15604
15610
  { CHECK_RETURN_TOP(end_hex(parser)); }
15605
15611
  break;
15606
15612
  case 8:
15607
- #line 2653 "upb/json/parser.rl"
15613
+ #line 2618 "upb/json/parser.rl"
15608
15614
  { CHECK_RETURN_TOP(escape(parser, p)); }
15609
15615
  break;
15610
15616
  case 9:
15611
- #line 2659 "upb/json/parser.rl"
15617
+ #line 2624 "upb/json/parser.rl"
15612
15618
  { p--; {cs = stack[--top]; goto _again;} }
15613
15619
  break;
15614
15620
  case 10:
15615
- #line 2664 "upb/json/parser.rl"
15621
+ #line 2629 "upb/json/parser.rl"
15616
15622
  { start_year(parser, p); }
15617
15623
  break;
15618
15624
  case 11:
15619
- #line 2665 "upb/json/parser.rl"
15625
+ #line 2630 "upb/json/parser.rl"
15620
15626
  { CHECK_RETURN_TOP(end_year(parser, p)); }
15621
15627
  break;
15622
15628
  case 12:
15623
- #line 2669 "upb/json/parser.rl"
15629
+ #line 2634 "upb/json/parser.rl"
15624
15630
  { start_month(parser, p); }
15625
15631
  break;
15626
15632
  case 13:
15627
- #line 2670 "upb/json/parser.rl"
15633
+ #line 2635 "upb/json/parser.rl"
15628
15634
  { CHECK_RETURN_TOP(end_month(parser, p)); }
15629
15635
  break;
15630
15636
  case 14:
15631
- #line 2674 "upb/json/parser.rl"
15637
+ #line 2639 "upb/json/parser.rl"
15632
15638
  { start_day(parser, p); }
15633
15639
  break;
15634
15640
  case 15:
15635
- #line 2675 "upb/json/parser.rl"
15641
+ #line 2640 "upb/json/parser.rl"
15636
15642
  { CHECK_RETURN_TOP(end_day(parser, p)); }
15637
15643
  break;
15638
15644
  case 16:
15639
- #line 2679 "upb/json/parser.rl"
15645
+ #line 2644 "upb/json/parser.rl"
15640
15646
  { start_hour(parser, p); }
15641
15647
  break;
15642
15648
  case 17:
15643
- #line 2680 "upb/json/parser.rl"
15649
+ #line 2645 "upb/json/parser.rl"
15644
15650
  { CHECK_RETURN_TOP(end_hour(parser, p)); }
15645
15651
  break;
15646
15652
  case 18:
15647
- #line 2684 "upb/json/parser.rl"
15653
+ #line 2649 "upb/json/parser.rl"
15648
15654
  { start_minute(parser, p); }
15649
15655
  break;
15650
15656
  case 19:
15651
- #line 2685 "upb/json/parser.rl"
15657
+ #line 2650 "upb/json/parser.rl"
15652
15658
  { CHECK_RETURN_TOP(end_minute(parser, p)); }
15653
15659
  break;
15654
15660
  case 20:
15655
- #line 2689 "upb/json/parser.rl"
15661
+ #line 2654 "upb/json/parser.rl"
15656
15662
  { start_second(parser, p); }
15657
15663
  break;
15658
15664
  case 21:
15659
- #line 2690 "upb/json/parser.rl"
15665
+ #line 2655 "upb/json/parser.rl"
15660
15666
  { CHECK_RETURN_TOP(end_second(parser, p)); }
15661
15667
  break;
15662
15668
  case 22:
15663
- #line 2695 "upb/json/parser.rl"
15669
+ #line 2660 "upb/json/parser.rl"
15664
15670
  { start_duration_base(parser, p); }
15665
15671
  break;
15666
15672
  case 23:
15667
- #line 2696 "upb/json/parser.rl"
15673
+ #line 2661 "upb/json/parser.rl"
15668
15674
  { CHECK_RETURN_TOP(end_duration_base(parser, p)); }
15669
15675
  break;
15670
15676
  case 24:
15671
- #line 2698 "upb/json/parser.rl"
15677
+ #line 2663 "upb/json/parser.rl"
15672
15678
  { p--; {cs = stack[--top]; goto _again;} }
15673
15679
  break;
15674
15680
  case 25:
15675
- #line 2703 "upb/json/parser.rl"
15681
+ #line 2668 "upb/json/parser.rl"
15676
15682
  { start_timestamp_base(parser); }
15677
15683
  break;
15678
15684
  case 26:
15679
- #line 2705 "upb/json/parser.rl"
15685
+ #line 2670 "upb/json/parser.rl"
15680
15686
  { start_timestamp_fraction(parser, p); }
15681
15687
  break;
15682
15688
  case 27:
15683
- #line 2706 "upb/json/parser.rl"
15689
+ #line 2671 "upb/json/parser.rl"
15684
15690
  { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
15685
15691
  break;
15686
15692
  case 28:
15687
- #line 2708 "upb/json/parser.rl"
15693
+ #line 2673 "upb/json/parser.rl"
15688
15694
  { start_timestamp_zone(parser, p); }
15689
15695
  break;
15690
15696
  case 29:
15691
- #line 2709 "upb/json/parser.rl"
15697
+ #line 2674 "upb/json/parser.rl"
15692
15698
  { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
15693
15699
  break;
15694
15700
  case 30:
15695
- #line 2711 "upb/json/parser.rl"
15701
+ #line 2676 "upb/json/parser.rl"
15696
15702
  { p--; {cs = stack[--top]; goto _again;} }
15697
15703
  break;
15698
15704
  case 31:
15699
- #line 2716 "upb/json/parser.rl"
15705
+ #line 2681 "upb/json/parser.rl"
15700
15706
  { start_fieldmask_path_text(parser, p); }
15701
15707
  break;
15702
15708
  case 32:
15703
- #line 2717 "upb/json/parser.rl"
15709
+ #line 2682 "upb/json/parser.rl"
15704
15710
  { end_fieldmask_path_text(parser, p); }
15705
15711
  break;
15706
15712
  case 33:
15707
- #line 2722 "upb/json/parser.rl"
15713
+ #line 2687 "upb/json/parser.rl"
15708
15714
  { start_fieldmask_path(parser); }
15709
15715
  break;
15710
15716
  case 34:
15711
- #line 2723 "upb/json/parser.rl"
15717
+ #line 2688 "upb/json/parser.rl"
15712
15718
  { end_fieldmask_path(parser); }
15713
15719
  break;
15714
15720
  case 35:
15715
- #line 2729 "upb/json/parser.rl"
15721
+ #line 2694 "upb/json/parser.rl"
15716
15722
  { p--; {cs = stack[--top]; goto _again;} }
15717
15723
  break;
15718
15724
  case 36:
15719
- #line 2734 "upb/json/parser.rl"
15725
+ #line 2699 "upb/json/parser.rl"
15720
15726
  {
15721
15727
  if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
15722
15728
  {stack[top++] = cs; cs = 47;goto _again;}
@@ -15730,11 +15736,11 @@ _match:
15730
15736
  }
15731
15737
  break;
15732
15738
  case 37:
15733
- #line 2747 "upb/json/parser.rl"
15739
+ #line 2712 "upb/json/parser.rl"
15734
15740
  { p--; {stack[top++] = cs; cs = 78;goto _again;} }
15735
15741
  break;
15736
15742
  case 38:
15737
- #line 2752 "upb/json/parser.rl"
15743
+ #line 2717 "upb/json/parser.rl"
15738
15744
  {
15739
15745
  if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
15740
15746
  start_any_member(parser, p);
@@ -15744,11 +15750,11 @@ _match:
15744
15750
  }
15745
15751
  break;
15746
15752
  case 39:
15747
- #line 2759 "upb/json/parser.rl"
15753
+ #line 2724 "upb/json/parser.rl"
15748
15754
  { CHECK_RETURN_TOP(end_membername(parser)); }
15749
15755
  break;
15750
15756
  case 40:
15751
- #line 2762 "upb/json/parser.rl"
15757
+ #line 2727 "upb/json/parser.rl"
15752
15758
  {
15753
15759
  if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
15754
15760
  end_any_member(parser, p);
@@ -15758,7 +15764,7 @@ _match:
15758
15764
  }
15759
15765
  break;
15760
15766
  case 41:
15761
- #line 2773 "upb/json/parser.rl"
15767
+ #line 2738 "upb/json/parser.rl"
15762
15768
  {
15763
15769
  if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
15764
15770
  start_any_object(parser, p);
@@ -15768,7 +15774,7 @@ _match:
15768
15774
  }
15769
15775
  break;
15770
15776
  case 42:
15771
- #line 2782 "upb/json/parser.rl"
15777
+ #line 2747 "upb/json/parser.rl"
15772
15778
  {
15773
15779
  if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
15774
15780
  CHECK_RETURN_TOP(end_any_object(parser, p));
@@ -15778,54 +15784,54 @@ _match:
15778
15784
  }
15779
15785
  break;
15780
15786
  case 43:
15781
- #line 2794 "upb/json/parser.rl"
15787
+ #line 2759 "upb/json/parser.rl"
15782
15788
  { CHECK_RETURN_TOP(start_array(parser)); }
15783
15789
  break;
15784
15790
  case 44:
15785
- #line 2798 "upb/json/parser.rl"
15791
+ #line 2763 "upb/json/parser.rl"
15786
15792
  { end_array(parser); }
15787
15793
  break;
15788
15794
  case 45:
15789
- #line 2803 "upb/json/parser.rl"
15795
+ #line 2768 "upb/json/parser.rl"
15790
15796
  { CHECK_RETURN_TOP(start_number(parser, p)); }
15791
15797
  break;
15792
15798
  case 46:
15793
- #line 2804 "upb/json/parser.rl"
15799
+ #line 2769 "upb/json/parser.rl"
15794
15800
  { CHECK_RETURN_TOP(end_number(parser, p)); }
15795
15801
  break;
15796
15802
  case 47:
15797
- #line 2806 "upb/json/parser.rl"
15803
+ #line 2771 "upb/json/parser.rl"
15798
15804
  { CHECK_RETURN_TOP(start_stringval(parser)); }
15799
15805
  break;
15800
15806
  case 48:
15801
- #line 2807 "upb/json/parser.rl"
15807
+ #line 2772 "upb/json/parser.rl"
15802
15808
  { CHECK_RETURN_TOP(end_stringval(parser)); }
15803
15809
  break;
15804
15810
  case 49:
15805
- #line 2809 "upb/json/parser.rl"
15811
+ #line 2774 "upb/json/parser.rl"
15806
15812
  { CHECK_RETURN_TOP(end_bool(parser, true)); }
15807
15813
  break;
15808
15814
  case 50:
15809
- #line 2811 "upb/json/parser.rl"
15815
+ #line 2776 "upb/json/parser.rl"
15810
15816
  { CHECK_RETURN_TOP(end_bool(parser, false)); }
15811
15817
  break;
15812
15818
  case 51:
15813
- #line 2813 "upb/json/parser.rl"
15819
+ #line 2778 "upb/json/parser.rl"
15814
15820
  { CHECK_RETURN_TOP(end_null(parser)); }
15815
15821
  break;
15816
15822
  case 52:
15817
- #line 2815 "upb/json/parser.rl"
15823
+ #line 2780 "upb/json/parser.rl"
15818
15824
  { CHECK_RETURN_TOP(start_subobject_full(parser)); }
15819
15825
  break;
15820
15826
  case 53:
15821
- #line 2816 "upb/json/parser.rl"
15827
+ #line 2781 "upb/json/parser.rl"
15822
15828
  { end_subobject_full(parser); }
15823
15829
  break;
15824
15830
  case 54:
15825
- #line 2821 "upb/json/parser.rl"
15831
+ #line 2786 "upb/json/parser.rl"
15826
15832
  { p--; {cs = stack[--top]; goto _again;} }
15827
15833
  break;
15828
- #line 3229 "upb/json/parser.c"
15834
+ #line 3194 "upb/json/parser.c"
15829
15835
  }
15830
15836
  }
15831
15837
 
@@ -15842,32 +15848,32 @@ _again:
15842
15848
  while ( __nacts-- > 0 ) {
15843
15849
  switch ( *__acts++ ) {
15844
15850
  case 0:
15845
- #line 2630 "upb/json/parser.rl"
15851
+ #line 2595 "upb/json/parser.rl"
15846
15852
  { p--; {cs = stack[--top]; if ( p == pe )
15847
15853
  goto _test_eof;
15848
15854
  goto _again;} }
15849
15855
  break;
15850
15856
  case 46:
15851
- #line 2804 "upb/json/parser.rl"
15857
+ #line 2769 "upb/json/parser.rl"
15852
15858
  { CHECK_RETURN_TOP(end_number(parser, p)); }
15853
15859
  break;
15854
15860
  case 49:
15855
- #line 2809 "upb/json/parser.rl"
15861
+ #line 2774 "upb/json/parser.rl"
15856
15862
  { CHECK_RETURN_TOP(end_bool(parser, true)); }
15857
15863
  break;
15858
15864
  case 50:
15859
- #line 2811 "upb/json/parser.rl"
15865
+ #line 2776 "upb/json/parser.rl"
15860
15866
  { CHECK_RETURN_TOP(end_bool(parser, false)); }
15861
15867
  break;
15862
15868
  case 51:
15863
- #line 2813 "upb/json/parser.rl"
15869
+ #line 2778 "upb/json/parser.rl"
15864
15870
  { CHECK_RETURN_TOP(end_null(parser)); }
15865
15871
  break;
15866
15872
  case 53:
15867
- #line 2816 "upb/json/parser.rl"
15873
+ #line 2781 "upb/json/parser.rl"
15868
15874
  { end_subobject_full(parser); }
15869
15875
  break;
15870
- #line 3271 "upb/json/parser.c"
15876
+ #line 3236 "upb/json/parser.c"
15871
15877
  }
15872
15878
  }
15873
15879
  }
@@ -15875,7 +15881,7 @@ goto _again;} }
15875
15881
  _out: {}
15876
15882
  }
15877
15883
 
15878
- #line 2849 "upb/json/parser.rl"
15884
+ #line 2814 "upb/json/parser.rl"
15879
15885
 
15880
15886
  if (p != pe) {
15881
15887
  upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@@ -15915,23 +15921,17 @@ static void json_parser_reset(upb_json_parser *p) {
15915
15921
  int top;
15916
15922
 
15917
15923
  p->top = p->stack;
15918
- p->top->f = NULL;
15919
- p->top->is_repeated = false;
15920
- p->top->is_map = false;
15921
- p->top->is_mapentry = false;
15922
- p->top->is_any = false;
15923
- p->top->any_frame = NULL;
15924
- p->top->is_unknown_field = false;
15924
+ init_frame(p->top);
15925
15925
 
15926
15926
  /* Emit Ragel initialization of the parser. */
15927
15927
 
15928
- #line 3329 "upb/json/parser.c"
15928
+ #line 3288 "upb/json/parser.c"
15929
15929
  {
15930
15930
  cs = json_start;
15931
15931
  top = 0;
15932
15932
  }
15933
15933
 
15934
- #line 2898 "upb/json/parser.rl"
15934
+ #line 2857 "upb/json/parser.rl"
15935
15935
  p->current_state = cs;
15936
15936
  p->parser_top = top;
15937
15937
  accumulate_clear(p);
@@ -10639,4 +10639,3 @@ inline reffed_ptr<const Handlers> Printer::NewHandlers(
10639
10639
  #undef UPB_FIELD_AT
10640
10640
  #undef UPB_READ_ONEOF
10641
10641
  #undef UPB_WRITE_ONEOF
10642
- #undef UPB_WRITE_ONEOF
Binary file
Binary file
Binary file
Binary file
@@ -357,5 +357,25 @@ module BasicTest
357
357
  assert_equal nil, file_descriptor.name
358
358
  assert_equal :proto3, file_descriptor.syntax
359
359
  end
360
+
361
+ # Ruby 2.5 changed to raise FrozenError instead of RuntimeError
362
+ FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
363
+
364
+ def test_map_freeze
365
+ m = proto_module::MapMessage.new
366
+ m.map_string_int32['a'] = 5
367
+ m.map_string_msg['b'] = proto_module::TestMessage2.new
368
+
369
+ m.map_string_int32.freeze
370
+ m.map_string_msg.freeze
371
+
372
+ assert m.map_string_int32.frozen?
373
+ assert m.map_string_msg.frozen?
374
+
375
+ assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
376
+ assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
377
+ assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
378
+ assert_raise(FrozenErrorType) { m.map_string_int32.clear }
379
+ end
360
380
  end
361
381
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.8.0.rc.1
5
5
  platform: x86-linux
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-26 00:00:00.000000000 Z
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler-dock
@@ -126,9 +126,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - ">"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 1.3.1
132
132
  requirements: []
133
133
  rubyforge_project:
134
134
  rubygems_version: 2.7.8