Skip to content

Commit

Permalink
singleton: don't forward visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Apr 11, 2024
1 parent 5ce1643 commit f102430
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cortex-m/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380).
- Added `critical-section-single-core` feature which provides an implementation for the `critical_section` crate for single-core systems, based on disabling all interrupts. (#447)
- Added support for `embedded-hal` version 1 delay traits, requiring rust 1.60.
- `singleton!()` now forwards attributes and visibility (#521).
- `singleton!()` now forwards attributes (#522).

### Fixed
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).
Expand Down
13 changes: 7 additions & 6 deletions cortex-m/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ macro_rules! iprintln {
/// ```
#[macro_export]
macro_rules! singleton {
($(#[$meta:meta])* $vis:vis $name:ident: $ty:ty = $expr:expr) => {
($(#[$meta:meta])* $name:ident: $ty:ty = $expr:expr) => {
$crate::_export::critical_section::with(|_| {
// 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`...
$(#[$meta])*
$vis static mut $name: (::core::mem::MaybeUninit<$ty>, bool) =
static mut $name: (::core::mem::MaybeUninit<$ty>, bool) =
(::core::mem::MaybeUninit::uninit(), false);

#[allow(unsafe_code)]
Expand All @@ -89,8 +89,8 @@ macro_rules! singleton {
}
})
};
(: $ty:ty = $expr:expr) => {
$crate::singleton!(VAR: $ty = $expr)
($(#[$meta:meta])* : $ty:ty = $expr:expr) => {
$crate::singleton!($(#[$meta])* VAR: $ty = $expr)
};
}

Expand Down Expand Up @@ -121,8 +121,9 @@ const CPASS: () = ();
/// use cortex_m::singleton;
///
/// fn foo() {
/// // check that attributes and visibility are forwarded
/// singleton!(#[link_section = ".bss"] pub(crate) FOO: u8 = 0);
/// // check that attributes are forwarded
/// singleton!(#[link_section = ".bss"] FOO: u8 = 0);
/// singleton!(#[link_section = ".bss"]: u8 = 1);
/// }
/// ```
#[allow(dead_code)]
Expand Down

0 comments on commit f102430

Please sign in to comment.