Skip to content

Commit e927cf1

Browse files
committed
Revert changes and remove #[no_mangle] attribute
1 parent 42c0dad commit e927cf1

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
88
## [Unreleased]
99

1010
- Fix `enumeratedValues` with `isDefault` only
11-
- Generate unique identifier instead of `DEVICE_PERIPHERALS` to solve
11+
- Remove `#[no_mangle]` attribute of `DEVICE_PERIPHERALS` to solve
1212
the link time issue when multiple devices used
1313

1414
## [v0.33.4] - 2024-06-16

src/generate/device.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::svd::{array::names, Device, Peripheral};
22
use proc_macro2::{Span, TokenStream};
33
use quote::{quote, ToTokens};
4-
use regex::Regex;
5-
use syn::Ident;
64

75
use log::debug;
86
use std::fs::File;
@@ -272,22 +270,8 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
272270
}
273271
}
274272

275-
// Generate unique identifier to prevent linkage errors when using multiple devices.
276-
let mut id = String::from("TAKEN_");
277-
let re = Regex::new(r"[^A-Za-z0-9_]").unwrap();
278-
let result = re.replace_all(&d.name, "_");
279-
for ch in result.chars() {
280-
id.extend(ch.to_uppercase());
281-
}
282-
283-
let taken: Ident = syn::parse_str(&id)?;
284-
285273
out.extend(quote! {
286-
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
287-
// crate as that would let you `take` the device peripherals more than once (one per minor
288-
// version)
289-
#[no_mangle]
290-
static mut #taken: bool = false;
274+
static mut DEVICE_PERIPHERALS: bool = false;
291275

292276
/// All the peripherals.
293277
#[allow(non_snake_case)]
@@ -302,12 +286,12 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
302286
pub fn take() -> Option<Self> {
303287
critical_section::with(|_| {
304288
// SAFETY: We are in a critical section, so we have exclusive access
305-
// to `#taken`.
306-
if unsafe { #taken } {
289+
// to `DEVICE_PERIPHERALS`.
290+
if unsafe { DEVICE_PERIPHERALS } {
307291
return None
308292
}
309293

310-
// SAFETY: `#taken` is set to `true` by `Peripherals::steal`,
294+
// SAFETY: `DEVICE_PERIPHERALS` is set to `true` by `Peripherals::steal`,
311295
// ensuring the peripherals can only be returned once.
312296
Some(unsafe { Peripherals::steal() })
313297
})
@@ -320,7 +304,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
320304
/// Each of the returned peripherals must be used at most once.
321305
#[inline]
322306
pub unsafe fn steal() -> Self {
323-
#taken = true;
307+
DEVICE_PERIPHERALS = true;
324308

325309
Peripherals {
326310
#exprs

0 commit comments

Comments
 (0)