Skip to content

Commit

Permalink
Bump bytecheck to 0.7.0 (rkyv#370)
Browse files Browse the repository at this point in the history
* Bump bytecheck to 0.7.0

Signed-off-by: Jesse Szwedko <[email protected]>

* Bump rkyv version

Since bytecheck was bumped a minor version

Signed-off-by: Jesse Szwedko <[email protected]>

* update to bytecheck 0.7

* add Send + Sync bounds to rkyv_dyn errors

---------

Signed-off-by: Jesse Szwedko <[email protected]>
Co-authored-by: samlich <[email protected]>
Co-authored-by: David Koloski <[email protected]>
  • Loading branch information
3 people authored Mar 31, 2023
1 parent aa8b1a8 commit 1aea469
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ default-members = [
]

[workspace.package]
version = "0.7.41"
version = "0.8.0"
authors = ["David Koloski <[email protected]>"]
edition = "2021"
license = "MIT"
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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)._
Expand Down
2 changes: 1 addition & 1 deletion examples/json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rkyv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rkyv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)._
Expand Down
2 changes: 1 addition & 1 deletion rkyv/crates-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)._
6 changes: 3 additions & 3 deletions rkyv_dyn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
90 changes: 52 additions & 38 deletions rkyv_dyn/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait DynContext {
&mut self,
base: *const u8,
offset: isize,
) -> Result<*const u8, Box<dyn Error>>;
) -> Result<*const u8, Box<dyn Error + Send + Sync>>;

/// Checks that a given pointer can be dereferenced.
///
Expand All @@ -51,7 +51,7 @@ pub trait DynContext {
&mut self,
data_address: *const u8,
layout: &Layout,
) -> Result<(), Box<dyn Error>>;
) -> Result<(), Box<dyn Error + Send + Sync>>;

/// Checks that the given data address and layout is located completely within the subtree
/// range.
Expand All @@ -67,7 +67,7 @@ pub trait DynContext {
&mut self,
data_address: *const u8,
layout: &Layout,
) -> Result<(), Box<dyn Error>>;
) -> Result<(), Box<dyn Error + Send + Sync>>;

/// Pushes a new subtree range onto the validator and starts validating it.
///
Expand All @@ -82,14 +82,17 @@ pub trait DynContext {
&mut self,
root: *const u8,
end: *const u8,
) -> Result<Box<dyn Any>, Box<dyn Error>>;
) -> Result<Box<dyn Any>, Box<dyn Error + Send + Sync>>;

/// 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<dyn Any>) -> Result<(), Box<dyn Error>>;
fn pop_prefix_range_dyn(
&mut self,
range: Box<dyn Any>,
) -> Result<(), Box<dyn Error + Send + Sync>>;

/// Pushes a new subtree range onto the validator and starts validating it.
///
Expand All @@ -104,21 +107,24 @@ pub trait DynContext {
&mut self,
start: *const u8,
root: *const u8,
) -> Result<Box<dyn Any>, Box<dyn Error>>;
) -> Result<Box<dyn Any>, Box<dyn Error + Send + Sync>>;

/// 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<dyn Any>) -> Result<(), Box<dyn Error>>;
fn pop_suffix_range_dyn(
&mut self,
range: Box<dyn Any>,
) -> Result<(), Box<dyn Error + Send + Sync>>;

/// 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<dyn Error>>;
fn finish_dyn(&mut self) -> Result<(), Box<dyn Error + Send + Sync>>;

/// Registers the given `ptr` as a shared pointer with the given type.
///
Expand All @@ -129,92 +135,99 @@ pub trait DynContext {
&mut self,
ptr: *const u8,
type_id: TypeId,
) -> Result<bool, Box<dyn Error>>;
) -> Result<bool, Box<dyn Error + Send + Sync>>;
}

