diff options
author | 2022-05-31 18:10:42 +0000 | |
---|---|---|
committer | 2022-05-31 18:10:42 +0000 | |
commit | e0bfe3ae21903e9dbd80e903e726f7341662e12b (patch) | |
tree | 60fee9596f4e85344aac3f889741f8891d0b4e4d /src | |
parent | b581ec74b295811387b4a2a4f4cfeeb91ec788d8 (diff) | |
parent | bba4f0f83287b2c642f074cbcc96312ca7688135 (diff) | |
download | cortex-m-e0bfe3ae21903e9dbd80e903e726f7341662e12b.tar.gz cortex-m-e0bfe3ae21903e9dbd80e903e726f7341662e12b.tar.zst cortex-m-e0bfe3ae21903e9dbd80e903e726f7341662e12b.zip |
Merge #441v0.7.5
441: Prepare for v0.7.5 r=newAM a=adamgreig
Currently with cortex-m 0.7.4 it's not possible for stable Rust users to enable the inline-asm feature, even though their compiler might support it, because of the `![cfg_attr(feature = "inline-asm", feature(asm))]` line. I propose a new 0.7.5 release that removes this line, which means users on stable Rust >=1.59 could enable the previously nightly-only feature to get stable inline asm.
I wouldn't enable the feature by default, because that would be a significant MSRV bump, but at least this way more users could enable it before we release 0.8 with the revamped and inline-only asm.
I've also backported the bugfix from #380 which I don't believe is a breaking change.
I haven't had a chance to test this yet so it would be great if someone could try it out and just make sure the inline-asm feature does work before merging.
Any thoughts on anything else worth backporting from 0.8?
Co-authored-by: Adam Greig <adam@adamgreig.com>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/macros.rs | 32 |
2 files changed, 24 insertions, 12 deletions
@@ -22,7 +22,8 @@ //! - Some of the `register` API only becomes available only when `inline-asm` is enabled. Check the //! API docs for details. //! -//! The disadvantage is that `inline-asm` requires a nightly toolchain. +//! The disadvantage is that `inline-asm` requires a Rust version at least 1.59 to use the `asm!()` +//! macro. In the future 0.8 and above versions of `cortex-m`, this feature will always be enabled. //! //! ## `cm7-r0p1` //! @@ -55,7 +56,6 @@ //! This crate is guaranteed to compile on stable Rust 1.38 and up. It *might* //! compile with older versions but that may change in any new patch release. -#![cfg_attr(feature = "inline-asm", feature(asm))] #![deny(missing_docs)] #![no_std] #![allow(clippy::identity_op)] diff --git a/src/macros.rs b/src/macros.rs index 66b75b1..512c932 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -30,9 +30,12 @@ macro_rules! iprintln { /// `None` variant the caller must ensure that the macro is called from a function that's executed /// at most once in the whole lifetime of the program. /// -/// # Note +/// # Notes /// This macro is unsound on multi core systems. /// +/// For debuggability, you can set an explicit name for a singleton. This name only shows up the +/// the debugger and is not referencable from other code. See example below. +/// /// # Example /// /// ``` no_run @@ -50,15 +53,24 @@ macro_rules! iprintln { /// fn alias() -> &'static mut bool { /// singleton!(: bool = false).unwrap() /// } +/// +/// fn singleton_with_name() { +/// // A name only for debugging purposes +/// singleton!(FOO_BUFFER: [u8; 1024] = [0u8; 1024]); +/// } /// ``` #[macro_export] macro_rules! singleton { - (: $ty:ty = $expr:expr) => { + ($name:ident: $ty:ty = $expr:expr) => { $crate::interrupt::free(|_| { - static mut VAR: Option<$ty> = None; + // this is a tuple of a MaybeUninit and a bool because using an Option here is + // problematic: Due to niche-optimization, an Option could end up producing a non-zero + // initializer value which would move the entire static from `.bss` into `.data`... + static mut $name: (::core::mem::MaybeUninit<$ty>, bool) = + (::core::mem::MaybeUninit::uninit(), false); #[allow(unsafe_code)] - let used = unsafe { VAR.is_some() }; + let used = unsafe { $name.1 }; if used { None } else { @@ -66,16 +78,16 @@ macro_rules! singleton { #[allow(unsafe_code)] unsafe { - VAR = Some(expr) - } - - #[allow(unsafe_code)] - unsafe { - VAR.as_mut() + $name.1 = true; + $name.0 = ::core::mem::MaybeUninit::new(expr); + Some(&mut *$name.0.as_mut_ptr()) } } }) }; + (: $ty:ty = $expr:expr) => { + $crate::singleton!(VAR: $ty = $expr) + }; } /// ``` compile_fail |