google-protobuf 3.11.3-universal-darwin → 3.11.4-universal-darwin

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: b29851910e498003e0e48e52417d216317f6840858199107797598352277c448
4
- data.tar.gz: eefa18e52ae9b8855229b203c2c9dce5a0b3371cc13490fc3dfd9b06def129bb
3
+ metadata.gz: e1d35ea365beb2d1fd985075121e6d3c7978ff4923568f2d6f15ca81847d1bb3
4
+ data.tar.gz: af4528f44417e355f2acce1bc2981ad4a597266d0f46a0a9d5c09b48fd156ff3
5
5
  SHA512:
6
- metadata.gz: 9fe317c770f7f44b2654e660843b2f1d95f246b563cfd9896bcc016482c72f8d1467d59e11f8e1d774a6d3de026ccd1fcf92322c82bbf59a1313e85fc6af7194
7
- data.tar.gz: 802e20fca7d0b451e5e82bc3d16f76a1603a80b1cd52ece65fdab4d485503f6bc0c7b95f24aef6599b6e856cfa174a254c987f2f1185593244083efe6f51bca3
6
+ metadata.gz: e411753150875b505dc313b067edecbf0be782e493312dc2d37e1631d155e4e5341522e8e993d7033dacd973868c1b004efc1dc09c5b43492c80e556415bf352
7
+ data.tar.gz: c407bc185e00ace57b05d5a5e69236352d88e62ef3d1fbced7fdcbc8bcd13ccbd537a68aa8517c5489528543a16edf073914a923942f85dd56760c8c2ad1fc8b
@@ -44,6 +44,23 @@ VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len) {
44
44
  return rb_str;
45
45
  }
46
46
 
47
+ bool is_wrapper(const upb_msgdef* m) {
48
+ switch (upb_msgdef_wellknowntype(m)) {
49
+ case UPB_WELLKNOWN_DOUBLEVALUE:
50
+ case UPB_WELLKNOWN_FLOATVALUE:
51
+ case UPB_WELLKNOWN_INT64VALUE:
52
+ case UPB_WELLKNOWN_UINT64VALUE:
53
+ case UPB_WELLKNOWN_INT32VALUE:
54
+ case UPB_WELLKNOWN_UINT32VALUE:
55
+ case UPB_WELLKNOWN_STRINGVALUE:
56
+ case UPB_WELLKNOWN_BYTESVALUE:
57
+ case UPB_WELLKNOWN_BOOLVALUE:
58
+ return true;
59
+ default:
60
+ return false;
61
+ }
62
+ }
63
+
47
64
  // The code below also comes from upb's prototype Ruby binding, developed by
48
65
  // haberman@.
49
66
 
@@ -117,19 +134,26 @@ static const void* newhandlerdata(upb_handlers* h, uint32_t ofs, int32_t hasbit)
117
134
  typedef struct {
118
135
  size_t ofs;
119
136
  int32_t hasbit;
137
+ upb_fieldtype_t wrapped_type; // Only for wrappers.
120
138
  VALUE subklass;
121
139
  } submsg_handlerdata_t;
122
140
 
123
141
  // Creates a handlerdata that contains offset and submessage type information.
124
142
  static const void *newsubmsghandlerdata(upb_handlers* h,
143
+ const upb_fielddef *f,
125
144
  uint32_t ofs,
126
145
  int32_t hasbit,
127
146
  VALUE subklass) {
128
147
  submsg_handlerdata_t *hd = ALLOC(submsg_handlerdata_t);
148
+ const upb_msgdef *subm = upb_fielddef_msgsubdef(f);
129
149
  hd->ofs = ofs;
130
150
  hd->hasbit = hasbit;
131
151
  hd->subklass = subklass;
132
152
  upb_handlers_addcleanup(h, hd, xfree);
153
+ if (is_wrapper(subm)) {
154
+ const upb_fielddef *value_f = upb_msgdef_itof(subm, 1);
155
+ hd->wrapped_type = upb_fielddef_type(value_f);
156
+ }
133
157
  return hd;
134
158
  }
135
159
 
@@ -310,12 +334,39 @@ static void *submsg_handler(void *closure, const void *hd) {
310
334
  }
311
335
 
