Skip to content

Commit 0acd543

Browse files
committed
Merge branch 'master' into conformance-build
2 parents 2996da4 + 16d0021 commit 0acd543

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1631
-1807
lines changed

java/core/src/main/java/com/google/protobuf/Descriptors.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,11 +2119,12 @@ private static String computeFullName(
21192119
/**
21202120
* All descriptors implement this to make it easier to implement tools like {@code
21212121
* DescriptorPool}.
2122-
*
2123-
* <p>This class is public so that the methods it exposes can be called from outside of this
2124-
* package. However, it should only be subclassed from nested classes of Descriptors.
21252122
*/
21262123
public abstract static class GenericDescriptor {
2124+
2125+
// Private constructor to prevent subclasses outside of com.google.protobuf.Descriptors
2126+
private GenericDescriptor() {}
2127+
21272128
public abstract Message toProto();
21282129

21292130
public abstract String getName();
@@ -2593,20 +2594,23 @@ static void validateSymbolName(final GenericDescriptor descriptor)
25932594
}
25942595

25952596
/** Describes an oneof of a message type. */
2596-
public static final class OneofDescriptor {
2597+
public static final class OneofDescriptor extends GenericDescriptor {
25972598
/** Get the index of this descriptor within its parent. */
25982599
public int getIndex() {
25992600
return index;
26002601
}
26012602

2603+
@Override
26022604
public String getName() {
26032605
return proto.getName();
26042606
}
26052607

2608+
@Override
26062609
public FileDescriptor getFile() {
26072610
return file;
26082611
}
26092612

2613+
@Override
26102614
public String getFullName() {
26112615
return fullName;
26122616
}
@@ -2632,6 +2636,11 @@ public FieldDescriptor getField(int index) {
26322636
return fields[index];
26332637
}
26342638

2639+
@Override
2640+
public OneofDescriptorProto toProto() {
2641+
return proto;
2642+
}
2643+
26352644
private void setProto(final OneofDescriptorProto proto) {
26362645
this.proto = proto;
26372646
}

js/binary/decoder_test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ describe('binaryDecoderTest', function() {
255255

256256
/**
257257
* Verifies that misuse of the decoder class triggers assertions.
258-
* @suppress {checkTypes|visibility}
259258
*/
260259
it('testDecodeErrors', function() {
261260
// Reading a value past the end of the stream should trigger an assertion.

python/google/protobuf/descriptor_pool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ def _CheckConflictRegister(self, desc, desc_name, file_name):
164164
warn_msg = ('Conflict register for file "' + file_name +
165165
'": ' + desc_name +
166166
' is already defined in file "' +
167-
old_file + '"')
167+
old_file + '". Please fix the conflict by adding '
168+
'package name on the proto file, or use different '
169+
'name for the duplication. This warning will '
170+
'turn into error soon.')
168171
if isinstance(desc, descriptor.EnumValueDescriptor):
169172
warn_msg += ('\nNote: enum values appear as '
170173
'siblings of the enum type instead of '

python/google/protobuf/internal/well_known_types.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
class Any(object):
6868
"""Class for Any Message type."""
6969

70+
__slots__ = ()
71+
7072
def Pack(self, msg, type_url_prefix='type.googleapis.com/',
7173
deterministic=None):
7274
"""Packs the specified message into current Any message."""
@@ -100,6 +102,8 @@ def Is(self, descriptor):
100102
class Timestamp(object):
101103
"""Class for Timestamp message type."""
102104

105+
__slots__ = ()
106+
103107
def ToJsonString(self):
104108
"""Converts Timestamp to RFC 3339 date string format.
105109
@@ -250,6 +254,8 @@ def FromDatetime(self, dt):
250254
class Duration(object):
251255
"""Class for Duration message type."""
252256

257+
__slots__ = ()
258+
253259
def ToJsonString(self):
254260
"""Converts Duration to string format.
255261
@@ -407,6 +413,8 @@ def _RoundTowardZero(value, divider):
407413
class FieldMask(object):
408414
"""Class for FieldMask message type."""
409415

416+
__slots__ = ()
417+
410418
def ToJsonString(self):
411419
"""Converts FieldMask to string according to proto3 JSON spec."""
412420
camelcase_paths = []
@@ -563,6 +571,8 @@ class _FieldMaskTree(object):
563571
In the tree, each leaf node represents a field path.
564572
"""
565573

574+
__slots__ = ('_root',)
575+
566576
def __init__(self, field_mask=None):
567577
"""Initializes the tree by FieldMask."""
568578
self._root = {}
@@ -743,7 +753,7 @@ def _GetStructValue(struct_value):
743753
class Struct(object):
744754
"""Class for Struct message type."""
745755

746-
__slots__ = []
756+
__slots__ = ()
747757

748758
def __getitem__(self, key):
749759
return _GetStructValue(self.fields[key])
@@ -796,6 +806,8 @@ def update(self, dictionary): # pylint: disable=invalid-name
796806
class ListValue(object):
797807
"""Class for ListValue message type."""
798808

809+
__slots__ = ()
810+
799811
def __len__(self):
800812
return len(self.values)
801813

ruby/ext/google/protobuf_c/map.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ VALUE Map_dup(VALUE _self) {
538538
return new_map;
539539
}
540540

541-
// Used by Google::Protobuf.deep_copy but not exposed directly.
542-
VALUE Map_deep_copy(VALUE _self) {
541+
/* :nodoc: */
542+
static VALUE Map_deep_copy(VALUE _self) {
543543
Map* self = ruby_to_Map(_self);
544544
VALUE new_map = Map_new_this_type(_self);
545545
Map* new_self = ruby_to_Map(new_map);
@@ -851,5 +851,6 @@ void Map_register(VALUE module) {
851851
rb_define_method(klass, "to_h", Map_to_h, 0);
852852
rb_define_method(klass, "inspect", Map_inspect, 0);
853853
rb_define_method(klass, "merge", Map_merge, 1);
854+
rb_define_method(klass, "deep_copy", Map_deep_copy, 0);
854855
rb_include_module(klass, rb_mEnumerable);
855856
}

ruby/ext/google/protobuf_c/message.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ VALUE Message_dup(VALUE _self) {
511511
return new_msg;
512512
}
513513

514-
// Internal only; used by Google::Protobuf.deep_copy.
515-
VALUE Message_deep_copy(VALUE _self) {
514+
/* :nodoc: */
515+
static VALUE Message_deep_copy(VALUE _self) {
516516
MessageHeader* self;
517517
MessageHeader* new_msg_self;
518518
VALUE new_msg;
@@ -742,6 +742,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
742742
rb_define_method(klass, "to_s", Message_inspect, 0);
743743
rb_define_method(klass, "[]", Message_index, 1);
744744
rb_define_method(klass, "[]=", Message_index_set, 2);
745+
rb_define_method(klass, "deep_copy", Message_deep_copy, 0);
745746
rb_define_singleton_method(klass, "decode", Message_decode, 1);
746747
rb_define_singleton_method(klass, "encode", Message_encode, 1);
747748
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
@@ -829,21 +830,3 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) {
829830

830831
return mod;
831832
}
832-
833-
/*
834-
* call-seq:
835-
* Google::Protobuf.deep_copy(obj) => copy_of_obj
836-
*
837-
* Performs a deep copy of a RepeatedField instance, a Map instance, or a
838-
* message object, recursively copying its members.
839-
*/
840-
VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) {
841-
VALUE klass = CLASS_OF(obj);
842-
if (klass == cRepeatedField) {
843-
return RepeatedField_deep_copy(obj);
844-
} else if (klass == cMap) {
845-
return Map_deep_copy(obj);
846-
} else {
847-
return Message_deep_copy(obj);
848-
}
849-
}

ruby/ext/google/protobuf_c/protobuf.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ VALUE RepeatedField_replace(VALUE _self, VALUE list);
425425
VALUE RepeatedField_clear(VALUE _self);
426426
VALUE RepeatedField_length(VALUE _self);
427427
VALUE RepeatedField_dup(VALUE _self);
428-
VALUE RepeatedField_deep_copy(VALUE _self);
429428
VALUE RepeatedField_to_ary(VALUE _self);
430429
VALUE RepeatedField_eq(VALUE _self, VALUE _other);
431430
VALUE RepeatedField_hash(VALUE _self);
@@ -469,7 +468,6 @@ VALUE Map_delete(VALUE _self, VALUE key);
469468
VALUE Map_clear(VALUE _self);
470469
VALUE Map_length(VALUE _self);
471470
VALUE Map_dup(VALUE _self);
472-
VALUE Map_deep_copy(VALUE _self);
473471
VALUE Map_eq(VALUE _self, VALUE _other);
474472
VALUE Map_hash(VALUE _self);
475473
VALUE Map_to_h(VALUE _self);
@@ -564,7 +562,6 @@ VALUE Message_alloc(VALUE klass);
564562
VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
565563
VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
566564
VALUE Message_dup(VALUE _self);
567-
VALUE Message_deep_copy(VALUE _self);
568565
VALUE Message_eq(VALUE _self, VALUE _other);
569566
VALUE Message_hash(VALUE _self);
570567
VALUE Message_inspect(VALUE _self);

ruby/ext/google/protobuf_c/repeated_field.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ VALUE RepeatedField_dup(VALUE _self) {
355355
return new_rptfield;
356356
}
357357

358-
// Internal only: used by Google::Protobuf.deep_copy.
359-
VALUE RepeatedField_deep_copy(VALUE _self) {
358+
/* :nodoc: */
359+
static VALUE RepeatedField_deep_copy(VALUE _self) {
360360
RepeatedField* self = ruby_to_RepeatedField(_self);
361361
VALUE new_rptfield = RepeatedField_new_this_type(_self);
362362
RepeatedField* new_rptfield_self = ruby_to_RepeatedField(new_rptfield);
@@ -656,5 +656,6 @@ void RepeatedField_register(VALUE module) {
656656
rb_define_method(klass, "hash", RepeatedField_hash, 0);
657657
rb_define_method(klass, "+", RepeatedField_plus, 1);
658658
rb_define_method(klass, "concat", RepeatedField_concat, 1);
659+
rb_define_method(klass, "deep_copy", RepeatedField_deep_copy, 0);
659660
rb_include_module(klass, rb_mEnumerable);
660661
}

ruby/lib/google/protobuf.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,13 @@ def self.decode_json(klass, json, options = {})
7373
klass.decode_json(json, options)
7474
end
7575

76+
# call-seq:
77+
# Google::Protobuf.deep_copy(obj) => copy_of_obj
78+
#
79+
# Performs a deep copy of a RepeatedField instance, a Map instance, or a
80+
# message object, recursively copying its members.
81+
def self.deep_copy(obj)
82+
obj.deep_copy
83+
end
7684
end
7785
end

src/google/protobuf/any.pb.cc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)