diff options
author | Joel Galenson <jgalenson@google.com> | 2021-08-10 16:40:08 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-08-10 16:40:08 +0000 |
commit | 9b1477ed4a4a9d6ad68844d4baad7b2d488cc425 (patch) | |
tree | b419ebb8026e72871067ec28e0a03373e6955e70 | |
parent | e51e3ca7522a3cf6d3f3321c56f23894a30a3110 (diff) | |
parent | ca20b351ae5009ac47012e9dbc4f64554dabafe9 (diff) | |
download | protobuf-9b1477ed4a4a9d6ad68844d4baad7b2d488cc425.tar.gz |
Upgrade rust/crates/protobuf to 2.25.0 am: f9dc51bd82 am: f9546adad1 am: 5af5bcf460 am: ca20b351ae
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/protobuf/+/1791073
Change-Id: Ib5e18d2d98426b0e71d33e3dd326674090db5352
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | out/version.rs | 6 | ||||
-rw-r--r-- | src/buf_read_iter.rs | 2 | ||||
-rw-r--r-- | src/coded_output_stream.rs | 2 | ||||
-rw-r--r-- | src/reflect/acc/v1.rs | 19 | ||||
-rw-r--r-- | src/repeated.rs | 52 | ||||
-rw-r--r-- | src/unknown.rs | 35 |
10 files changed, 118 insertions, 21 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index ce434ce..1911953 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "6a1143f708c31fa16253a015c334fc6e9b001013" + "sha1": "645d02b122c3c19309d1c56dee7f771829e36d76" } } @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "protobuf" -version = "2.24.1" +version = "2.25.0" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] description = "Rust implementation of Google protocol buffers\n" homepage = "https://github.com/stepancheg/rust-protobuf/" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 01322d9..5fef66e 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,7 @@ [package] name = "protobuf" -version = "2.24.1" +version = "2.25.0" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] edition = "2018" license = "MIT" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/protobuf/protobuf-2.24.1.crate" + value: "https://static.crates.io/crates/protobuf/protobuf-2.25.0.crate" } - version: "2.24.1" + version: "2.25.0" license_type: NOTICE last_upgrade_date { year: 2021 - month: 6 - day: 21 + month: 8 + day: 9 } } diff --git a/out/version.rs b/out/version.rs index cc886db..c5fda3f 100644 --- a/out/version.rs +++ b/out/version.rs @@ -1,7 +1,7 @@ /// protobuf crate version -pub const VERSION: &'static str = "2.24.1"; +pub const VERSION: &'static str = "2.25.0"; /// This symbol is used by codegen #[doc(hidden)] -pub const VERSION_IDENT: &'static str = "VERSION_2_24_1"; +pub const VERSION_IDENT: &'static str = "VERSION_2_25_0"; /// This symbol can be referenced to assert that proper version of crate is used -pub const VERSION_2_24_1: () = (); +pub const VERSION_2_25_0: () = (); diff --git a/src/buf_read_iter.rs b/src/buf_read_iter.rs index 21f51a1..37bc353 100644 --- a/src/buf_read_iter.rs +++ b/src/buf_read_iter.rs @@ -330,7 +330,7 @@ impl<'ignore> BufReadIter<'ignore> { let rem = &self.buf[self.pos_within_buf..self.limit_within_buf]; let len = cmp::min(rem.len(), buf.len()); - &mut buf[..len].copy_from_slice(&rem[..len]); + buf[..len].copy_from_slice(&rem[..len]); self.pos_within_buf += len; Ok(len) } diff --git a/src/coded_output_stream.rs b/src/coded_output_stream.rs index fb7e75c..bbfe228 100644 --- a/src/coded_output_stream.rs +++ b/src/coded_output_stream.rs @@ -190,7 +190,7 @@ impl<'a> CodedOutputStream<'a> { assert!(self.position == 0); if self.position + bytes.len() < self.buffer.len() { - &mut self.buffer[self.position..self.position + bytes.len()].copy_from_slice(bytes); + self.buffer[self.position..self.position + bytes.len()].copy_from_slice(bytes); self.position += bytes.len(); return Ok(()); } diff --git a/src/reflect/acc/v1.rs b/src/reflect/acc/v1.rs index 5cf53d5..d6bd3d3 100644 --- a/src/reflect/acc/v1.rs +++ b/src/reflect/acc/v1.rs @@ -249,7 +249,24 @@ impl<M: Message + 'static> FieldAccessorTrait for FieldAccessorImpl<M> { get_set: SingularGetSet::Enum(ref get), .. } => get.get_enum(message_down_cast(m)), - _ => panic!(), + FieldAccessorFunctions::Optional(ref t) => { + match t + .get_field(message_down_cast(m)) + .to_option() + .expect("field unset") + .as_ref() + { + ReflectValueRef::Enum(e) => e, + _ => panic!("not an enum"), + } + } + FieldAccessorFunctions::Simple(ref t) => { + match t.get_field(message_down_cast(m)).as_ref() { + ReflectValueRef::Enum(e) => e, + _ => panic!("not an enum"), + } + } + ref fns => panic!("unknown accessor type: {:?}", fns), } } diff --git a/src/repeated.rs b/src/repeated.rs index 8068d0c..d157f0c 100644 --- a/src/repeated.rs +++ b/src/repeated.rs @@ -396,6 +396,18 @@ impl<T: PartialEq> PartialEq for RepeatedField<T> { impl<T: Eq> Eq for RepeatedField<T> {} +impl<T: PartialEq> PartialEq<[T]> for RepeatedField<T> { + fn eq(&self, other: &[T]) -> bool { + self.as_slice() == other + } +} + +impl<T: PartialEq> PartialEq<RepeatedField<T>> for [T] { + fn eq(&self, other: &RepeatedField<T>) -> bool { + self == other.as_slice() + } +} + impl<T: PartialEq> RepeatedField<T> { /// True iff this container contains given element. #[inline] @@ -455,6 +467,22 @@ impl<T> IndexMut<usize> for RepeatedField<T> { } } +impl<T> Extend<T> for RepeatedField<T> { + fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) { + self.vec.truncate(self.len); + self.vec.extend(iter); + self.len = self.vec.len(); + } +} + +impl<'a, T: Copy + 'a> Extend<&'a T> for RepeatedField<T> { + fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { + self.vec.truncate(self.len); + self.vec.extend(iter); + self.len = self.vec.len(); + } +} + impl<T: fmt::Debug> fmt::Debug for RepeatedField<T> { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -508,4 +536,28 @@ mod test { v.clear(); assert_eq!("".to_string(), *v.push_default()); } + + #[test] + fn extend_values() { + let mut r = RepeatedField::new(); + r.push(10); + r.push(20); + r.clear(); + // self-check + assert_eq!(2, r.vec.len()); + r.extend(vec![30, 40]); + assert_eq!(&[30, 40][..], &r); + } + + #[test] + fn extend_copy() { + let mut r = RepeatedField::new(); + r.push(10); + r.push(20); + r.clear(); + // self-check + assert_eq!(2, r.vec.len()); + r.extend(&[30, 40]); + assert_eq!(&[30, 40][..], &r); + } } diff --git a/src/unknown.rs b/src/unknown.rs index fb0cf45..8e9da12 100644 --- a/src/unknown.rs +++ b/src/unknown.rs @@ -6,6 +6,7 @@ use std::collections::hash_map; use std::collections::hash_map::DefaultHasher; use std::collections::HashMap; use std::default::Default; +use std::hash::BuildHasherDefault; use std::hash::Hash; use std::hash::Hasher; use std::slice; @@ -169,10 +170,19 @@ impl<'o> Iterator for UnknownValuesIter<'o> { #[derive(Clone, PartialEq, Eq, Debug, Default)] pub struct UnknownFields { /// The map. - // option is needed, because HashMap constructor performs allocation, - // and very expensive + // + // `Option` is needed, because HashMap constructor performs allocation, + // and very expensive. + // + // We use "default hasher" to make iteration order deterministic. + // Which is used to make codegen output deterministic in presence of unknown fields + // (e. g. file options are represented as unknown fields). + // Using default hasher is suboptimal, because it makes unknown fields less safe. + // Note, Google Protobuf C++ simply uses linear map (which can exploitable the same way), + // and Google Protobuf Java uses tree map to store unknown fields + // (which is more expensive than hashmap). // TODO: hide - pub fields: Option<Box<HashMap<u32, UnknownValues>>>, + pub fields: Option<Box<HashMap<u32, UnknownValues, BuildHasherDefault<DefaultHasher>>>>, } /// Very simple hash implementation of `Hash` for `UnknownFields`. @@ -329,4 +339,23 @@ mod test { assert_eq!(hash(&unknown_fields_1), hash(&unknown_fields_2)); } + + #[test] + fn unknown_fields_iteration_order_deterministic() { + let mut u_1 = UnknownFields::new(); + let mut u_2 = UnknownFields::new(); + for u in &mut [&mut u_1, &mut u_2] { + u.add_fixed32(10, 20); + u.add_varint(30, 40); + u.add_fixed64(50, 60); + u.add_length_delimited(70, Vec::new()); + u.add_varint(80, 90); + u.add_fixed32(11, 22); + u.add_fixed64(33, 44); + } + + let items_1: Vec<_> = u_1.iter().collect(); + let items_2: Vec<_> = u_2.iter().collect(); + assert_eq!(items_1, items_2); + } } |