312
336
  static void* startwrapper(void* closure, const void* hd) {
313
- char* msg = closure;
314
337
  const submsg_handlerdata_t* submsgdata = hd;
338
+ char* msg = closure;
339
+ VALUE* field = (VALUE*)(msg + submsgdata->ofs);
315
340
 
316
341
  set_hasbit(closure, submsgdata->hasbit);
317
342
 
318
- return msg + submsgdata->ofs;
343
+ switch (submsgdata->wrapped_type) {
344
+ case UPB_TYPE_FLOAT:
345
+ case UPB_TYPE_DOUBLE:
346
+ *field = DBL2NUM(0);
347
+ break;
348
+ case UPB_TYPE_BOOL:
349
+ *field = Qfalse;
350
+ break;
351
+ case UPB_TYPE_STRING:
352
+ *field = get_frozen_string(NULL, 0, false);
353
+ break;
354
+ case UPB_TYPE_BYTES:
355
+ *field = get_frozen_string(NULL, 0, true);
356
+ break;
357
+ case UPB_TYPE_ENUM:
358
+ case UPB_TYPE_INT32:
359
+ case UPB_TYPE_INT64:
360
+ case UPB_TYPE_UINT32:
361
+ case UPB_TYPE_UINT64:
362
+ *field = INT2NUM(0);
363
+ break;
364
+ case UPB_TYPE_MESSAGE:
365
+ rb_raise(rb_eRuntimeError,
366
+ "Internal logic error with well-known types.");
367
+ }
368
+
369
+ return field;
319
370
  }
320
371
 
321
372
  // Handler data for startmap/endmap handlers.
@@ -522,23 +573,6 @@ static void* oneof_startwrapper(void* closure, const void* hd) {
522
573
  return msg + oneofdata->ofs;
523
574
  }
524
575
 
525
- bool is_wrapper(const upb_msgdef* m) {
526
- switch (upb_msgdef_wellknowntype(m)) {
527
- case UPB_WELLKNOWN_DOUBLEVALUE:
528
- case UPB_WELLKNOWN_FLOATVALUE:
529
- case UPB_WELLKNOWN_INT64VALUE:
530
- case UPB_WELLKNOWN_UINT64VALUE:
531
- case UPB_WELLKNOWN_INT32VALUE:
532
- case UPB_WELLKNOWN_UINT32VALUE:
533
- case UPB_WELLKNOWN_STRINGVALUE:
534
- case UPB_WELLKNOWN_BYTESVALUE:
535
- case UPB_WELLKNOWN_BOOLVALUE:
536
- return true;
537
- default:
538
- return false;
539
- }
540
- }
541
-
542
576
  // Set up handlers for a repeated field.
