#![allow(deprecated)]
use crate::api::alloc::SmartAlloc;
use crate::core::tls;
#[deprecated(
since = "0.11.1",
note = "framealloc is deprecated. Use `memkit::MkScope` instead (available in memkit 0.12+)"
)]
pub struct FrameGuard<'a> {
alloc: &'a SmartAlloc,
saved_head: usize,
}
impl<'a> FrameGuard<'a> {
pub(crate) fn new(alloc: &'a SmartAlloc) -> Self {
let saved_head = tls::with_tls(|tls| tls.frame_head());
Self { alloc, saved_head }
}
pub fn alloc<T>(&self) -> *mut T {
self.alloc.frame_alloc::<T>()
}
}
impl<'a> Drop for FrameGuard<'a> {
fn drop(&mut self) {
tls::with_tls(|tls| {
tls.reset_frame_to(self.saved_head);
});
}
}
#[deprecated(
since = "0.11.1",
note = "framealloc is deprecated. Use `memkit::MkScope` instead (available in memkit 0.12+)"
)]
pub trait FrameScope {
fn frame_scope(&self) -> FrameGuard<'_>;
}
impl FrameScope for SmartAlloc {
fn frame_scope(&self) -> FrameGuard<'_> {
FrameGuard::new(self)
}
}