Skip to content

Commit 4df52a9

Browse files
committed
crc-fast-rust: added conditional panic handler for CI no_std checks; global allocator for CI wasm checks. libs shouldn't contain this.
1 parent 6d142a9 commit 4df52a9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@
136136
//!
137137
//! Supports `no_std` environments. Use `default-features = false` in Cargo.toml.
138138
139+
// Provide a panic handler for no_std library checks/builds
140+
// This is only used when checking the library itself; final binaries must provide their own
141+
#[cfg(all(not(feature = "std"), not(test), not(doctest)))]
142+
#[panic_handler]
143+
fn panic(_info: &core::panic::PanicInfo) -> ! {
144+
loop {}
145+
}
146+
147+
// Provide a global allocator for no_std + alloc library checks/builds
148+
// This is only used when checking the library itself; final binaries must provide their own
149+
#[cfg(all(feature = "alloc", not(feature = "std"), not(test), not(doctest)))]
150+
#[global_allocator]
151+
static ALLOCATOR: LibcAllocator = LibcAllocator;
152+
153+
#[cfg(all(feature = "alloc", not(feature = "std"), not(test), not(doctest)))]
154+
struct LibcAllocator;
155+
156+
#[cfg(all(feature = "alloc", not(feature = "std"), not(test), not(doctest)))]
157+
unsafe impl core::alloc::GlobalAlloc for LibcAllocator {
158+
unsafe fn alloc(&self, _layout: core::alloc::Layout) -> *mut u8 {
159+
core::ptr::null_mut()
160+
}
161+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: core::alloc::Layout) {}
162+
}
163+
139164
use crate::crc32::consts::{
140165
CRC32_AIXM, CRC32_AUTOSAR, CRC32_BASE91_D, CRC32_BZIP2, CRC32_CD_ROM_EDC, CRC32_CKSUM,
141166
CRC32_ISCSI, CRC32_ISO_HDLC, CRC32_JAMCRC, CRC32_MEF, CRC32_MPEG_2, CRC32_XFER,

0 commit comments

Comments
 (0)