From 8065d741aceb96ea06e70afce05408e334a977b5 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 2 Nov 2021 13:41:12 +0100 Subject: Fixed aliasing issue due to RacyCell implementation --- macros/src/codegen/post_init.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'macros/src/codegen/post_init.rs') diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 5624b20..b3359ab 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -19,10 +19,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // We include the cfgs #(#cfgs)* // Resource is a RacyCell> - // - `get_mut_unchecked` to obtain `MaybeUninit` - // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` + // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T - #mangled_name.get_mut_unchecked().as_mut_ptr().write(shared_resources.#name); + (&mut *#mangled_name.get_mut()).as_mut_ptr().write(shared_resources.#name); )); } } @@ -37,10 +36,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // We include the cfgs #(#cfgs)* // Resource is a RacyCell> - // - `get_mut_unchecked` to obtain `MaybeUninit` - // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` + // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T - #mangled_name.get_mut_unchecked().as_mut_ptr().write(local_resources.#name); + (&mut *#mangled_name.get_mut()).as_mut_ptr().write(local_resources.#name); )); } } @@ -58,7 +56,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // Store the monotonic let name = util::monotonic_ident(&monotonic.to_string()); - stmts.push(quote!(*#name.get_mut_unchecked() = Some(monotonics.#idx);)); + stmts.push(quote!(#name.get_mut().write(Some(monotonics.#idx));)); } // Enable the interrupts -- this completes the `init`-ialization phase -- cgit v1.2.3 From d3d66c97aef5eeb06ea57dac8200c43f6720e1c1 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 3 Nov 2021 08:26:45 +0100 Subject: Cleanup of resource initialization, no need to dereference --- macros/src/codegen/post_init.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'macros/src/codegen/post_init.rs') diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index b3359ab..07fbd03 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -21,7 +21,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // Resource is a RacyCell> // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T - (&mut *#mangled_name.get_mut()).as_mut_ptr().write(shared_resources.#name); + #mangled_name.get_mut().write(core::mem::MaybeUninit::new(shared_resources.#name)); )); } } @@ -38,7 +38,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // Resource is a RacyCell> // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T - (&mut *#mangled_name.get_mut()).as_mut_ptr().write(local_resources.#name); + #mangled_name.get_mut().write(core::mem::MaybeUninit::new(local_resources.#name)); )); } } -- cgit v1.2.3