google-protobuf 3.11.3 → 3.11.4

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: cb1f61dc81af240f6b37ae162bc7fec560eab26b1cf975e1284b43b3115eab0f
4
- data.tar.gz: 171b252117047aee011831cd1e205d84fa688f9bf07b145a7fd30857bc64a462
3
+ metadata.gz: c11a63396e4ac2f4b54478d4f08c1bf2713511ff4c409d508210970f1227fe36
4
+ data.tar.gz: a2f9b5f8f2feab64822d1371e9aa0d2eb039e50af5303892f1adec900ba952b9
5
5
  SHA512:
6
- metadata.gz: 6d5d9f0b7eba7ffe3bb30842d5be5074d423cee22f83150c0d0d1521ceca13007914666fc22f3c07821e7d6f78c0e32a94de11969a23130cdcf26593385b6817
7
- data.tar.gz: 9da84d2bd388f058a4bf189524d8e5680aec55a4507954aeccce1656424e19931d604ad1ecd2ec94d2657c55449eaf2c344f7a7a15c39dc3f384bab1d04b575b
6
+ metadata.gz: e9ecfaa9019ce7acc1cda24fe773a3a652d844c4e0c37275593498f55f53ded8e97f20c3e96a5cac80a9cdc5b499e16f22fa34284788a5067b3b266cf09aedc9
7
+ data.tar.gz: b3fdb518e4bfbe75997fbd466b6b54723cb7e23b336d6411e4fa2ea13929a4d6dc3edc1719fac73bc18920b9481d9a4bd7a8dd5a9fb3175c52652809cecccefb
@@ -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: ruby
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
@@ -112,7 +112,7 @@ homepage: https://developers.google.com/protocol-buffers
112
112
  licenses:
113
113
  - BSD-3-Clause
114
114
  metadata:
115
- source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.11.3/ruby
115
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.11.4/ruby
116
116
  post_install_message:
117
117
  rdoc_options: []
118
118
  require_paths: