Skip to content

Commit 6a0b472

Browse files
committed
small fixes, formatting
1 parent 880a140 commit 6a0b472

34 files changed

+872
-1079
lines changed

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ _no versions before 0.13.2 have a changelog as I started the changelog in that v
44

55
## Table of Contents
66

7+
[//]: # (TODO: do this a better way)
8+
79
- [Current low-priority to-dos](#current-low-priority-to-dos)
810
- [Version 0.18.0](#version-0180)
9-
- [Commit 5](#commit-5-2025-8-16)
11+
- [Commit 7](#commit-7-2025-8-16-1855)
12+
- [Commit 6](#commit-6-2025-8-16-1519)
13+
- [Commit 5](#commit-5-2025-8-16-1519)
1014
- [Commit 4](#commit-4-2025-8-16-834)
1115
- [Commit 3](#commit-3-2025-8-15-2341)
1216
- [Commit 2](#commit-2-2025-8-14-1926)
@@ -65,14 +69,22 @@ _no versions before 0.13.2 have a changelog as I started the changelog in that v
6569

6670
## Version 0.18.0
6771

72+
### Commit 7 (2025-8-16 18:55)
73+
74+
i'm almost ready to release this version finally, just need to check that everything is correct
75+
76+
...1.0 soon?
77+
78+
- Formatting
79+
- Small fixes
80+
6881
### Commit 6 (2025-8-16 15:19)
6982

7083
- Add rustfmt config
7184
- Add more cold error constructors
7285
- Remove many methods from `AllocSlice`/`AllocExt`
7386
- Add missing `falloc_at` method to `AllocAlignedAt`
7487
- Add missing `repr(u8)` attrs to some enums
75-
-
7688

7789
### Commit 5 (2025-8-16 15:19)
7890

benches/bench.rs

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
#[cfg(not(feature = "no_alloc"))]
2-
extern crate alloc;
1+
#[cfg(not(feature = "no_alloc"))] extern crate alloc;
32
extern crate criterion;
43

5-
use core::{hint::black_box, time::Duration};
6-
use criterion::{criterion_main, Criterion};
7-
use memapi::{type_props::SizedProps, Alloc, AllocExt, DefaultAlloc, Layout};
8-
use std::ptr;
4+
use {
5+
core::{hint::black_box, time::Duration},
6+
criterion::{Criterion, criterion_main},
7+
memapi::{Alloc, AllocExt, DefaultAlloc, Layout, type_props::SizedProps},
8+
std::ptr
9+
};
910

1011
fn bench_alloc_dealloc(c: &mut Criterion) {
1112
c.bench_function("allod_dealloc", |b| {
1213
b.iter(|| unsafe {
1314
let alloc = black_box(DefaultAlloc);
1415
let layout = black_box(Layout::from_size_align_unchecked(
1516
black_box(usize::SZ),
16-
black_box(usize::ALN),
17+
black_box(usize::ALN)
1718
));
1819
let mem = black_box(alloc.alloc(black_box(layout))).unwrap();
1920
mem.as_ptr().cast::<usize>().write(black_box(193874));
@@ -27,10 +28,7 @@ fn bench_alloc_filled_1k(c: &mut Criterion) {
2728
b.iter(|| {
2829
let alloc = black_box(DefaultAlloc);
2930
let layout = unsafe {
30-
black_box(Layout::from_size_align_unchecked(
31-
black_box(1024),
32-
black_box(1),
33-
))
31+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)))
3432
};
3533
let byte = black_box(0xA5_u8);
3634
let ptr = black_box(alloc.falloc(layout, byte)).unwrap();
@@ -46,21 +44,14 @@ fn bench_grow_filled_1k_to_4k(c: &mut Criterion) {
4644
c.bench_function("grow_filled_1k_to_4k", |b| {
4745
b.iter(|| unsafe {
4846
let alloc = black_box(DefaultAlloc);
49-
let old_layout = black_box(Layout::from_size_align_unchecked(
50-
black_box(1024),
51-
black_box(1),
52-
));
53-
let new_layout = black_box(Layout::from_size_align_unchecked(
54-
black_box(4096),
55-
black_box(1),
56-
));
47+
let old_layout =
48+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)));
49+
let new_layout =
50+
black_box(Layout::from_size_align_unchecked(black_box(4096), black_box(1)));
5751
let ptr = black_box(alloc.falloc(old_layout, black_box(0x11_u8))).unwrap();
5852

59-
let grown = black_box(
60-
alloc
61-
.fgrow(ptr, old_layout, new_layout, black_box(0x22_u8))
62-
.unwrap(),
63-
);
53+
let grown =
54+
black_box(alloc.fgrow(ptr, old_layout, new_layout, black_box(0x22_u8)).unwrap());
6455

6556
ptr::write_bytes(grown.as_ptr(), 0, new_layout.size());
6657
alloc.dealloc(grown, new_layout);
@@ -72,21 +63,14 @@ fn bench_realloc_filled_4k_to_1k(c: &mut Criterion) {
7263
c.bench_function("realloc_filled_4k_to_1k", |b| {
7364
b.iter(|| unsafe {
7465
let alloc = black_box(DefaultAlloc);
75-
let old_layout = black_box(Layout::from_size_align_unchecked(
76-
black_box(4096),
77-
black_box(1),
78-
));
79-
let new_layout = black_box(Layout::from_size_align_unchecked(
80-
black_box(1024),
81-
black_box(1),
82-
));
66+
let old_layout =
67+
black_box(Layout::from_size_align_unchecked(black_box(4096), black_box(1)));
68+
let new_layout =
69+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)));
8370
let ptr = black_box(alloc.falloc(old_layout, black_box(0xEE_u8))).unwrap();
8471

85-
let shrunk = black_box(
86-
alloc
87-
.refalloc(ptr, old_layout, new_layout, black_box(0xFF_u8))
88-
.unwrap(),
89-
);
72+
let shrunk =
73+
black_box(alloc.refalloc(ptr, old_layout, new_layout, black_box(0xFF_u8)).unwrap());
9074

9175
ptr::write_bytes(shrunk.as_ptr(), 0, new_layout.size());
9276
alloc.dealloc(shrunk, new_layout);
@@ -102,7 +86,7 @@ fn bench_alloc_dealloc_base(c: &mut Criterion) {
10286
b.iter(|| unsafe {
10387
let layout = black_box(Layout::from_size_align_unchecked(
10488
black_box(usize::SZ),
105-
black_box(usize::ALN),
89+
black_box(usize::ALN)
10690
));
10791
let mem = black_box(alloc(black_box(layout)));
10892
mem.cast::<usize>().write(black_box(193874));
@@ -119,7 +103,7 @@ fn bench_alloc_default_u64_base(c: &mut Criterion) {
119103
b.iter(|| unsafe {
120104
let layout = black_box(Layout::from_size_align_unchecked(
121105
black_box(u64::SZ),
122-
black_box(u64::ALN),
106+
black_box(u64::ALN)
123107
));
124108
let mem = black_box(alloc(black_box(layout)));
125109
mem.cast::<u64>().write(black_box(u64::default()));
@@ -136,7 +120,7 @@ fn bench_alloc_write_u128_base(c: &mut Criterion) {
136120
b.iter(|| unsafe {
137121
let layout = black_box(Layout::from_size_align_unchecked(
138122
black_box(u128::SZ),
139-
black_box(u128::ALN),
123+
black_box(u128::ALN)
140124
));
141125
let mem = black_box(alloc(black_box(layout)));
142126
let value = black_box(0xDEADBEEF_DEADBEEF_DEADBEEF_DEADBEEF_u128);
@@ -152,10 +136,8 @@ fn bench_alloc_filled_1k_base(c: &mut Criterion) {
152136

153137
c.bench_function("base_alloc_filled_1k", |b| {
154138
b.iter(|| unsafe {
155-
let layout = black_box(Layout::from_size_align_unchecked(
156-
black_box(1024),
157-
black_box(1),
158-
));
139+
let layout =
140+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)));
159141
let byte = black_box(0xA5_u8);
160142
let mem = black_box(alloc(black_box(layout)));
161143
core::ptr::write_bytes(mem, byte, layout.size());
@@ -171,27 +153,23 @@ fn bench_grow_filled_1k_to_4k_base(c: &mut Criterion) {
171153

172154
c.bench_function("base_grow_filled_1k_to_4k", |b| {
173155
b.iter(|| unsafe {
174-
let old_layout = black_box(Layout::from_size_align_unchecked(
175-
black_box(1024),
176-
black_box(1),
177-
));
178-
let new_layout = black_box(Layout::from_size_align_unchecked(
179-
black_box(4096),
180-
black_box(1),
181-
));
156+
let old_layout =
157+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)));
158+
let new_layout =
159+
black_box(Layout::from_size_align_unchecked(black_box(4096), black_box(1)));
182160
let ptr = black_box(alloc(black_box(old_layout)));
183161
core::ptr::write_bytes(ptr, black_box(0x11_u8), old_layout.size());
184162

185163
let grown = black_box(realloc(
186164
black_box(ptr),
187165
black_box(old_layout),
188-
black_box(new_layout.size()),
166+
black_box(new_layout.size())
189167
));
190168
// Fill the newly added tail region
191169
core::ptr::write_bytes(
192170
grown.add(old_layout.size()),
193171
black_box(0x22_u8),
194-
new_layout.size() - old_layout.size(),
172+
new_layout.size() - old_layout.size()
195173
);
196174

197175
core::ptr::write_bytes(grown, 0u8, new_layout.size());
@@ -206,28 +184,24 @@ fn bench_realloc_filled_4k_to_1k_base(c: &mut Criterion) {
206184

207185
c.bench_function("base_realloc_filled_4k_to_1k", |b| {
208186
b.iter(|| unsafe {
209-
let old_layout = black_box(Layout::from_size_align_unchecked(
210-
black_box(4096),
211-
black_box(1),
212-
));
213-
let new_layout = black_box(Layout::from_size_align_unchecked(
214-
black_box(1024),
215-
black_box(1),
216-
));
187+
let old_layout =
188+
black_box(Layout::from_size_align_unchecked(black_box(4096), black_box(1)));
189+
let new_layout =
190+
black_box(Layout::from_size_align_unchecked(black_box(1024), black_box(1)));
217191
let ptr = black_box(alloc(black_box(old_layout)));
218192
// Initial fill
219193
core::ptr::write_bytes(ptr, black_box(0xEE_u8), old_layout.size());
220194
// Pre-fill the soon-to-be-freed tail region before shrinking
221195
core::ptr::write_bytes(
222196
ptr.add(new_layout.size()),
223197
black_box(0xFF_u8),
224-
old_layout.size() - new_layout.size(),
198+
old_layout.size() - new_layout.size()
225199
);
226200

227201
let shrunk = black_box(realloc(
228202
black_box(ptr),
229203
black_box(old_layout),
230-
black_box(new_layout.size()),
204+
black_box(new_layout.size())
231205
));
232206
core::ptr::write_bytes(shrunk, 0u8, new_layout.size());
233207
dealloc(shrunk, black_box(new_layout));
@@ -243,7 +217,7 @@ fn bench_dealloc_typed_usize_base(c: &mut Criterion) {
243217
b.iter(|| unsafe {
244218
let layout = black_box(Layout::from_size_align_unchecked(
245219
black_box(usize::SZ),
246-
black_box(usize::ALN),
220+
black_box(usize::ALN)
247221
));
248222
let mem = black_box(alloc(black_box(layout)));
249223
mem.cast::<usize>().write(black_box(193874_usize));

build.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ fn main() {
1313
let req_info = "please open an issue with your rust toolchain info";
1414
let get_tc_info = "(`rustup default`, `cargo --version`).";
1515
panic!(
16-
"sp_frp UB checks failed (codes: {:?}).\n\
17-
{} {}\n\
18-
example: {}",
16+
"sp_frp UB checks failed (codes: {:?}).\n{} {}\nexample: {}",
1917
failures.iter().map(|f| f.code).collect::<Vec<_>>(),
2018
req_info,
2119
get_tc_info,
@@ -26,7 +24,7 @@ fn main() {
2624
/// Represents a single check failure
2725
pub struct Failure {
2826
code: usize,
29-
msg: &'static str,
27+
msg: &'static str
3028
}
3129

3230
fn run_checks() -> Vec<Failure> {
@@ -39,8 +37,7 @@ fn run_checks() -> Vec<Failure> {
3937

4038
mod checks {
4139
pub mod sp_frp {
42-
use crate::Failure;
43-
use core::ptr::NonNull;
40+
use {crate::Failure, core::ptr::NonNull};
4441

4542
pub fn check() -> Vec<Failure> {
4643
let mut failures = Vec::<Failure>::new();
@@ -56,36 +53,25 @@ mod checks {
5653

5754
// check that they dereference to the same thing
5855
if unsafe { &*slice_ptr } != slice {
59-
failures.push(Failure {
60-
code: 0,
61-
msg: "result doesn't dereference properly",
62-
});
56+
failures.push(Failure { code: 0, msg: "result doesn't dereference properly" });
6357
}
6458
// check that they have the same pointer and length
6559
if slice.as_ptr() != slice_ptr.cast::<usize>() {
66-
failures.push(Failure {
67-
code: 1,
68-
msg: "result doesn't have the same pointer",
69-
});
60+
failures.push(Failure { code: 1, msg: "result doesn't have the same pointer" });
7061
}
7162
if unsafe { slice_ptr.as_ref() }.unwrap().len() != len {
72-
failures.push(Failure {
73-
code: 2,
74-
msg: "result doesn't have the same length",
75-
});
63+
failures.push(Failure { code: 2, msg: "result doesn't have the same length" });
7664
}
7765

7866
unsafe {
7967
if len
8068
!= nonnull_slice_len(nonnull_slice_from_raw_parts(
8169
NonNull::new_unchecked(ptr),
82-
len,
70+
len
8371
))
8472
{
85-
failures.push(Failure {
86-
code: 3,
87-
msg: "result doesn't have the correct metadata",
88-
});
73+
failures
74+
.push(Failure { code: 3, msg: "result doesn't have the correct metadata" });
8975
}
9076
}
9177

@@ -95,15 +81,15 @@ mod checks {
9581
if elem != via_raw {
9682
failures.push(Failure {
9783
code: 4,
98-
msg: "values differ between original slice and raw-slice",
84+
msg: "values differ between original slice and raw-slice"
9985
});
10086
}
10187

10288
// manually check that the values are the same
10389
if via_raw != 64_usize << i {
10490
failures.push(Failure {
10591
code: 5,
106-
msg: "raw-slice value mismatch against expected",
92+
msg: "raw-slice value mismatch against expected"
10793
});
10894
}
10995
}
@@ -114,9 +100,7 @@ mod checks {
114100
// from the crate
115101

116102
#[must_use]
117-
fn nonnull_slice_len<T>(ptr: NonNull<[T]>) -> usize {
118-
unsafe { (&*ptr.as_ptr()).len() }
119-
}
103+
fn nonnull_slice_len<T>(ptr: NonNull<[T]>) -> usize { unsafe { (&*ptr.as_ptr()).len() } }
120104

121105
#[must_use]
122106
fn nonnull_slice_from_raw_parts<T>(p: NonNull<T>, len: usize) -> NonNull<[T]> {

devbin/err_fmt.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#![allow(clippy::vec_init_then_push)]
22

3-
use core::ptr::NonNull;
4-
use memapi::{
5-
error::{AlignErr, AllocError, ArithOp, ArithOverflow, Cause, InvLayout, LayoutErr},
6-
Layout,
3+
use {
4+
core::ptr::NonNull,
5+
memapi::{
6+
Layout,
7+
error::{AlignErr, AllocError, ArithOp, ArithOverflow, Cause, InvLayout, LayoutErr}
8+
}
79
};
810

911
fn main() {
@@ -26,23 +28,23 @@ fn main() {
2628
items.push(AllocError::DeallocFailed(
2729
dangling,
2830
l1,
29-
Cause::InvalidBlockStatus(memapi::fallible_dealloc::BlockStatus::NotOwned),
31+
Cause::InvalidBlockStatus(memapi::fallible_dealloc::BlockStatus::NotOwned)
3032
));
3133

3234
items.push(AllocError::DeallocFailed(
3335
dangling,
3436
l1,
3537
Cause::InvalidBlockStatus(memapi::fallible_dealloc::BlockStatus::OwnedIncomplete(
36-
Some(l2),
37-
)),
38+
Some(l2)
39+
))
3840
));
3941

4042
items.push(AllocError::DeallocFailed(
4143
dangling,
4244
l1,
4345
Cause::InvalidBlockStatus(memapi::fallible_dealloc::BlockStatus::OwnedMisaligned(
44-
Some(1),
45-
)),
46+
Some(1)
47+
))
4648
));
4749
}
4850

0 commit comments

Comments
 (0)