543
577
  static void add_handlers_for_repeated_field(upb_handlers *h,
544
578
  const Descriptor* desc,
@@ -579,7 +613,7 @@ static void add_handlers_for_repeated_field(upb_handlers *h,
579
613
  case UPB_TYPE_MESSAGE: {
580
614
  VALUE subklass = field_type_class(desc->layout, f);
581
615
  upb_handlerattr attr = UPB_HANDLERATTR_INIT;
582
- attr.handler_data = newsubmsghandlerdata(h, 0, -1, subklass);
616
+ attr.handler_data = newsubmsghandlerdata(h, f, 0, -1, subklass);
583
617
  if (is_wrapper(upb_fielddef_msgsubdef(f))) {
584
618
  upb_handlers_setstartsubmsg(h, f, appendwrapper_handler, &attr);
585
619
  } else {
@@ -708,7 +742,7 @@ static void add_handlers_for_singular_field(const Descriptor* desc,
708
742
  case UPB_TYPE_MESSAGE: {
709
743
  upb_handlerattr attr = UPB_HANDLERATTR_INIT;
710
744
  attr.handler_data = newsubmsghandlerdata(
711
- h, offset, hasbit, field_type_class(desc->layout, f));
745
+ h, f, offset, hasbit, field_type_class(desc->layout, f));
712
746
  if (is_wrapper(upb_fielddef_msgsubdef(f))) {
713
747
  upb_handlers_setstartsubmsg(h, f, startwrapper, &attr);
714
748
  } else {
@@ -1432,6 +1466,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
1432
1466
  MessageHeader* msg;
1433
1467
  upb_msg_field_iter i;
1434
1468
  upb_status status;
1469
+ bool json_wrapper = is_wrapper(desc->msgdef) && is_json;
1435
1470
 
1436
1471
  if (is_json &&
1437
1472
  upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) {
@@ -1508,7 +1543,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
1508
1543
  is_default = RSTRING_LEN(str) == 0;
1509
1544
  }
1510
1545
 
1511
- if (is_matching_oneof || emit_defaults || !is_default) {
1546
+ if (is_matching_oneof || emit_defaults || !is_default || json_wrapper) {
1512
1547
  putstr(str, f, sink);
1513
1548
  }
1514
1549
  } else if (upb_fielddef_issubmsg(f)) {
@@ -1528,7 +1563,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
1528
1563
  } else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) { \
1529
1564
  is_default = default_value == value; \
1530
1565
  } \
1531
- if (is_matching_oneof || emit_defaults || !is_default) { \
1566
+ if (is_matching_oneof || emit_defaults || !is_default || json_wrapper) { \
1532
1567
  upb_sink_put##upbtype(sink, sel, value); \
1533
1568
  } \
1534
1569
  } break;
@@ -276,6 +276,86 @@ module BasicTest
276
276
  assert_equal m5, m
277
277
  end
278
278
 
279
+ def test_map_wrappers_with_default_values
280
+ run_asserts = ->(m) {
281
+ assert_equal 0.0, m.map_double[0].value
282
+ assert_equal 0.0, m.map_float[0].value
283
+ assert_equal 0, m.map_int32[0].value
284
+ assert_equal 0, m.map_int64[0].value
285
+ assert_equal 0, m.map_uint32[0].value
286
+ assert_equal 0, m.map_uint64[0].value
287
+ assert_equal false, m.map_bool[0].value
288
+ assert_equal '', m.map_string[0].value
289
+ assert_equal '', m.map_bytes[0].value
290
+ }
291
+
292
+ m = proto_module::Wrapper.new(
293
+ map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
294
+ map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
295
+ map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
296
+ map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
297
+ map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
298
+ map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
299
+ map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
300
+ map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
301
+ map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
302
+ )
303
+
304
+ run_asserts.call(m)
305
+ serialized = proto_module::Wrapper::encode(m)
306
+ m2 = proto_module::Wrapper::decode(serialized)
307
+ run_asserts.call(m2)
308
+
309
+ # Test the case where we are serializing directly from the parsed form
310
+ # (before anything lazy is materialized).
311
+ m3 = proto_module::Wrapper::decode(serialized)
312
+ serialized2 = proto_module::Wrapper::encode(m3)
313
+ m4 = proto_module::Wrapper::decode(serialized2)
314
+ run_asserts.call(m4)
315
+
316
+ # Test that the lazy form compares equal to the expanded form.
317
+ m5 = proto_module::Wrapper::decode(serialized2)
318
+ assert_equal m5, m
319
+ end
320
+
321
+ def test_map_wrappers_with_no_value
322
+ run_asserts = ->(m) {
323
+ assert_equal 0.0, m.map_double[0].value
324
+ assert_equal 0.0, m.map_float[0].value
325
+ assert_equal 0, m.map_int32[0].value
326
+ assert_equal 0, m.map_int64[0].value
327
+ assert_equal 0, m.map_uint32[0].value
328
+ assert_equal 0, m.map_uint64[0].value
329
+ assert_equal false, m.map_bool[0].value
330
+ assert_equal '', m.map_string[0].value
331
+ assert_equal '', m.map_bytes[0].value
332
+ }
333
+
334
+ m = proto_module::Wrapper.new(
335
+ map_double: {0 => Google::Protobuf::DoubleValue.new()},
336
+ map_float: {0 => Google::Protobuf::FloatValue.new()},
337
+ map_int32: {0 => Google::Protobuf::Int32Value.new()},
338
+ map_int64: {0 => Google::Protobuf::Int64Value.new()},
339
+ map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
340
+ map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
341
+ map_bool: {0 => Google::Protobuf::BoolValue.new()},
342
+ map_string: {0 => Google::Protobuf::StringValue.new()},
343
+ map_bytes: {0 => Google::Protobuf::BytesValue.new()},
344
+ )
345
+ run_asserts.call(m)
346
+
347
+ serialized = proto_module::Wrapper::encode(m)
348
+ m2 = proto_module::Wrapper::decode(serialized)
349
+ run_asserts.call(m2)
350
+
351
+ # Test the case where we are serializing directly from the parsed form
352
+ # (before anything lazy is materialized).
353
+ m3 = proto_module::Wrapper::decode(serialized)
354
+ serialized2 = proto_module::Wrapper::encode(m3)
355
+ m4 = proto_module::Wrapper::decode(serialized2)
356
+ run_asserts.call(m4)
357
+ end
358
+
279
359
  def test_concurrent_decoding
280
360
  o = Outer.new
281
361
  o.items[0] = Inner.new
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.11.3
4
+ version: 3.11.4
5
5
  platform: universal-darwin
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-03 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler-dock
@@ -115,7 +115,7 @@ homepage: https://developers.google.com/protocol-buffers
115
115
  licenses:
116
116
  - BSD-3-Clause
117
117
  metadata:
118
- source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.11.3/ruby
118
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.11.4/ruby
119
119
  post_install_message:
120
120
  rdoc_options: []
121
121
  require_paths: