Skip to content

Commit

Permalink
Move static ctor out of unsafe context (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk authored Aug 7, 2023
1 parent 3c8372b commit 1b5e7cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ctor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
:
unsafe extern "C" fn() = {
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")]
unsafe extern "C" fn initer() {
#storage_ident = Some(#expr);
extern "C" fn initer() {
let val = Some(#expr);
// Only write the value to `storage_ident` on startup
unsafe {
#storage_ident = val;
}
}; initer }
;
);
Expand Down

0 comments on commit 1b5e7cd

Please sign in to comment.