Skip to content

Commit

Permalink
unsafe no-mangle
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 11, 2024
1 parent b6ef0b0 commit cd6efea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ This project is developed and maintained by the [Tools team][team].

## Minimum Supported Rust Version (MSRV)

The **generated code** is guaranteed to compile on stable Rust 1.76.0 and up.
The **generated code** is guaranteed to compile on stable Rust 1.82.0 and up.

If you encounter compilation errors on any stable version newer than 1.76.0, please open an issue.
If you encounter compilation errors on any stable version newer than 1.82.0, please open an issue.

# Testing Locally

Expand Down
8 changes: 5 additions & 3 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },));
}
Peripheral::Array(p, dim_element) => {
for p_name in names(p, dim_element) {
Expand All @@ -288,7 +288,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(
quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },),
);
}
}
}
Expand All @@ -298,7 +300,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
// crate as that would let you `take` the device peripherals more than once (one per minor
// version)
#[no_mangle]
#[unsafe(no_mangle)]
static mut DEVICE_PERIPHERALS: bool = false;

/// All the peripherals.
Expand Down
10 changes: 5 additions & 5 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __INTERRUPTS: [Vector; #n] = [
#elements
];
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
#[used]
pub static __INTERRUPTS:
[Vector; #n] = [
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [
#elements
];
Expand Down Expand Up @@ -414,7 +414,7 @@ pub fn render(
}

#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;
Expand All @@ -433,7 +433,7 @@ pub fn render(
};
($NAME:ident, $path:path) => {
#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;
Expand Down

0 comments on commit cd6efea

Please sign in to comment.