impl<C> 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<dyn Error>> {
) -> Result<*const u8, Box<dyn Error + Send + Sync>> {
self.bounds_check_ptr(base, offset)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

unsafe fn bounds_check_layout_dyn(
&mut self,
ptr: *const u8,
layout: &Layout,
) -> Result<(), Box<dyn Error>> {
) -> Result<(), Box<dyn Error + Send + Sync>> {
self.bounds_check_layout(ptr, layout)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

unsafe fn bounds_check_subtree_ptr_layout_dyn(
&mut self,
data_address: *const u8,
layout: &Layout,
) -> Result<(), Box<dyn Error>> {
) -> Result<(), Box<dyn Error + Send + Sync>> {
self.bounds_check_subtree_ptr_layout(data_address, layout)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

unsafe fn push_prefix_subtree_range_dyn(
&mut self,
root: *const u8,
end: *const u8,
) -> Result<Box<dyn Any>, Box<dyn Error>> {
) -> Result<Box<dyn Any>, Box<dyn Error + Send + Sync>> {
self.push_prefix_subtree_range(root, end)
.map(|r| Box::new(r) as Box<dyn Any>)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

fn pop_prefix_range_dyn(&mut self, range: Box<dyn Any>) -> Result<(), Box<dyn Error>> {
fn pop_prefix_range_dyn(
&mut self,
range: Box<dyn Any>,
) -> Result<(), Box<dyn Error + Send + Sync>> {
self.pop_prefix_range(*range.downcast().unwrap())
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

unsafe fn push_suffix_subtree_range_dyn(
&mut self,
start: *const u8,
root: *const u8,
) -> Result<Box<dyn Any>, Box<dyn Error>> {
) -> Result<Box<dyn Any>, Box<dyn Error + Send + Sync>> {
self.push_suffix_subtree_range(start, root)
.map(|r| Box::new(r) as Box<dyn Any>)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

fn pop_suffix_range_dyn(&mut self, range: Box<dyn Any>) -> Result<(), Box<dyn Error>> {
fn pop_suffix_range_dyn(
&mut self,
range: Box<dyn Any>,
) -> Result<(), Box<dyn Error + Send + Sync>> {
self.pop_suffix_range(*range.downcast().unwrap())
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

fn finish_dyn(&mut self) -> Result<(), Box<dyn Error>> {
self.finish().map_err(|e| Box::new(e) as Box<dyn Error>)
fn finish_dyn(&mut self) -> Result<(), Box<dyn Error + Send + Sync>> {
self.finish()
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}

fn register_shared_ptr_dyn(
&mut self,
ptr: *const u8,
type_id: TypeId,
) -> Result<bool, Box<dyn Error>> {
) -> Result<bool, Box<dyn Error + Send + Sync>> {
self.register_shared_ptr(ptr, type_id)
.map_err(|e| Box::new(e) as Box<dyn Error>)
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
}
}

/// The error type for `DynContext`.
pub struct DynError {
inner: Box<dyn Error>,
inner: Box<dyn Error + Send + Sync>,
}

impl From<Box<dyn Error>> for DynError {
fn from(inner: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for DynError {
fn from(inner: Box<dyn Error + Send + Sync>) -> Self {
Self { inner }
}
}
Expand Down Expand Up @@ -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<dyn Error>,
inner: Box::new(layout_error) as Box<dyn Error + Send + Sync>,
}
}
fn finish(&mut self) -> Result<(), Self::Error> {
Expand All @@ -317,14 +330,15 @@ impl fmt::Display for CheckBytesUnimplemented {

impl Error for CheckBytesUnimplemented {}

type CheckBytesDyn = unsafe fn(*const u8, &mut dyn DynContext) -> Result<(), Box<dyn Error>>;
type CheckBytesDyn =
unsafe fn(*const u8, &mut dyn DynContext) -> Result<(), Box<dyn Error + Send + Sync>>;

// 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<dyn Error>> {
) -> Result<(), Box<dyn Error + Send + Sync>> {
Err(Box::new(CheckBytesUnimplemented).into())
}

Expand All @@ -346,7 +360,7 @@ impl<T: for<'a> CheckBytes<dyn DynContext + 'a>> IsCheckBytesDyn<T> {
unsafe fn check_bytes_dyn(
bytes: *const u8,
context: &mut dyn DynContext,
) -> Result<(), Box<dyn Error>> {
) -> Result<(), Box<dyn Error + Send + Sync>> {
T::check_bytes(bytes.cast(), context)?;
Ok(())
}
Expand Down Expand Up @@ -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<dyn Error>),
CheckBytes(Box<dyn Error + Send + Sync>),
}

impl fmt::Display for CheckDynError {
Expand All @@ -474,8 +488,8 @@ impl Error for CheckDynError {
}
}

impl From<Box<dyn Error>> for CheckDynError {
fn from(e: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for CheckDynError {
fn from(e: Box<dyn Error + Send + Sync>) -> Self {
Self::CheckBytes(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion rkyv_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion rkyv_typename/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 1aea469

Please sign in to comment.