-
Notifications
You must be signed in to change notification settings - Fork 0
phase 16: no-alloc CI gate #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -776,6 +776,156 @@ mod std_handle_impls { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Bare-metal no-alloc impls of [`E2ERegistryHandle`] and [`InterfaceHandle`]. | ||||||
| /// | ||||||
| /// These types satisfy `Clone + Send + Sync + 'static` without any heap | ||||||
| /// allocation. The backing storage lives in a caller-owned `static`; the | ||||||
| /// handles are thin `&'static` pointers that are trivially `Copy`. | ||||||
| /// | ||||||
| /// # Production pattern | ||||||
| /// | ||||||
| /// ```ignore | ||||||
| /// use core::cell::RefCell; | ||||||
| /// use core::sync::atomic::{AtomicU32, Ordering}; | ||||||
| /// use embassy_sync::blocking_mutex::Mutex; | ||||||
| /// use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||||||
| /// use simple_someip::e2e::E2ERegistry; | ||||||
| /// use simple_someip::transport::{StaticE2EHandle, AtomicInterfaceHandle}; | ||||||
| /// | ||||||
| /// // Initialize once in main() before spawning tasks. | ||||||
| /// fn init() -> (StaticE2EHandle, AtomicInterfaceHandle) { | ||||||
| /// static IFACE_ADDR: AtomicU32 = AtomicU32::new(0); | ||||||
| /// // E2ERegistry::new() is not const so the storage is heap-placed once. | ||||||
| /// let registry_storage: &'static _ = Box::leak(Box::new( | ||||||
| /// Mutex::<CriticalSectionRawMutex, RefCell<E2ERegistry>>::new( | ||||||
| /// RefCell::new(E2ERegistry::new()), | ||||||
| /// ), | ||||||
| /// )); | ||||||
| /// (StaticE2EHandle::new(registry_storage), AtomicInterfaceHandle::new(&IFACE_ADDR)) | ||||||
| /// } | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// # No-allocator targets | ||||||
| /// | ||||||
| /// The example above uses `Box::leak` because [`E2ERegistry::new`] is not | ||||||
| /// currently `const`. On a target with no allocator, swap that for a | ||||||
| /// `static`-cell pattern (e.g. `static_cell::StaticCell::init`) once the | ||||||
| /// registry constructor becomes `const`-friendly. The handle layer itself | ||||||
| /// never allocates — only the one-time storage materialization does. | ||||||
| #[cfg(feature = "bare_metal")] | ||||||
|
||||||
| #[cfg(feature = "bare_metal")] | |
| #[cfg(all(feature = "bare_metal", feature = "std"))] |
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe impl Send/Sync is a significant safety escape hatch. It would be safer to rely on auto-traits (if StaticE2EStorage is actually Send + Sync) rather than forcing Send/Sync manually. If the underlying embassy_sync::blocking_mutex::Mutex<..., RefCell<_>> is intentionally not Send/Sync on some targets, these unsafe impls could be unsound; consider removing them or switching to a backing type that is explicitly Send + Sync.
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe impl Send/Sync here looks unnecessary and weakens the compiler’s thread-safety checks. AtomicInterfaceHandle contains only a &'static AtomicU32, which is already Send + Sync, so the auto-traits should apply without unsafe. Prefer removing these unsafe impls (or, if you keep them, add a stronger safety justification than “&'static … is already Send + Sync”).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These re-exports are gated only on
feature = "bare_metal", but the newly added handle implementations currently rely on std-onlyE2ERegistry. If the implementation is updated tocfg(all(feature = "bare_metal", feature = "std"))(or otherwise made std-free), thispub useshould match to avoid build failures under--no-default-features --features bare_metal.