diff options
author | Joel Galenson <jgalenson@google.com> | 2021-04-13 23:48:06 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-13 23:48:06 +0000 |
commit | abc5b8687da1ddc2d5d266483ef9e47291fa1f1b (patch) | |
tree | c5ffb7b06eff412106240d3af108bf86da4b39df | |
parent | 56ba34d7d9a878db95ba8299270802c05c69f959 (diff) | |
parent | 85ef0c30465905cddeb4542c63fd6f2f83b60f71 (diff) | |
download | serde-abc5b8687da1ddc2d5d266483ef9e47291fa1f1b.tar.gz |
Upgrade rust/crates/serde to 1.0.125 am: b32e27274d am: b47b8285ec am: 64651b7890 am: 85ef0c3046
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/serde/+/1662806
Change-Id: I80beb5f3b5b6a33105f1f4766b6cd4e59a2ce9ba
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 40 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | TEST_MAPPING | 41 | ||||
-rw-r--r-- | build.rs | 4 | ||||
-rw-r--r-- | patches/Android.bp.patch | 20 | ||||
-rw-r--r-- | src/de/impls.rs | 21 | ||||
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/private/de.rs | 37 | ||||
-rw-r--r-- | src/ser/impls.rs | 55 |
12 files changed, 187 insertions, 55 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 71f38ef..1eff8ec 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "3d6c4149b177e9cadfb948ebc6d1e55b33861792" + "sha1": "e9270e59f0c46817899dd61119674396f24c2b3e" } } @@ -1,4 +1,5 @@ // This file is generated by cargo2android.py --run --device --dependencies --features=default,derive --patch=patches/Android.bp.patch. +// Do not modify this file as changes will be overridden on upgrade. package { default_applicable_licenses: ["external_rust_crates_serde_license"], @@ -49,21 +50,22 @@ rust_library { "serde_derive", "std", ], - flags: [ - "--cfg core_duration", - "--cfg core_reverse", - "--cfg core_try_from", - "--cfg de_boxed_c_str", - "--cfg de_boxed_path", - "--cfg de_rc_dst", - "--cfg integer128", - "--cfg num_nonzero", - "--cfg num_nonzero_signed", - "--cfg ops_bound", - "--cfg range_inclusive", - "--cfg serde_derive", - "--cfg std_atomic", - // "--cfg std_atomic64", // not for arm/arm64 + cfgs: [ + "core_duration", + "core_reverse", + "core_try_from", + "de_boxed_c_str", + "de_boxed_path", + "de_rc_dst", + "integer128", + "num_nonzero", + "num_nonzero_signed", + "ops_bound", + "range_inclusive", + "serde_derive", + "std_atomic", + // "std_atomic64", // not for arm/arm64 + "systemtime_checked_add", ], proc_macros: ["libserde_derive"], apex_available: [ @@ -73,8 +75,8 @@ rust_library { } // dependent_library ["feature_list"] -// proc-macro2-1.0.24 "default,proc-macro" -// quote-1.0.8 "default,proc-macro" -// serde_derive-1.0.123 "default" -// syn-1.0.60 "clone-impls,default,derive,parsing,printing,proc-macro,quote" +// proc-macro2-1.0.26 "default,proc-macro" +// quote-1.0.9 "default,proc-macro" +// serde_derive-1.0.125 "default" +// syn-1.0.69 "clone-impls,default,derive,parsing,printing,proc-macro,quote" // unicode-xid-0.2.1 "default" @@ -12,7 +12,7 @@ [package] name = "serde" -version = "1.0.123" +version = "1.0.125" authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] build = "build.rs" include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] @@ -30,7 +30,7 @@ targets = ["x86_64-unknown-linux-gnu"] [package.metadata.playground] features = ["derive", "rc"] [dependencies.serde_derive] -version = "=1.0.123" +version = "=1.0.125" optional = true [dev-dependencies.serde_derive] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index b777712..6488d90 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "serde" -version = "1.0.123" # remember to update html_root_url and serde_derive dependency +version = "1.0.125" # remember to update html_root_url and serde_derive dependency authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] license = "MIT OR Apache-2.0" description = "A generic serialization/deserialization framework" @@ -14,7 +14,7 @@ include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APAC build = "build.rs" [dependencies] -serde_derive = { version = "=1.0.123", optional = true, path = "../serde_derive" } +serde_derive = { version = "=1.0.125", optional = true, path = "../serde_derive" } [dev-dependencies] serde_derive = { version = "1.0", path = "../serde_derive" } @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/serde/serde-1.0.123.crate" + value: "https://static.crates.io/crates/serde/serde-1.0.125.crate" } - version: "1.0.123" + version: "1.0.125" license_type: NOTICE last_upgrade_date { year: 2021 - month: 2 - day: 9 + month: 4 + day: 13 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index bb118af..b835c6b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -2,13 +2,52 @@ { "presubmit": [ { + "name": "authfs_device_test_src_lib" + }, + { + "name": "either_device_test_src_lib" + }, + { + "name": "serde_cbor_device_test_src_lib" + }, + { + "name": "serde_cbor_device_test_tests_bennofs" + }, + { + "name": "serde_cbor_device_test_tests_canonical" + }, + { + "name": "serde_cbor_device_test_tests_de" + }, + { + "name": "serde_cbor_device_test_tests_enum" + }, + { + "name": "serde_cbor_device_test_tests_ser" + }, + { + "name": "serde_cbor_device_test_tests_std_types" + }, + { + "name": "serde_cbor_device_test_tests_tags" + }, + { + "name": "serde_cbor_device_test_tests_value" + }, + { "name": "serde_test_device_test_src_lib" }, { + "name": "unicode-bidi_device_test_src_lib" + }, + { "name": "url_device_test_src_lib" }, { - "name": "unicode-bidi_device_test_src_lib" + "name": "url_device_test_tests_data" + }, + { + "name": "url_device_test_tests_unit" } ] } @@ -76,12 +76,14 @@ fn main() { println!("cargo:rustc-cfg=serde_derive"); } - // TryFrom, Atomic types, and non-zero signed integers stabilized in Rust 1.34: + // TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add + // stabilized in Rust 1.34: // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations if minor >= 34 { println!("cargo:rustc-cfg=core_try_from"); println!("cargo:rustc-cfg=num_nonzero_signed"); + println!("cargo:rustc-cfg=systemtime_checked_add"); // Whitelist of archs that support std::sync::atomic module. Ideally we // would use #[cfg(target_has_atomic = "...")] but it is not stable yet. diff --git a/patches/Android.bp.patch b/patches/Android.bp.patch index 4f03f0b..c124dc0 100644 --- a/patches/Android.bp.patch +++ b/patches/Android.bp.patch @@ -2,11 +2,19 @@ diff --git b/Android.bp a/Android.bp index 41d67cc..277296f 100644 --- b/Android.bp +++ a/Android.bp -@@ -23,6 +23,6 @@ rust_library { - "--cfg ops_bound", - "--cfg range_inclusive", - "--cfg std_atomic", -- "--cfg std_atomic64", -+ // "--cfg std_atomic64", // not for arm/arm64 +@@ -64,10 +64,14 @@ + "range_inclusive", + "serde_derive", + "std_atomic", +- "std_atomic64", ++ // "std_atomic64", // not for arm/arm64 + "systemtime_checked_add", ], + proc_macros: ["libserde_derive"], ++ apex_available: [ ++ "//apex_available:platform", ++ "com.android.virt", ++ ], } + + // dependent_library ["feature_list"] diff --git a/src/de/impls.rs b/src/de/impls.rs index 409f6cb..59d90d2 100644 --- a/src/de/impls.rs +++ b/src/de/impls.rs @@ -2046,6 +2046,17 @@ impl<'de> Deserialize<'de> for SystemTime { } } + fn check_overflow<E>(secs: u64, nanos: u32) -> Result<(), E> + where + E: Error, + { + static NANOS_PER_SEC: u32 = 1_000_000_000; + match secs.checked_add((nanos / NANOS_PER_SEC) as u64) { + Some(_) => Ok(()), + None => Err(E::custom("overflow deserializing SystemTime epoch offset")), + } + } + struct DurationVisitor; impl<'de> Visitor<'de> for DurationVisitor { @@ -2071,6 +2082,7 @@ impl<'de> Deserialize<'de> for SystemTime { return Err(Error::invalid_length(1, &self)); } }; + try!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } @@ -2108,13 +2120,20 @@ impl<'de> Deserialize<'de> for SystemTime { Some(nanos) => nanos, None => return Err(<A::Error as Error>::missing_field("nanos_since_epoch")), }; + try!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } } const FIELDS: &'static [&'static str] = &["secs_since_epoch", "nanos_since_epoch"]; let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor)); - Ok(UNIX_EPOCH + duration) + #[cfg(systemtime_checked_add)] + let ret = UNIX_EPOCH + .checked_add(duration) + .ok_or_else(|| D::Error::custom("overflow deserializing SystemTime")); + #[cfg(not(systemtime_checked_add))] + let ret = Ok(UNIX_EPOCH + duration); + ret } } @@ -44,7 +44,7 @@ //! - [BSON], the data storage and network transfer format used by MongoDB. //! - [Avro], a binary format used within Apache Hadoop, with support for schema //! definition. -//! - [JSON5], A superset of JSON including some productions from ES5. +//! - [JSON5], a superset of JSON including some productions from ES5. //! - [Postcard], a no\_std and embedded-systems friendly compact binary format. //! - [URL] query strings, in the x-www-form-urlencoded format. //! - [Envy], a way to deserialize environment variables into Rust structs. @@ -84,7 +84,7 @@ //////////////////////////////////////////////////////////////////////////////// // Serde types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/serde/1.0.123")] +#![doc(html_root_url = "https://docs.rs/serde/1.0.125")] // Support using Serde without the standard library! #![cfg_attr(not(feature = "std"), no_std)] // Unstable functionality only if the user asks for it. For tracking and @@ -120,6 +120,7 @@ zero_prefixed_literal, // correctly used enum_glob_use, + let_underscore_drop, map_err_ignore, result_unit_err, wildcard_imports, @@ -138,7 +139,6 @@ ) )] // Rustc lints. -#![forbid(unsafe_code)] #![deny(missing_docs, unused_imports)] //////////////////////////////////////////////////////////////////////////////// diff --git a/src/private/de.rs b/src/private/de.rs index 0c2f3b8..9199816 100644 --- a/src/private/de.rs +++ b/src/private/de.rs @@ -1287,8 +1287,9 @@ mod content { // } // // We want {"topic":"Info"} to deserialize even though - // ordinarily unit structs do not deserialize from empty map. + // ordinarily unit structs do not deserialize from empty map/seq. Content::Map(ref v) if v.is_empty() => visitor.visit_unit(), + Content::Seq(ref v) if v.is_empty() => visitor.visit_unit(), _ => self.deserialize_any(visitor), } } @@ -1741,6 +1742,25 @@ mod content { _ => Err(self.invalid_type(&visitor)), } } + + fn deserialize_float<V>(self, visitor: V) -> Result<V::Value, E> + where + V: Visitor<'de>, + { + match *self.content { + Content::F32(v) => visitor.visit_f32(v), + Content::F64(v) => visitor.visit_f64(v), + Content::U8(v) => visitor.visit_u8(v), + Content::U16(v) => visitor.visit_u16(v), + Content::U32(v) => visitor.visit_u32(v), + Content::U64(v) => visitor.visit_u64(v), + Content::I8(v) => visitor.visit_i8(v), + Content::I16(v) => visitor.visit_i16(v), + Content::I32(v) => visitor.visit_i32(v), + Content::I64(v) => visitor.visit_i64(v), + _ => Err(self.invalid_type(&visitor)), + } + } } fn visit_content_seq_ref<'a, 'de, V, E>( @@ -1888,25 +1908,14 @@ mod content { where V: Visitor<'de>, { - match *self.content { - Content::F32(v) => visitor.visit_f32(v), - Content::F64(v) => visitor.visit_f64(v), - Content::U64(v) => visitor.visit_u64(v), - Content::I64(v) => visitor.visit_i64(v), - _ => Err(self.invalid_type(&visitor)), - } + self.deserialize_float(visitor) } fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>, { - match *self.content { - Content::F64(v) => visitor.visit_f64(v), - Content::U64(v) => visitor.visit_u64(v), - Content::I64(v) => visitor.visit_i64(v), - _ => Err(self.invalid_type(&visitor)), - } + self.deserialize_float(visitor) } fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> diff --git a/src/ser/impls.rs b/src/ser/impls.rs index 431a478..c254ac6 100644 --- a/src/ser/impls.rs +++ b/src/ser/impls.rs @@ -675,6 +675,52 @@ impl Serialize for net::IpAddr { } #[cfg(feature = "std")] +const DEC_DIGITS_LUT: &'static [u8] = b"\ + 0001020304050607080910111213141516171819\ + 2021222324252627282930313233343536373839\ + 4041424344454647484950515253545556575859\ + 6061626364656667686970717273747576777879\ + 8081828384858687888990919293949596979899"; + +#[cfg(feature = "std")] +#[inline] +fn format_u8(mut n: u8, out: &mut [u8]) -> usize { + if n >= 100 { + let d1 = ((n % 100) << 1) as usize; + n /= 100; + out[0] = b'0' + n; + out[1] = DEC_DIGITS_LUT[d1]; + out[2] = DEC_DIGITS_LUT[d1 + 1]; + 3 + } else if n >= 10 { + let d1 = (n << 1) as usize; + out[0] = DEC_DIGITS_LUT[d1]; + out[1] = DEC_DIGITS_LUT[d1 + 1]; + 2 + } else { + out[0] = b'0' + n; + 1 + } +} + +#[cfg(feature = "std")] +#[test] +fn test_format_u8() { + let mut i = 0u8; + + loop { + let mut buf = [0u8; 3]; + let written = format_u8(i, &mut buf); + assert_eq!(i.to_string().as_bytes(), &buf[..written]); + + match i.checked_add(1) { + Some(next) => i = next, + None => break, + } + } +} + +#[cfg(feature = "std")] impl Serialize for net::Ipv4Addr { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where @@ -683,7 +729,14 @@ impl Serialize for net::Ipv4Addr { if serializer.is_human_readable() { const MAX_LEN: usize = 15; debug_assert_eq!(MAX_LEN, "101.102.103.104".len()); - serialize_display_bounded_length!(self, MAX_LEN, serializer) + let mut buf = [b'.'; MAX_LEN]; + let mut written = format_u8(self.octets()[0], &mut buf); + for oct in &self.octets()[1..] { + // Skip over delimiters that we initialized buf with + written += format_u8(*oct, &mut buf[written + 1..]) + 1; + } + // We've only written ASCII bytes to the buffer, so it is valid UTF-8 + serializer.serialize_str(unsafe { str::from_utf8_unchecked(&buf[..written]) }) } else { self.octets().serialize(serializer) } |