mmastrac / rust-ctor

Module initialization/global constructor functions for Rust
Apache License 2.0
739 stars 49 forks source link

Move static ctor out of unsafe context #294

Closed domenukk closed 1 year ago

domenukk commented 1 year ago

On master, the following test succeeds to mutate and read the mutable static test boolean without the use of an unsafe keyword:

extern crate ctor;
use ctor::*;

static mut test: bool = false;
#[ctor]
static STATIC_CTOR: bool = {
  test = true;
  test
}

This PR fixes the issue

mmastrac commented 1 year ago

@domenukk Thanks for the two excellent PRs. Both are merged and I'll release a new version shortly. If you are interested in contributing more, I'd be happy to add you as a full contributor on the project.

domenukk commented 1 year ago

Thanks for merging! I'll gladly send more PRs if I come across other things :)

domenukk commented 1 year ago

Is there a release on crates with these fixes yet?

mmastrac commented 1 year ago

I just pushed 0.2.5 with a cargo update bump and all the latest changes, so that's definitely up-to-date!

domenukk commented 1 year ago

Thank you! :)