mirror of
https://github.com/Noratrieb/stuff.git
synced 2026-01-15 00:45:08 +01:00
This is now a safe interface!
This commit is contained in:
parent
7d95a7dfaf
commit
22aaf91cc1
3 changed files with 10 additions and 14 deletions
|
|
@ -54,6 +54,7 @@ mod backend_size_asserts {
|
|||
const _: () = assert_same_size::<usize, <usize as Backend>::Stored>();
|
||||
}
|
||||
|
||||
// SAFETY: We are careful around provenance
|
||||
unsafe impl Backend for usize {
|
||||
type Stored = *mut ();
|
||||
|
||||
|
|
@ -72,6 +73,7 @@ unsafe impl Backend for usize {
|
|||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
/// on 64 bit, we can just treat u64/usize interchangeably, because uintptr_t == size_t in Rust
|
||||
// SAFETY: We are careful around provenance
|
||||
unsafe impl Backend for u64 {
|
||||
type Stored = *mut ();
|
||||
|
||||
|
|
@ -90,6 +92,7 @@ unsafe impl Backend for u64 {
|
|||
|
||||
macro_rules! impl_backend_2_tuple {
|
||||
(impl for $ty:ty { (*mut (), $int:ident), $num:expr }) => {
|
||||
// SAFETY: We are careful around provenance
|
||||
unsafe impl Backend for $ty {
|
||||
// this one keeps the MSB in the pointer address, and the LSB in the integer
|
||||
|
||||
|
|
@ -117,6 +120,7 @@ macro_rules! impl_backend_2_tuple {
|
|||
#[cfg_attr(target_pointer_width = "64", allow(unused))] // not required on 64 bit
|
||||
macro_rules! impl_backend_3_tuple {
|
||||
(impl for $ty:ty { (*mut (), $int1:ident, $int2:ident), $num1:expr, $num2:expr }) => {
|
||||
// SAFETY: We are careful around provenance
|
||||
unsafe impl Backend for $ty {
|
||||
// this one keeps the MSB in the pointer address, ISB in int1 and the LSB in the int2
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue