Skip to content

p-token: Add unsafe to transmutable trait #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion interface/src/state/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Account {
}
}

impl Transmutable for Account {
unsafe impl Transmutable for Account {
const LEN: usize = core::mem::size_of::<Account>();
}

Expand Down
2 changes: 1 addition & 1 deletion interface/src/state/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Mint {
}
}

impl Transmutable for Mint {
unsafe impl Transmutable for Mint {
/// The length of the `Mint` account data.
const LEN: usize = core::mem::size_of::<Mint>();
}
Expand Down
4 changes: 3 additions & 1 deletion interface/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ pub type COption<T> = ([u8; 4], T);

/// Marker trait for types that can be cast from a raw pointer.
///
/// # Safety
///
/// It is up to the type implementing this trait to guarantee that the cast is
/// safe, i.e., the fields of the type are well aligned and there are no padding
/// bytes.
Comment on lines 15 to 17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To go with this safety concern, what do you think about specifying that bytes must be on a well-aligned address for T for all the load functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will add a note on load in a separate PR.

pub trait Transmutable {
pub unsafe trait Transmutable {
/// The length of the type.
///
/// This must be equal to the size of each individual field in the type.
Expand Down
2 changes: 1 addition & 1 deletion interface/src/state/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Multisig {
}
}

impl Transmutable for Multisig {
unsafe impl Transmutable for Multisig {
/// The length of the `Multisig` account data.
const LEN: usize = core::mem::size_of::<Multisig>();
}
Expand Down
Loading