Skip to content

Commit

Permalink
bump version, reset MSRV, fix fuzz config
Browse files Browse the repository at this point in the history
  • Loading branch information
SFBdragon committed Apr 13, 2024
1 parent 8579035 commit eaabfd1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<sep>

<sub><i>If you find Talc useful, please consider leaving tip via [Paypal](https://www.paypal.com/donate/?hosted_button_id=8CSQ92VV58VPQ).</i></sub>
<sub><i>If you find Talc useful, please consider leaving tip via [Paypal](https://www.paypal.com/donate/?hosted_button_id=8CSQ92VV58VPQ)</i></sub>

#### What is this for?
- Embedded systems, OS kernels, and other `no_std` environments
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions talc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
24 changes: 16 additions & 8 deletions talc/src/talck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,24 @@ unsafe impl<R: lock_api::RawMutex, O: OomHandler> GlobalAlloc for Talck<R, O> {
}
}

/// Convert a nonnull and length to a nonnull slice.
#[cfg(any(feature = "allocator", feature = "allocator-api2"))]
fn nonnull_slice_from_raw_parts(ptr: NonNull<u8>, 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<R: lock_api::RawMutex, O: OomHandler> Allocator for Talck<R, O> {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, 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<u8>, layout: Layout) {
Expand All @@ -141,7 +149,7 @@ unsafe impl<R: lock_api::RawMutex, O: OomHandler> Allocator for Talck<R, O> {
} 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()));
}
}

Expand All @@ -160,7 +168,7 @@ unsafe impl<R: lock_api::RawMutex, O: OomHandler> Allocator for Talck<R, O> {

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(
Expand Down Expand Up @@ -195,7 +203,7 @@ unsafe impl<R: lock_api::RawMutex, O: OomHandler> Allocator for Talck<R, O> {
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()) {
Expand All @@ -211,12 +219,12 @@ unsafe impl<R: lock_api::RawMutex, O: OomHandler> Allocator for Talck<R, O> {
}

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()))
}
}

Expand Down
3 changes: 3 additions & 0 deletions wasm-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaabfd1

Please sign in to comment.