Skip to content

Commit 0643fcd

Browse files
committed
fixup! feat: implement Allocator for Pool
1 parent a73f48b commit 0643fcd

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/allocator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ where
3838
Ok(ptr)
3939
}
4040
///
41-
/// Creates a `NonNull` that is dangling, but well-aligned for this alignment.
41+
/// Creates a [NonNull] that is dangling, but well-aligned for this [Layout].
4242
///
4343
/// See also [::core::alloc::Layout::dangling()]
4444
#[inline(always)]
45-
pub(crate) const fn dangling_aligned<T>(align: usize) -> NonNull<T> {
45+
pub(crate) const fn dangling_for_layout(layout: &Layout) -> NonNull<u8> {
4646
unsafe {
47-
let ptr = ptr::null_mut::<T>().byte_add(align);
47+
let ptr = ptr::null_mut::<u8>().byte_add(layout.align());
4848
NonNull::new_unchecked(ptr)
4949
}
5050
}

src/core/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use nginx_sys::{
88
ngx_pool_cleanup_add, ngx_pool_t, NGX_ALIGNMENT,
99
};
1010

11-
use crate::allocator::{dangling_aligned, AllocError, Allocator};
11+
use crate::allocator::{dangling_for_layout, AllocError, Allocator};
1212
use crate::core::buffer::{Buffer, MemoryBuffer, TemporaryBuffer};
1313

1414
/// Non-owning wrapper for an [`ngx_pool_t`] pointer, providing methods for working with memory pools.
@@ -29,7 +29,7 @@ unsafe impl Allocator for Pool {
2929
// ngx_palloc_small. Any other cases are implementation-defined, and we can't tell which
3030
// one will be used internally.
3131
return Ok(NonNull::slice_from_raw_parts(
32-
dangling_aligned(layout.align()),
32+
dangling_for_layout(&layout),
3333
layout.size(),
3434
));
3535
} else if layout.align() == 1 {

0 commit comments

Comments
 (0)