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

Side-effects of rustrt::at_exit_impl::init should probably not be gated on ::util::ENFORCE_SANITY #16106

Closed
pnkfelix opened this issue Jul 30, 2014 · 1 comment

Comments

@pnkfelix
Copy link
Member

Here is some code from at_exit_impl.rs:

pub fn init() {
    let state: Box<Queue> = box Exclusive::new(Vec::new());
    unsafe {
        rtassert!(!RUNNING.load(atomics::SeqCst));
        rtassert!(QUEUE.swap(mem::transmute(state), atomics::SeqCst) == 0);
    }
}

The above calls are using the rtassert!(..) macro from macros.rs:

macro_rules! rtassert (
    ( $arg:expr ) => ( {
        if ::util::ENFORCE_SANITY {
            if !$arg {
                rtabort!(" assertion failed: {}", stringify!($arg));
            }
        }
    } )
)

Notably, that macro will only evaluate its argument expressions if ::util::ENFORCE_SANITY is true.

This means that the init() is a no-op if ::util::ENFORCE_SANITY is false. That is probably not what we intended.

We should probably either change the init() code to first run each expression and then pass their return value to the rtassert! macro, or change the rtassert! macro to unconditionally evaluate its argument.

@pnkfelix
Copy link
Member Author

cc @alexcrichton

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 30, 2014
This initialization should happen unconditionally, but the rtassert! macro is
gated on the ENFORCE_SANITY define

Closes rust-lang#16106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant