add RoxBox::as_ptr

This commit is contained in:
Dan Knutson 2024-11-30 10:56:58 -06:00
parent 49ab969ff3
commit dccc0f68da
No known key found for this signature in database
GPG key ID: D97DA800148D5B08

View file

@ -10,6 +10,8 @@ use core::{
ptr::{self, NonNull},
};
use std::os::raw::c_void;
#[repr(C)]
pub struct RocBox<T>
where
@ -69,16 +71,15 @@ where
}
fn storage(&self) -> &Cell<Storage> {
let alignment = Self::alloc_alignment();
unsafe { &*self.as_ptr().cast::<Cell<Storage>>() }
}
unsafe {
&*self
.contents
.as_ptr()
.cast::<u8>()
.sub(alignment)
.cast::<Cell<Storage>>()
}
/// The raw pointer to a roc box, including the leading refcount
/// Intended for use by platforms in roc_dealloc
pub unsafe fn as_ptr(&self) -> *mut c_void {
let alignment = Self::alloc_alignment();
let with_offset = unsafe { self.contents.as_ptr().cast::<u8>().sub(alignment) };
with_offset as *mut c_void
}
}