@@ -61,11 +61,12 @@ macro_rules! iprintln {
61
61
/// ```
62
62
#[ macro_export]
63
63
macro_rules! singleton {
64
- ( $name: ident: $ty: ty = $expr: expr) => {
64
+ ( $( # [ $meta : meta ] ) * $ name: ident: $ty: ty = $expr: expr) => {
65
65
$crate:: interrupt:: free( |_| {
66
66
// this is a tuple of a MaybeUninit and a bool because using an Option here is
67
67
// problematic: Due to niche-optimization, an Option could end up producing a non-zero
68
68
// initializer value which would move the entire static from `.bss` into `.data`...
69
+ $( #[ $meta] ) *
69
70
static mut $name: ( :: core:: mem:: MaybeUninit <$ty>, bool ) =
70
71
( :: core:: mem:: MaybeUninit :: uninit( ) , false ) ;
71
72
@@ -79,14 +80,13 @@ macro_rules! singleton {
79
80
#[ allow( unsafe_code) ]
80
81
unsafe {
81
82
$name. 1 = true ;
82
- $name. 0 = :: core:: mem:: MaybeUninit :: new( expr) ;
83
- Some ( & mut * $name. 0 . as_mut_ptr( ) )
83
+ Some ( $name. 0 . write( expr) )
84
84
}
85
85
}
86
86
} )
87
87
} ;
88
- ( : $ty: ty = $expr: expr) => {
89
- $crate:: singleton!( VAR : $ty = $expr)
88
+ ( $ ( # [ $meta : meta ] ) * : $ty: ty = $expr: expr) => {
89
+ $crate:: singleton!( $ ( # [ $meta ] ) * VAR : $ty = $expr)
90
90
} ;
91
91
}
92
92
@@ -112,3 +112,15 @@ const CFAIL: () = ();
112
112
/// ```
113
113
#[ allow( dead_code) ]
114
114
const CPASS : ( ) = ( ) ;
115
+
116
+ /// ```
117
+ /// use cortex_m::singleton;
118
+ ///
119
+ /// fn foo() {
120
+ /// // check that attributes are forwarded
121
+ /// singleton!(#[link_section = ".bss"] FOO: u8 = 0);
122
+ /// singleton!(#[link_section = ".bss"]: u8 = 1);
123
+ /// }
124
+ /// ```
125
+ #[ allow( dead_code) ]
126
+ const CPASS_ATTR : ( ) = ( ) ;
0 commit comments