From eaabfd131b2ef39dcf7416b9f9c369fa7f1679bd Mon Sep 17 00:00:00 2001 From: Shaun Beautement Date: Sat, 13 Apr 2024 17:54:02 +0200 Subject: [PATCH] bump version, reset MSRV, fix fuzz config --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 9 +++++++-- README.md | 7 ++++++- check.sh | 4 ++-- fuzz/Cargo.toml | 3 --- talc/Cargo.toml | 4 ++-- talc/src/talck.rs | 24 ++++++++++++++++-------- wasm-size.sh | 3 +++ 8 files changed, 38 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4121e96..3a067e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,5 +64,5 @@ jobs: - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: | - rustup toolchain add 1.70.0 --profile minimal - rustup run 1.70.0 cargo check -p talc --no-default-features --features lock_api,allocator-api2,counters --verbose + rustup toolchain add 1.67.1 --profile minimal + rustup run 1.67.1 cargo check -p talc --no-default-features --features lock_api,allocator-api2,counters --verbose diff --git a/Cargo.toml b/Cargo.toml index e3b3521..6de1664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,18 @@ members = [ ] [profile.release] -lto = "fat" -codegen-units = 1 panic = "abort" [profile.release.package.wasm-size] opt-level = "z" +codegen-units = 1 # be realistic about the optimization configuration, even if it's a benchmark [profile.release.package.wasm-perf] opt-level = "z" +codegen-units = 1 + +# the fuzzer needs debuginfo +[profile.release.package.talc-fuzz] +debug = 1 + diff --git a/README.md b/README.md index 0c6017d..2ed8be4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -If you find Talc useful, please consider leaving tip via [Paypal](https://www.paypal.com/donate/?hosted_button_id=8CSQ92VV58VPQ). +If you find Talc useful, please consider leaving tip via [Paypal](https://www.paypal.com/donate/?hosted_button_id=8CSQ92VV58VPQ) #### What is this for? - Embedded systems, OS kernels, and other `no_std` environments @@ -193,6 +193,7 @@ impl OomHandler for MyOomHandler { * `"allocator"` (default, requires nightly): Provides an `Allocator` trait implementation via `Talck`. * `"nightly_api"` (default, requires nightly): Provides the `Span::from(*mut [T])` and `Span::from_slice` functions. * `"counters"`: `Talc` will track heap and allocation metrics. Use `Talc::get_counters` to access them. +* `"allocator-api2"`: `Talck` will implement `allocator_api2::alloc::Allocator` if `"allocator"` is not active. ## Stable Rust and MSRV Talc can be built on stable Rust by disabling `"allocator"` and `"nightly_api"`. The MSRV is 1.67.1. @@ -212,6 +213,10 @@ Additionally, the layout of chunk metadata is rearranged to allow for smaller mi ## Changelog +#### v4.4.0 + +- Added feature `allocator-api2` which allows using the `Allocator` trait on stable via the [`allocator-api2`](https://github.com/zakarumych/allocator-api2) crate. Thanks [jess-sol](https://github.com/jess-sol)! + #### v4.3.1 - Updated the README a little diff --git a/check.sh b/check.sh index 6523763..b459380 100755 --- a/check.sh +++ b/check.sh @@ -18,7 +18,7 @@ rustup run stable cargo check -p stable_examples --example stable_allocator_api rustup run stable cargo check -p stable_examples --example std_global_allocator # check whether MSRV has been broken -rustup run 1.70.0 cargo check -p talc --no-default-features --features lock_api,allocator-api2,counters +rustup run 1.67.1 cargo check -p talc --no-default-features --features lock_api,allocator-api2,counters # NIGHTLY CONFIGURATIONS @@ -42,7 +42,7 @@ rustup run nightly cargo check -p benchmarks --bin random_actions # check wasm size benches ./wasm-size.sh check # check wasm size MSRV -rustup run 1.70.0 cargo check -p wasm-size --target wasm32-unknown-unknown +rustup run 1.68 cargo check -p wasm-size --target wasm32-unknown-unknown # check wasm perf benches ./wasm-perf.sh check diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 86d6786..2c38373 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -17,9 +17,6 @@ rand = "0.8.5" path = "../talc" features = ["fuzzing", "counters"] -# [profile.release] -# debug = 1 - [[bin]] name = "fuzz_talc" path = "fuzz_targets/fuzz_talc.rs" diff --git a/talc/Cargo.toml b/talc/Cargo.toml index 2c8420d..4a2ae46 100644 --- a/talc/Cargo.toml +++ b/talc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "talc" -version = "4.3.1" -rust-version = "1.70.0" +version = "4.4.0" +rust-version = "1.67.1" edition = "2021" readme = "README.md" authors = ["Shaun Beautement"] diff --git a/talc/src/talck.rs b/talc/src/talck.rs index 530d964..36d6c9f 100644 --- a/talc/src/talck.rs +++ b/talc/src/talck.rs @@ -110,16 +110,24 @@ unsafe impl GlobalAlloc for Talck { } } +/// Convert a nonnull and length to a nonnull slice. +#[cfg(any(feature = "allocator", feature = "allocator-api2"))] +fn nonnull_slice_from_raw_parts(ptr: NonNull, len: usize) -> NonNull<[u8]> { + unsafe { + NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(ptr.as_ptr(), len)) + } +} + #[cfg(any(feature = "allocator", feature = "allocator-api2"))] unsafe impl Allocator for Talck { fn allocate(&self, layout: Layout) -> Result, AllocError> { if layout.size() == 0 { - return Ok(NonNull::slice_from_raw_parts(NonNull::dangling(), 0)); + return Ok(nonnull_slice_from_raw_parts(NonNull::dangling(), 0)); } unsafe { self.lock().malloc(layout) } - .map(|nn| NonNull::slice_from_raw_parts(nn, layout.size())) - .map_err(|_| AllocError) + .map(|nn| nonnull_slice_from_raw_parts(nn, layout.size())) + .map_err(|_| AllocError) } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { @@ -141,7 +149,7 @@ unsafe impl Allocator for Talck { } else if is_aligned_to(ptr.as_ptr(), new_layout.align()) { // alignment is fine, try to allocate in-place if let Ok(nn) = self.lock().grow_in_place(ptr, old_layout, new_layout.size()) { - return Ok(NonNull::slice_from_raw_parts(nn, new_layout.size())); + return Ok(nonnull_slice_from_raw_parts(nn, new_layout.size())); } } @@ -160,7 +168,7 @@ unsafe impl Allocator for Talck { lock.free(ptr, old_layout); - Ok(NonNull::slice_from_raw_parts(allocation, new_layout.size())) + Ok(nonnull_slice_from_raw_parts(allocation, new_layout.size())) } unsafe fn grow_zeroed( @@ -195,7 +203,7 @@ unsafe impl Allocator for Talck { self.lock().free(ptr, old_layout); } - return Ok(NonNull::slice_from_raw_parts(NonNull::dangling(), 0)); + return Ok(nonnull_slice_from_raw_parts(NonNull::dangling(), 0)); } if !is_aligned_to(ptr.as_ptr(), new_layout.align()) { @@ -211,12 +219,12 @@ unsafe impl Allocator for Talck { } lock.free(ptr, old_layout); - return Ok(NonNull::slice_from_raw_parts(allocation, new_layout.size())); + return Ok(nonnull_slice_from_raw_parts(allocation, new_layout.size())); } self.lock().shrink(ptr, old_layout, new_layout.size()); - Ok(NonNull::slice_from_raw_parts(ptr, new_layout.size())) + Ok(nonnull_slice_from_raw_parts(ptr, new_layout.size())) } } diff --git a/wasm-size.sh b/wasm-size.sh index c30b3b0..89e518e 100755 --- a/wasm-size.sh +++ b/wasm-size.sh @@ -13,6 +13,9 @@ fi ALLOCATORS="talc talc_arena rlsf dlmalloc lol_alloc" for ALLOCATOR in ${ALLOCATORS}; do echo "${ALLOCATOR}" + + # turn on LTO via RUSTFLAGS + RUSTFLAGS="-C lto -C embed-bitcode=yes -C linker-plugin-lto" \ cargo $COMMAND -p wasm-size --quiet --release --target wasm32-unknown-unknown --features ${ALLOCATOR} if [[ $1 != "check" ]]; then