From 1aea469278da6bbed66c4dc20efd589c0b9059b6 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Fri, 31 Mar 2023 01:27:47 -0500 Subject: [PATCH] Bump bytecheck to 0.7.0 (#370) * Bump bytecheck to 0.7.0 Signed-off-by: Jesse Szwedko * Bump rkyv version Since bytecheck was bumped a minor version Signed-off-by: Jesse Szwedko * update to bytecheck 0.7 * add Send + Sync bounds to rkyv_dyn errors --------- Signed-off-by: Jesse Szwedko Co-authored-by: samlich <1349989+samlich@users.noreply.github.com> Co-authored-by: David Koloski --- Cargo.toml | 4 +- README.md | 2 +- examples/json/src/main.rs | 2 +- rkyv/Cargo.toml | 2 +- rkyv/README.md | 2 +- rkyv/crates-io.md | 2 +- rkyv_dyn/Cargo.toml | 6 +-- rkyv_dyn/src/validation.rs | 90 ++++++++++++++++++++++---------------- rkyv_test/Cargo.toml | 2 +- rkyv_typename/Cargo.toml | 2 +- 10 files changed, 64 insertions(+), 50 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index de1dda0a..040d421a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ default-members = [ ] [workspace.package] -version = "0.7.41" +version = "0.8.0" authors = ["David Koloski "] edition = "2021" license = "MIT" @@ -23,7 +23,7 @@ documentation = "https://docs.rs/rkyv" repository = "https://github.com/rkyv/rkyv" [workspace.dependencies] -bytecheck = { version = "=0.6.10", default-features = false } +bytecheck = { version = "=0.7.0", default-features = false } proc-macro2 = "1.0" ptr_meta = { version = "~0.1.3", default-features = false } quote = "1.0" diff --git a/README.md b/README.md index a956e67b..24e52570 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ assert_eq!(deserialized, value); _Note: the safe API requires the `validation` feature:_ ```toml -rkyv = { version = "0.7", features = ["validation"] } +rkyv = { version = "0.8", features = ["validation"] } ``` _Read more about [available features](https://docs.rs/rkyv/latest/rkyv/#features)._ diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 18753a46..40709b68 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -56,7 +56,7 @@ use std::{collections::HashMap, fmt}; // With those two changes, our recursive type can be validated with `check_archived_root`! #[archive(check_bytes)] #[archive_attr(check_bytes( - bound = "__C: rkyv::validation::ArchiveContext, <__C as rkyv::Fallible>::Error: std::error::Error" + bound = "__C: rkyv::validation::ArchiveContext, <__C as rkyv::Fallible>::Error: rkyv::bytecheck::Error" ))] pub enum JsonValue { Null, diff --git a/rkyv/Cargo.toml b/rkyv/Cargo.toml index 7fd0a471..540d0c3e 100644 --- a/rkyv/Cargo.toml +++ b/rkyv/Cargo.toml @@ -17,7 +17,7 @@ bytecheck = { workspace = true, optional = true } hashbrown = { version = "0.12", optional = true } ptr_meta = { workspace = true, default-features = false } rend = { version = "0.4", optional = true, default-features = false } -rkyv_derive = { version = "0.7.41", path = "../rkyv_derive" } +rkyv_derive = { version = "=0.8.0", path = "../rkyv_derive" } seahash = "4.0" # Support for various common crates. These are primarily to get users off the ground and build some diff --git a/rkyv/README.md b/rkyv/README.md index a830d98e..a65f90f5 100644 --- a/rkyv/README.md +++ b/rkyv/README.md @@ -104,7 +104,7 @@ assert_eq!(deserialized, value); _Note: the safe API requires the `validation` feature:_ ```toml -rkyv = { version = "0.7", features = ["validation"] } +rkyv = { version = "0.8", features = ["validation"] } ``` _Read more about [available features](https://docs.rs/rkyv/latest/rkyv/#features)._ diff --git a/rkyv/crates-io.md b/rkyv/crates-io.md index 913825a7..e947bf1e 100644 --- a/rkyv/crates-io.md +++ b/rkyv/crates-io.md @@ -104,7 +104,7 @@ assert_eq!(deserialized, value); _Note: the safe API requires the `validation` feature:_ ```toml -rkyv = { version = "0.7", features = ["validation"] } +rkyv = { version = "0.8", features = ["validation"] } ``` _Read more about [available features](https://docs.rs/rkyv/latest/rkyv/#features)._ diff --git a/rkyv_dyn/Cargo.toml b/rkyv_dyn/Cargo.toml index 6c5a9962..c9d96c36 100644 --- a/rkyv_dyn/Cargo.toml +++ b/rkyv_dyn/Cargo.toml @@ -17,9 +17,9 @@ bytecheck = { workspace = true, optional = true } inventory = "0.1" lazy_static = "1.4" ptr_meta.workspace = true -rkyv = { version = "0.7.41", path = "../rkyv", default-features = false } -rkyv_dyn_derive = { version = "0.7.41", path = "../rkyv_dyn_derive" } -rkyv_typename = { version = "0.7.41", path = "../rkyv_typename" } +rkyv = { version = "0.8.0", path = "../rkyv", default-features = false } +rkyv_dyn_derive = { version = "0.8.0", path = "../rkyv_dyn_derive" } +rkyv_typename = { version = "0.8.0", path = "../rkyv_typename" } [features] default = ["rkyv/size_32", "rkyv/std"] diff --git a/rkyv_dyn/src/validation.rs b/rkyv_dyn/src/validation.rs index fb23a46d..f83d2f6e 100644 --- a/rkyv_dyn/src/validation.rs +++ b/rkyv_dyn/src/validation.rs @@ -35,7 +35,7 @@ pub trait DynContext { &mut self, base: *const u8, offset: isize, - ) -> Result<*const u8, Box>; + ) -> Result<*const u8, Box>; /// Checks that a given pointer can be dereferenced. /// @@ -51,7 +51,7 @@ pub trait DynContext { &mut self, data_address: *const u8, layout: &Layout, - ) -> Result<(), Box>; + ) -> Result<(), Box>; /// Checks that the given data address and layout is located completely within the subtree /// range. @@ -67,7 +67,7 @@ pub trait DynContext { &mut self, data_address: *const u8, layout: &Layout, - ) -> Result<(), Box>; + ) -> Result<(), Box>; /// Pushes a new subtree range onto the validator and starts validating it. /// @@ -82,14 +82,17 @@ pub trait DynContext { &mut self, root: *const u8, end: *const u8, - ) -> Result, Box>; + ) -> Result, Box>; /// Pops the given range, restoring the original state with the pushed range removed. /// /// See [`pop_prefix_range`] for more information. /// /// [`pop_prefix_range`]: rkyv::validation::ArchiveContext::pop_prefix_range - fn pop_prefix_range_dyn(&mut self, range: Box) -> Result<(), Box>; + fn pop_prefix_range_dyn( + &mut self, + range: Box, + ) -> Result<(), Box>; /// Pushes a new subtree range onto the validator and starts validating it. /// @@ -104,21 +107,24 @@ pub trait DynContext { &mut self, start: *const u8, root: *const u8, - ) -> Result, Box>; + ) -> Result, Box>; /// Finishes the given range, restoring the original state with the pushed range removed. /// /// See [`pop_suffix_range`] for more information. /// /// [`pop_suffix_range`]: rkyv::validation::ArchiveContext::pop_suffix_range - fn pop_suffix_range_dyn(&mut self, range: Box) -> Result<(), Box>; + fn pop_suffix_range_dyn( + &mut self, + range: Box, + ) -> Result<(), Box>; /// Verifies that all outstanding claims have been returned. /// /// See [`finish`] for more information. /// /// [`finish`]: rkyv::validation::ArchiveContext::finish - fn finish_dyn(&mut self) -> Result<(), Box>; + fn finish_dyn(&mut self) -> Result<(), Box>; /// Registers the given `ptr` as a shared pointer with the given type. /// @@ -129,92 +135,99 @@ pub trait DynContext { &mut self, ptr: *const u8, type_id: TypeId, - ) -> Result>; + ) -> Result>; } impl DynContext for C where C: ArchiveContext + SharedContext + ?Sized, - C::Error: Error, + C::Error: Error + Send + Sync, { unsafe fn bounds_check_ptr_dyn( &mut self, base: *const u8, offset: isize, - ) -> Result<*const u8, Box> { + ) -> Result<*const u8, Box> { self.bounds_check_ptr(base, offset) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } unsafe fn bounds_check_layout_dyn( &mut self, ptr: *const u8, layout: &Layout, - ) -> Result<(), Box> { + ) -> Result<(), Box> { self.bounds_check_layout(ptr, layout) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } unsafe fn bounds_check_subtree_ptr_layout_dyn( &mut self, data_address: *const u8, layout: &Layout, - ) -> Result<(), Box> { + ) -> Result<(), Box> { self.bounds_check_subtree_ptr_layout(data_address, layout) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } unsafe fn push_prefix_subtree_range_dyn( &mut self, root: *const u8, end: *const u8, - ) -> Result, Box> { + ) -> Result, Box> { self.push_prefix_subtree_range(root, end) .map(|r| Box::new(r) as Box) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } - fn pop_prefix_range_dyn(&mut self, range: Box) -> Result<(), Box> { + fn pop_prefix_range_dyn( + &mut self, + range: Box, + ) -> Result<(), Box> { self.pop_prefix_range(*range.downcast().unwrap()) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } unsafe fn push_suffix_subtree_range_dyn( &mut self, start: *const u8, root: *const u8, - ) -> Result, Box> { + ) -> Result, Box> { self.push_suffix_subtree_range(start, root) .map(|r| Box::new(r) as Box) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } - fn pop_suffix_range_dyn(&mut self, range: Box) -> Result<(), Box> { + fn pop_suffix_range_dyn( + &mut self, + range: Box, + ) -> Result<(), Box> { self.pop_suffix_range(*range.downcast().unwrap()) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } - fn finish_dyn(&mut self) -> Result<(), Box> { - self.finish().map_err(|e| Box::new(e) as Box) + fn finish_dyn(&mut self) -> Result<(), Box> { + self.finish() + .map_err(|e| Box::new(e) as Box) } fn register_shared_ptr_dyn( &mut self, ptr: *const u8, type_id: TypeId, - ) -> Result> { + ) -> Result> { self.register_shared_ptr(ptr, type_id) - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } } /// The error type for `DynContext`. pub struct DynError { - inner: Box, + inner: Box, } -impl From> for DynError { - fn from(inner: Box) -> Self { +impl From> for DynError { + fn from(inner: Box) -> Self { Self { inner } } } @@ -291,7 +304,7 @@ impl ArchiveContext for (dyn DynContext + '_) { fn wrap_layout_error(layout_error: core::alloc::LayoutError) -> Self::Error { DynError { - inner: Box::new(layout_error) as Box, + inner: Box::new(layout_error) as Box, } } fn finish(&mut self) -> Result<(), Self::Error> { @@ -317,14 +330,15 @@ impl fmt::Display for CheckBytesUnimplemented { impl Error for CheckBytesUnimplemented {} -type CheckBytesDyn = unsafe fn(*const u8, &mut dyn DynContext) -> Result<(), Box>; +type CheckBytesDyn = + unsafe fn(*const u8, &mut dyn DynContext) -> Result<(), Box>; // This is the fallback function that gets called if the archived type doesn't implement CheckBytes. #[inline] unsafe fn check_bytes_dyn_unimplemented( _bytes: *const u8, _context: &mut dyn DynContext, -) -> Result<(), Box> { +) -> Result<(), Box> { Err(Box::new(CheckBytesUnimplemented).into()) } @@ -346,7 +360,7 @@ impl CheckBytes> IsCheckBytesDyn { unsafe fn check_bytes_dyn( bytes: *const u8, context: &mut dyn DynContext, - ) -> Result<(), Box> { + ) -> Result<(), Box> { T::check_bytes(bytes.cast(), context)?; Ok(()) } @@ -453,7 +467,7 @@ pub enum CheckDynError { /// The pointer metadata did not match any registered impl InvalidMetadata(u64), /// An error occurred while checking the bytes of the trait object - CheckBytes(Box), + CheckBytes(Box), } impl fmt::Display for CheckDynError { @@ -474,8 +488,8 @@ impl Error for CheckDynError { } } -impl From> for CheckDynError { - fn from(e: Box) -> Self { +impl From> for CheckDynError { + fn from(e: Box) -> Self { Self::CheckBytes(e) } } diff --git a/rkyv_test/Cargo.toml b/rkyv_test/Cargo.toml index 084d91f2..c1acab5b 100644 --- a/rkyv_test/Cargo.toml +++ b/rkyv_test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rkyv_test" description = "Test suite for rkyv crates" -version = "0.7.40" +version = "0.8.0" authors = ["David Koloski "] edition = "2021" license = "MIT" diff --git a/rkyv_typename/Cargo.toml b/rkyv_typename/Cargo.toml index df151d1a..9f823709 100644 --- a/rkyv_typename/Cargo.toml +++ b/rkyv_typename/Cargo.toml @@ -13,7 +13,7 @@ repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rkyv_typename_derive = { version = "0.7.41", path = "../rkyv_typename_derive" } +rkyv_typename_derive = { version = "=0.8.0", path = "../rkyv_typename_derive" } [features] default = ["std"]