Hi,
Here's another question I've been spamming this forum recently
I have global, thread-local context handle, and a local similar handle stored in some structure.
pub fn enter(&mut self, message: isize) -> isize {
use std::mem::{replace, swap};
let mut frame = &mut self.0.context;
// 0. Ret = Some(x), Frame = Some(y), Tmp = ???
// 1. Frame -> Tmp, Frame = None, Tmp = Some(y)
let tmp = replace(frame, None).unwrap();
G_CONTEXT.with(|cell| {
let mut ret = cell.borrow_mut();
// 2. Ret <-> Frame, Ret = None, Frame = Some(x)
swap(frame, &mut *ret);
// 3. jump! Ret = Some(z), tmp = ???
tmp.jump(&mut *ret, message)
})
}
My trouble comes near pt. 3. Accesses to G_CONTEXT may 'nest' to some degree. Please also note that jump
will switch execution contexts. Thus, ret
will be free before jump
completes its job.
So I need to somehow 'free' ret
in the middle of jump
. Which isn't possible - because jump
is a piece of assembly code. Otherwise, I'll get panic when doing borrow_mut
in a nested 'scope'.
So the question goes. Will it be Ok to &mut *ret as *mut _
, return it from scope where ret
exists, then *mut _ as &mut _
back and pass to jump
?
Thanks.