diff --git a/Cargo.toml b/Cargo.toml index e9a2a85..2a1462a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stackalloc" -version = "1.1.2" +version = "1.2.0" homepage = "https://git.flanchan.moe/flanchan/stackalloc-rs" repository = "https://github.com/notflan/stackalloc-rs" keywords = ["alloca", "stack", "stack-allocation", "safe"] diff --git a/README.md b/README.md index 3ed07ec..d1f295f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ However, it is still possible to cause a stack overflow by allocating too much m # Requirements The crate works on stable or nightly Rust, but a C99-compliant compiler is required to build. +# Features + * `no_std` - Enabled `no_std` support on nightly toolchains. + # Examples Allocating a byte buffer on the stack. ```rust diff --git a/src/lib.rs b/src/lib.rs index bfc5e32..bc93c19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,9 @@ #![cfg_attr(all(feature = "no_std", not(test)), no_std)] -#![cfg_attr(all(feature = "no_std"), feature(core_intrinsics))] +#![cfg_attr(all(feature = "no_std", not(feature="no_unwind_protection")), feature(core_intrinsics))] + +// NOTE: This feature `no_unwind_protection` doesn't actually exist at the moment; since a binary crate built with #![no_std] will not be using a stable compiler toolchain. It was just for testing. #[cfg(all(nightly, test))] extern crate test; @@ -111,7 +113,12 @@ use core::{ ptr, }; -pub mod avec; pub use avec::AVec; + +#[cfg(not(feature = "no_std"))] +pub mod avec; +#[cfg(not(feature = "no_std"))] +pub use avec::AVec; + mod ffi; /// Allocate a runtime length uninitialised byte buffer on the stack, call `callback` with this buffer, and then deallocate the buffer. @@ -206,7 +213,14 @@ where F: FnOnce(&mut [MaybeUninit]) -> T -#[cfg(feature = "no_std")] + +#[cfg(all(feature = "no_std", feature = "no_unwind_protection"))] +unsafe fn catch_unwind R>(f: F) -> Result { + // Catching unwinds disabled for this build for now since it requires core intrinsics. + Ok(f()) +} + +#[cfg(all(feature = "no_std", not(feature = "no_unwind_protection")))] unsafe fn catch_unwind R>(f: F) -> Result{ union Data { diff --git a/src/tests.rs b/src/tests.rs index 98a11f2..7a472d2 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -32,6 +32,7 @@ fn exact_size_iter() }), result); } +#[cfg(all(nightly, not(feature="no_std")))] // XXX: process will abort on no_std. This is expected, but won't "pass" this test. #[test] #[should_panic] fn unwinding_over_boundary()