Skip to content
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

rebind! macro #2

Open
CeleritasCelery opened this issue Apr 11, 2022 · 0 comments
Open

rebind! macro #2

CeleritasCelery opened this issue Apr 11, 2022 · 0 comments
Labels
unsound? Unsure if this unsafe code is sound

Comments

@CeleritasCelery
Copy link
Owner

CeleritasCelery commented Apr 11, 2022

The rebind macro has this definition:

rune/src/arena/mod.rs

Lines 96 to 102 in 7136b74

macro_rules! rebind {
($item:ident, $arena:ident) => {
#[allow(unused_qualifications)]
let bits: $crate::object::RawObj = $item.into();
let $item = unsafe { $arena.rebind_raw_ptr(bits) };
};
}

We are casting the object into a raw form that removes the lifetime. Then we call an unsafe function to create a new object from that raw pointer

Why this is safe

We are not actually changing the &mut reference to Arena. Instead we are releasing it then reborrowing it immutabley. We make sure to shadow the name so the old binding is no longer available.

@CeleritasCelery CeleritasCelery added the unsound? Unsure if this unsafe code is sound label Apr 11, 2022
@CeleritasCelery CeleritasCelery changed the title rebind macro rebind! macro Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unsound? Unsure if this unsafe code is sound
Projects
None yet
Development

No branches or pull requests

1 participant